Skip to content

Commit 4e4b2e7

Browse files
mdubuscurquiza
andauthored
Implement vector search experimental feature (#1623)
* Implement vector search experimental feature * Update README.md --------- Co-authored-by: Clémentine U. - curqui <[email protected]>
1 parent 7b52526 commit 4e4b2e7

File tree

7 files changed

+340
-9
lines changed

7 files changed

+340
-9
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ client.index('myIndex').resetDictionary(): Promise<EnqueuedTask>
963963

964964
### Proximity Precision <!-- omit in toc -->
965965

966-
#### [Get proximity precision](https://www.meilisearch.com/docs/reference/api/settings#get-prximity-precision)
966+
#### [Get proximity precision](https://www.meilisearch.com/docs/reference/api/settings#get-proximity-precision)
967967

968968
```ts
969969
client.index('myIndex').getProximityPrecision(): Promise<ProximityPrecision>
@@ -981,6 +981,28 @@ client.index('myIndex').updateProximityPrecision(proximityPrecision: ProximityPr
981981
client.index('myIndex').resetProximityPrecision(): Promise<EnqueuedTask>
982982
```
983983

984+
### Embedders <!-- omit in toc -->
985+
986+
⚠️ This feature is experimental. Activate the `vectorSearch` experimental feature to use it](https://www.meilisearch.com/docs/reference/api/experimental_features#configure-experimental-features)
987+
988+
#### [Get embedders](https://www.meilisearch.com/docs/reference/api/settings#get-embedders)
989+
990+
```ts
991+
client.index('myIndex').getEmbedders(): Promise<Embedders>
992+
```
993+
994+
#### [Update embedders](https://www.meilisearch.com/docs/reference/api/settings#update-embedders)
995+
996+
```ts
997+
client.index('myIndex').updateEmbedders(embedders: Embedders): Promise<EnqueuedTask>
998+
```
999+
1000+
#### [Reset embedders](https://www.meilisearch.com/docs/reference/api/settings#reset-embedders)
1001+
1002+
```ts
1003+
client.index('myIndex').resetEmbedders(): Promise<EnqueuedTask>
1004+
```
1005+
9841006
### Keys <!-- omit in toc -->
9851007

9861008
#### [Get keys](https://www.meilisearch.com/docs/reference/api/keys#get-all-keys)

src/indexes.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
NonSeparatorTokens,
5252
Dictionary,
5353
ProximityPrecision,
54+
Embedders,
5455
} from './types'
5556
import { removeUndefinedFromObject } from './utils'
5657
import { HttpRequests } from './http-requests'
@@ -1292,6 +1293,47 @@ class Index<T extends Record<string, any> = Record<string, any>> {
12921293

12931294
return task
12941295
}
1296+
1297+
///
1298+
/// EMBEDDERS
1299+
///
1300+
1301+
/**
1302+
* Get the embedders settings of a Meilisearch index.
1303+
*
1304+
* @returns Promise containing the embedders settings
1305+
*/
1306+
async getEmbedders(): Promise<Embedders> {
1307+
const url = `indexes/${this.uid}/settings/embedders`
1308+
return await this.httpRequest.get<Embedders>(url)
1309+
}
1310+
1311+
/**
1312+
* Update the embedders settings. Overwrite the old settings.
1313+
*
1314+
* @param embedders - Object that contains the new embedders settings.
1315+
* @returns Promise containing an EnqueuedTask or null
1316+
*/
1317+
async updateEmbedders(embedders: Embedders): Promise<EnqueuedTask> {
1318+
const url = `indexes/${this.uid}/settings/embedders`
1319+
const task = await this.httpRequest.patch(url, embedders)
1320+
1321+
return new EnqueuedTask(task)
1322+
}
1323+
1324+
/**
1325+
* Reset the embedders settings to its default value
1326+
*
1327+
* @returns Promise containing an EnqueuedTask
1328+
*/
1329+
async resetEmbedders(): Promise<EnqueuedTask> {
1330+
const url = `indexes/${this.uid}/settings/embedders`
1331+
const task = await this.httpRequest.delete<EnqueuedTask>(url)
1332+
1333+
task.enqueuedAt = new Date(task.enqueuedAt)
1334+
1335+
return task
1336+
}
12951337
}
12961338

12971339
export { Index }

src/types/types.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ export type SearchForFacetValuesResponse = {
9595
processingTimeMs: number
9696
}
9797

98+
export type HybridSearch = {
99+
embedder?: string
100+
semanticRatio?: number
101+
}
102+
98103
export type SearchParams = Query &
99104
Pagination &
100105
Highlight &
@@ -113,6 +118,7 @@ export type SearchParams = Query &
113118
showRankingScore?: boolean
114119
showRankingScoreDetails?: boolean
115120
attributesToSearchOn?: string[] | null
121+
hybrid?: HybridSearch
116122
}
117123

118124
// Search parameters for searches made with the GET method
@@ -130,6 +136,8 @@ export type SearchRequestGET = Pagination &
130136
showMatchesPosition?: boolean
131137
vector?: string | null
132138
attributesToSearchOn?: string | null
139+
hybridEmbedder?: string
140+
hybridSemanticRatio?: number
133141
}
134142

135143
export type MultiSearchQuery = SearchParams & { indexUid: string }
@@ -318,6 +326,31 @@ export type NonSeparatorTokens = string[] | null
318326
export type Dictionary = string[] | null
319327
export type ProximityPrecision = 'byWord' | 'byAttribute'
320328

329+
export type OpenAiEmbedder = {
330+
source: 'openAi'
331+
model?: string
332+
apiKey?: string
333+
documentTemplate?: string
334+
}
335+
336+
export type HuggingFaceEmbedder = {
337+
source: 'huggingFace'
338+
model?: string
339+
revision?: string
340+
documentTemplate?: string
341+
}
342+
343+
export type UserProvidedEmbedder = {
344+
source: 'userProvided'
345+
dimensions: number
346+
}
347+
export type Embedder =
348+
| OpenAiEmbedder
349+
| HuggingFaceEmbedder
350+
| UserProvidedEmbedder
351+
352+
export type Embedders = Record<string, Embedder> | null
353+
321354
export type FacetOrder = 'alpha' | 'count'
322355

323356
export type Faceting = {
@@ -345,6 +378,7 @@ export type Settings = {
345378
nonSeparatorTokens?: NonSeparatorTokens
346379
dictionary?: Dictionary
347380
proximityPrecision?: ProximityPrecision
381+
embedders?: Embedders
348382
}
349383

350384
/*

tests/__snapshots__/settings.test.ts.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Object {
77
"*",
88
],
99
"distinctAttribute": null,
10+
"embedders": Object {},
1011
"faceting": Object {
1112
"maxValuesPerFacet": 100,
1213
"sortFacetValuesBy": Object {
@@ -53,6 +54,7 @@ Object {
5354
"*",
5455
],
5556
"distinctAttribute": null,
57+
"embedders": Object {},
5658
"faceting": Object {
5759
"maxValuesPerFacet": 100,
5860
"sortFacetValuesBy": Object {
@@ -99,6 +101,7 @@ Object {
99101
"*",
100102
],
101103
"distinctAttribute": null,
104+
"embedders": Object {},
102105
"faceting": Object {
103106
"maxValuesPerFacet": 100,
104107
"sortFacetValuesBy": Object {
@@ -145,6 +148,7 @@ Object {
145148
"*",
146149
],
147150
"distinctAttribute": null,
151+
"embedders": Object {},
148152
"faceting": Object {
149153
"maxValuesPerFacet": 100,
150154
"sortFacetValuesBy": Object {
@@ -191,6 +195,7 @@ Object {
191195
"*",
192196
],
193197
"distinctAttribute": null,
198+
"embedders": Object {},
194199
"faceting": Object {
195200
"maxValuesPerFacet": 100,
196201
"sortFacetValuesBy": Object {
@@ -237,6 +242,7 @@ Object {
237242
"*",
238243
],
239244
"distinctAttribute": null,
245+
"embedders": Object {},
240246
"faceting": Object {
241247
"maxValuesPerFacet": 100,
242248
"sortFacetValuesBy": Object {
@@ -286,6 +292,7 @@ Object {
286292
"title",
287293
],
288294
"distinctAttribute": "title",
295+
"embedders": Object {},
289296
"faceting": Object {
290297
"maxValuesPerFacet": 50,
291298
"sortFacetValuesBy": Object {
@@ -350,6 +357,7 @@ Object {
350357
"*",
351358
],
352359
"distinctAttribute": "title",
360+
"embedders": Object {},
353361
"faceting": Object {
354362
"maxValuesPerFacet": 100,
355363
"sortFacetValuesBy": Object {
@@ -394,6 +402,7 @@ Object {
394402
"*",
395403
],
396404
"distinctAttribute": null,
405+
"embedders": Object {},
397406
"faceting": Object {
398407
"maxValuesPerFacet": 100,
399408
"sortFacetValuesBy": Object {
@@ -440,6 +449,7 @@ Object {
440449
"*",
441450
],
442451
"distinctAttribute": null,
452+
"embedders": Object {},
443453
"faceting": Object {
444454
"maxValuesPerFacet": 100,
445455
"sortFacetValuesBy": Object {
@@ -486,6 +496,7 @@ Object {
486496
"*",
487497
],
488498
"distinctAttribute": null,
499+
"embedders": Object {},
489500
"faceting": Object {
490501
"maxValuesPerFacet": 100,
491502
"sortFacetValuesBy": Object {
@@ -532,6 +543,7 @@ Object {
532543
"*",
533544
],
534545
"distinctAttribute": null,
546+
"embedders": Object {},
535547
"faceting": Object {
536548
"maxValuesPerFacet": 100,
537549
"sortFacetValuesBy": Object {
@@ -578,6 +590,7 @@ Object {
578590
"*",
579591
],
580592
"distinctAttribute": null,
593+
"embedders": Object {},
581594
"faceting": Object {
582595
"maxValuesPerFacet": 100,
583596
"sortFacetValuesBy": Object {
@@ -624,6 +637,7 @@ Object {
624637
"*",
625638
],
626639
"distinctAttribute": null,
640+
"embedders": Object {},
627641
"faceting": Object {
628642
"maxValuesPerFacet": 100,
629643
"sortFacetValuesBy": Object {
@@ -670,6 +684,7 @@ Object {
670684
"*",
671685
],
672686
"distinctAttribute": null,
687+
"embedders": Object {},
673688
"faceting": Object {
674689
"maxValuesPerFacet": 100,
675690
"sortFacetValuesBy": Object {
@@ -719,6 +734,7 @@ Object {
719734
"title",
720735
],
721736
"distinctAttribute": "title",
737+
"embedders": Object {},
722738
"faceting": Object {
723739
"maxValuesPerFacet": 50,
724740
"sortFacetValuesBy": Object {
@@ -783,6 +799,7 @@ Object {
783799
"*",
784800
],
785801
"distinctAttribute": "title",
802+
"embedders": Object {},
786803
"faceting": Object {
787804
"maxValuesPerFacet": 100,
788805
"sortFacetValuesBy": Object {
@@ -827,6 +844,7 @@ Object {
827844
"*",
828845
],
829846
"distinctAttribute": null,
847+
"embedders": Object {},
830848
"faceting": Object {
831849
"maxValuesPerFacet": 100,
832850
"sortFacetValuesBy": Object {

0 commit comments

Comments
 (0)