Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vector search experimental feature #1623

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ client.index('myIndex').resetDictionary(): Promise<EnqueuedTask>

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

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

```ts
client.index('myIndex').getProximityPrecision(): Promise<ProximityPrecision>
Expand All @@ -981,6 +981,28 @@ client.index('myIndex').updateProximityPrecision(proximityPrecision: ProximityPr
client.index('myIndex').resetProximityPrecision(): Promise<EnqueuedTask>
```

### Embedders <!-- omit in toc -->

curquiza marked this conversation as resolved.
Show resolved Hide resolved
⚠️ This feature is experimental. Activate the `vectorSearch` experimental feature to use it](https://www.meilisearch.com/docs/reference/api/experimental_features#configure-experimental-features)

#### [Get embedders](https://www.meilisearch.com/docs/reference/api/settings#get-embedders)

```ts
client.index('myIndex').getEmbedders(): Promise<Embedders>
```

#### [Update embedders](https://www.meilisearch.com/docs/reference/api/settings#update-embedders)

```ts
client.index('myIndex').updateEmbedders(embedders: Embedders): Promise<EnqueuedTask>
```

#### [Reset embedders](https://www.meilisearch.com/docs/reference/api/settings#reset-embedders)

```ts
client.index('myIndex').resetEmbedders(): Promise<EnqueuedTask>
```

### Keys <!-- omit in toc -->

#### [Get keys](https://www.meilisearch.com/docs/reference/api/keys#get-all-keys)
Expand Down
42 changes: 42 additions & 0 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
NonSeparatorTokens,
Dictionary,
ProximityPrecision,
Embedders,
} from './types'
import { removeUndefinedFromObject } from './utils'
import { HttpRequests } from './http-requests'
Expand Down Expand Up @@ -1292,6 +1293,47 @@ class Index<T extends Record<string, any> = Record<string, any>> {

return task
}

///
/// EMBEDDERS
///

/**
* Get the embedders settings of a Meilisearch index.
*
* @returns Promise containing the embedders settings
*/
async getEmbedders(): Promise<Embedders> {
const url = `indexes/${this.uid}/settings/embedders`
return await this.httpRequest.get<Embedders>(url)
}

/**
* Update the embedders settings. Overwrite the old settings.
*
* @param embedders - Object that contains the new embedders settings.
* @returns Promise containing an EnqueuedTask or null
*/
async updateEmbedders(embedders: Embedders): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/embedders`
const task = await this.httpRequest.patch(url, embedders)

return new EnqueuedTask(task)
}

/**
* Reset the embedders settings to its default value
*
* @returns Promise containing an EnqueuedTask
*/
async resetEmbedders(): Promise<EnqueuedTask> {
const url = `indexes/${this.uid}/settings/embedders`
const task = await this.httpRequest.delete<EnqueuedTask>(url)

task.enqueuedAt = new Date(task.enqueuedAt)

return task
}
}

export { Index }
34 changes: 34 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ export type SearchForFacetValuesResponse = {
processingTimeMs: number
}

export type HybridSearch = {
embedder?: string
semanticRatio?: number
}

export type SearchParams = Query &
Pagination &
Highlight &
Expand All @@ -113,6 +118,7 @@ export type SearchParams = Query &
showRankingScore?: boolean
showRankingScoreDetails?: boolean
attributesToSearchOn?: string[] | null
hybrid?: HybridSearch
}

// Search parameters for searches made with the GET method
Expand All @@ -130,6 +136,8 @@ export type SearchRequestGET = Pagination &
showMatchesPosition?: boolean
vector?: string | null
attributesToSearchOn?: string | null
hybridEmbedder?: string
hybridSemanticRatio?: number
}

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

export type OpenAiEmbedder = {
source: 'openAi'
model?: string
apiKey?: string
documentTemplate?: string
}

export type HuggingFaceEmbedder = {
source: 'huggingFace'
model?: string
revision?: string
documentTemplate?: string
}

export type UserProvidedEmbedder = {
source: 'userProvided'
dimensions: number
}
export type Embedder =
| OpenAiEmbedder
| HuggingFaceEmbedder
| UserProvidedEmbedder

export type Embedders = Record<string, Embedder> | null

export type FacetOrder = 'alpha' | 'count'

export type Faceting = {
Expand Down Expand Up @@ -345,6 +378,7 @@ export type Settings = {
nonSeparatorTokens?: NonSeparatorTokens
dictionary?: Dictionary
proximityPrecision?: ProximityPrecision
embedders?: Embedders
}

/*
Expand Down
18 changes: 18 additions & 0 deletions tests/__snapshots__/settings.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -53,6 +54,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -99,6 +101,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -145,6 +148,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -191,6 +195,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -237,6 +242,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -286,6 +292,7 @@ Object {
"title",
],
"distinctAttribute": "title",
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 50,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -350,6 +357,7 @@ Object {
"*",
],
"distinctAttribute": "title",
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -394,6 +402,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -440,6 +449,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -486,6 +496,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -532,6 +543,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -578,6 +590,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -624,6 +637,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -670,6 +684,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -719,6 +734,7 @@ Object {
"title",
],
"distinctAttribute": "title",
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 50,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -783,6 +799,7 @@ Object {
"*",
],
"distinctAttribute": "title",
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down Expand Up @@ -827,6 +844,7 @@ Object {
"*",
],
"distinctAttribute": null,
"embedders": Object {},
"faceting": Object {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": Object {
Expand Down
Loading