Skip to content

Commit e9e1f00

Browse files
authored
Experimental vector search for MS v1.3.0 (#1535)
* Experimental vector search for MS v1.3.0 * Add vector search error codes * Use permission as key when enabling the experimental prototype
1 parent 4338c47 commit e9e1f00

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

src/indexes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
137137
attributesToRetrieve: options?.attributesToRetrieve?.join(','),
138138
attributesToCrop: options?.attributesToCrop?.join(','),
139139
attributesToHighlight: options?.attributesToHighlight?.join(','),
140+
vector: options?.vector?.join(','),
140141
}
141142

142143
return await this.httpRequest.get<SearchResponse<D, S>>(

src/types/types.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export type SearchParams = Query &
9090
matchingStrategy?: MatchingStrategies
9191
hitsPerPage?: number
9292
page?: number
93+
vector?: number[] | null
9394
}
9495

9596
// Search parameters for searches made with the GET method
@@ -105,6 +106,7 @@ export type SearchRequestGET = Pagination &
105106
attributesToHighlight?: string
106107
attributesToCrop?: string
107108
showMatchesPosition?: boolean
109+
vector?: string | null
108110
}
109111

110112
export type MultiSearchQuery = SearchParams & { indexUid: string }
@@ -142,6 +144,7 @@ export type SearchResponse<
142144
facetDistribution?: FacetDistribution
143145
query: string
144146
facetStats?: FacetStats
147+
vector: number[]
145148
} & (undefined extends S
146149
? Partial<FinitePagination & InfinitePagination>
147150
: true extends IsFinitePagination<NonNullable<S>>
@@ -560,12 +563,15 @@ export const enum ErrorStatusCode {
560563
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_offset */
561564
INVALID_DOCUMENT_OFFSET = 'invalid_document_offset',
562565

563-
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_offset */
566+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_filter */
564567
INVALID_DOCUMENT_FILTER = 'invalid_document_filter',
565568

566-
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_offset */
569+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#missing_document_filter */
567570
MISSING_DOCUMENT_FILTER = 'missing_document_filter',
568571

572+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_document_vectors_field */
573+
INVALID_DOCUMENT_VECTORS_FIELD = 'invalid_document_vectors_field',
574+
569575
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#payload_too_large */
570576
PAYLOAD_TOO_LARGE = 'payload_too_large',
571577

@@ -641,6 +647,9 @@ export const enum ErrorStatusCode {
641647
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_matching_strategy */
642648
INVALID_SEARCH_MATCHING_STRATEGY = 'invalid_search_matching_strategy',
643649

650+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_vector */
651+
INVALID_SEARCH_VECTOR = 'invalid_search_vector',
652+
644653
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#bad_request */
645654
BAD_REQUEST = 'bad_request',
646655

tests/get_search.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
BAD_HOST,
77
MeiliSearch,
88
getClient,
9+
HOST,
10+
getKey,
911
} from './utils/meilisearch-test-utils'
1012

1113
const index = {
@@ -423,6 +425,25 @@ describe.each([
423425
'The filter query parameter should be in string format when using searchGet'
424426
)
425427
})
428+
test(`${permission} key: search with vectors`, async () => {
429+
const client = await getClient(permission)
430+
const key = await getKey(permission)
431+
432+
await fetch(`${HOST}/experimental-features`, {
433+
body: JSON.stringify({ vectorStore: true }),
434+
headers: {
435+
Authorization: `Bearer ${key}`,
436+
'Content-Type': 'application/json',
437+
},
438+
method: 'PATCH',
439+
})
440+
441+
const response = await client
442+
.index(emptyIndex.uid)
443+
.searchGet('', { vector: [1] })
444+
445+
expect(response.vector).toEqual([1])
446+
})
426447

427448
test(`${permission} key: Try to search on deleted index and fail`, async () => {
428449
const client = await getClient(permission)

tests/search.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ import {
88
MeiliSearch,
99
getClient,
1010
datasetWithNests,
11+
HOST,
12+
getKey,
1113
} from './utils/meilisearch-test-utils'
1214

15+
if (typeof fetch === 'undefined') {
16+
require('cross-fetch/polyfill')
17+
}
18+
1319
const index = {
1420
uid: 'movies_test',
1521
}
@@ -767,6 +773,26 @@ describe.each([
767773
expect(response.hits.length).toEqual(0)
768774
})
769775

776+
test(`${permission} key: search with vectors`, async () => {
777+
const client = await getClient(permission)
778+
const key = await getKey(permission)
779+
780+
await fetch(`${HOST}/experimental-features`, {
781+
body: JSON.stringify({ vectorStore: true }),
782+
headers: {
783+
Authorization: `Bearer ${key}`,
784+
'Content-Type': 'application/json',
785+
},
786+
method: 'PATCH',
787+
})
788+
789+
const response = await client
790+
.index(emptyIndex.uid)
791+
.search('', { vector: [1] })
792+
793+
expect(response.vector).toEqual([1])
794+
})
795+
770796
test(`${permission} key: Try to search on deleted index and fail`, async () => {
771797
const client = await getClient(permission)
772798
const masterClient = await getClient('Master')

0 commit comments

Comments
 (0)