Skip to content

Commit 4662933

Browse files
authored
feat: AI-powered search changes for v1.11 (#1742)
1 parent 1f5be1b commit 4662933

File tree

5 files changed

+79
-79
lines changed

5 files changed

+79
-79
lines changed

src/types/types.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export type SearchForFacetValuesResponse = {
9898
};
9999

100100
export type HybridSearch = {
101-
embedder?: string;
101+
embedder: string;
102102
semanticRatio?: number;
103103
};
104104

@@ -389,6 +389,8 @@ export type OpenAiEmbedder = {
389389
dimensions?: number;
390390
distribution?: Distribution;
391391
url?: string;
392+
documentTemplateMaxBytes?: number;
393+
binaryQuantized?: boolean;
392394
};
393395

394396
export type HuggingFaceEmbedder = {
@@ -397,12 +399,15 @@ export type HuggingFaceEmbedder = {
397399
revision?: string;
398400
documentTemplate?: string;
399401
distribution?: Distribution;
402+
documentTemplateMaxBytes?: number;
403+
binaryQuantized?: boolean;
400404
};
401405

402406
export type UserProvidedEmbedder = {
403407
source: "userProvided";
404408
dimensions: number;
405409
distribution?: Distribution;
410+
binaryQuantized?: boolean;
406411
};
407412

408413
export type RestEmbedder = {
@@ -415,6 +420,8 @@ export type RestEmbedder = {
415420
request: Record<string, any>;
416421
response: Record<string, any>;
417422
headers?: Record<string, string>;
423+
documentTemplateMaxBytes?: number;
424+
binaryQuantized?: boolean;
418425
};
419426

420427
export type OllamaEmbedder = {
@@ -425,6 +432,8 @@ export type OllamaEmbedder = {
425432
documentTemplate?: string;
426433
distribution?: Distribution;
427434
dimensions?: number;
435+
documentTemplateMaxBytes?: number;
436+
binaryQuantized?: boolean;
428437
};
429438

430439
export type Embedder =

tests/__snapshots__/settings.test.ts.snap

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ exports[`Test on settings > Admin key: Update embedders settings 1`] = `
249249
"distinctAttribute": null,
250250
"embedders": {
251251
"default": {
252-
"documentTemplate": "{% for field in fields %} {{ field.name }}: {{ field.value }}
253-
{% endfor %}",
252+
"documentTemplate": "{% for field in fields %}{% if field.is_searchable and field.value != nil %}{{ field.name }}: {{ field.value }}
253+
{% endif %}{% endfor %}",
254+
"documentTemplateMaxBytes": 400,
254255
"model": "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
255256
"source": "huggingFace",
256257
},
@@ -804,8 +805,9 @@ exports[`Test on settings > Master key: Update embedders settings 1`] = `
804805
"distinctAttribute": null,
805806
"embedders": {
806807
"default": {
807-
"documentTemplate": "{% for field in fields %} {{ field.name }}: {{ field.value }}
808-
{% endfor %}",
808+
"documentTemplate": "{% for field in fields %}{% if field.is_searchable and field.value != nil %}{{ field.name }}: {{ field.value }}
809+
{% endif %}{% endfor %}",
810+
"documentTemplateMaxBytes": 400,
809811
"model": "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2",
810812
"source": "huggingFace",
811813
},

tests/embedders.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
9090
mean: 0.7,
9191
sigma: 0.3,
9292
},
93+
binaryQuantized: false,
9394
},
9495
};
9596
const task: EnqueuedTask = await client
@@ -101,6 +102,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
101102
const response: Embedders = await client.index(index.uid).getEmbedders();
102103

103104
expect(response).toEqual(newEmbedder);
105+
expect(response).not.toHaveProperty("documentTemplateMaxBytes");
104106
});
105107

106108
test(`${permission} key: Update embedders with 'openAi' source`, async () => {
@@ -118,6 +120,8 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
118120
sigma: 0.3,
119121
},
120122
url: "https://api.openai.com/v1/embeddings",
123+
documentTemplateMaxBytes: 500,
124+
binaryQuantized: false,
121125
},
122126
};
123127
const task: EnqueuedTask = await client
@@ -147,6 +151,8 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
147151
mean: 0.7,
148152
sigma: 0.3,
149153
},
154+
documentTemplateMaxBytes: 500,
155+
binaryQuantized: false,
150156
},
151157
};
152158
const task: EnqueuedTask = await client
@@ -188,6 +194,8 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
188194
headers: {
189195
"Custom-Header": "CustomValue",
190196
},
197+
documentTemplateMaxBytes: 500,
198+
binaryQuantized: false,
191199
},
192200
};
193201
const task: EnqueuedTask = await client
@@ -219,6 +227,8 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
219227
sigma: 0.3,
220228
},
221229
dimensions: 512,
230+
documentTemplateMaxBytes: 500,
231+
binaryQuantized: false,
222232
},
223233
};
224234
const task: EnqueuedTask = await client
@@ -266,6 +276,58 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
266276
expect(response).toEqual(null);
267277
});
268278

279+
test(`${permission} key: search (POST) with vectors`, async () => {
280+
const client = await getClient(permission);
281+
282+
const { taskUid } = await client.index(index.uid).updateEmbedders({
283+
default: {
284+
source: "userProvided",
285+
dimensions: 1,
286+
},
287+
});
288+
await client.waitForTask(taskUid);
289+
290+
const response = await client.index(index.uid).search("", {
291+
vector: [1],
292+
hybrid: {
293+
embedder: "default",
294+
semanticRatio: 1.0,
295+
},
296+
});
297+
298+
expect(response).toHaveProperty("hits");
299+
expect(response).toHaveProperty("semanticHitCount");
300+
// Those fields are no longer returned by the search response
301+
// We want to ensure that they don't appear in it anymore
302+
expect(response).not.toHaveProperty("vector");
303+
expect(response).not.toHaveProperty("_semanticScore");
304+
});
305+
306+
test(`${permission} key: search (GET) with vectors`, async () => {
307+
const client = await getClient(permission);
308+
309+
const { taskUid } = await client.index(index.uid).updateEmbedders({
310+
default: {
311+
source: "userProvided",
312+
dimensions: 1,
313+
},
314+
});
315+
await client.waitForTask(taskUid);
316+
317+
const response = await client.index(index.uid).searchGet("", {
318+
vector: [1],
319+
hybridEmbedder: "default",
320+
hybridSemanticRatio: 1.0,
321+
});
322+
323+
expect(response).toHaveProperty("hits");
324+
expect(response).toHaveProperty("semanticHitCount");
325+
// Those fields are no longer returned by the search response
326+
// We want to ensure that they don't appear in it anymore
327+
expect(response).not.toHaveProperty("vector");
328+
expect(response).not.toHaveProperty("_semanticScore");
329+
});
330+
269331
test(`${permission} key: search for similar documents`, async () => {
270332
const client = await getClient(permission);
271333

@@ -288,6 +350,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
288350
await client.waitForTask(documentAdditionTask);
289351

290352
const response = await client.index(index.uid).searchSimilarDocuments({
353+
embedder: "manual",
291354
id: "143",
292355
});
293356

tests/get_search.test.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -457,41 +457,6 @@ describe.each([
457457
"The filter query parameter should be in string format when using searchGet",
458458
);
459459
});
460-
test(`${permission} key: search with vectors`, async () => {
461-
const client = await getClient(permission);
462-
const adminClient = await getClient("Admin");
463-
const adminKey = await getKey("Admin");
464-
465-
await fetch(`${HOST}/experimental-features`, {
466-
body: JSON.stringify({ vectorStore: true }),
467-
headers: {
468-
Authorization: `Bearer ${adminKey}`,
469-
"Content-Type": "application/json",
470-
},
471-
method: "PATCH",
472-
});
473-
474-
const { taskUid } = await adminClient
475-
.index(emptyIndex.uid)
476-
.updateEmbedders({
477-
default: {
478-
source: "userProvided",
479-
dimensions: 1,
480-
},
481-
});
482-
await adminClient.waitForTask(taskUid);
483-
484-
const response = await client
485-
.index(emptyIndex.uid)
486-
.searchGet("", { vector: [1], hybridSemanticRatio: 1.0 });
487-
488-
expect(response).toHaveProperty("hits");
489-
expect(response).toHaveProperty("semanticHitCount");
490-
// Those fields are no longer returned by the search response
491-
// We want to ensure that they don't appear in it anymore
492-
expect(response).not.toHaveProperty("vector");
493-
expect(response).not.toHaveProperty("_semanticScore");
494-
});
495460

496461
test(`${permission} key: search without vectors`, async () => {
497462
const client = await getClient(permission);

tests/search.test.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -936,45 +936,6 @@ describe.each([
936936
expect(response.hits.length).toEqual(0);
937937
});
938938

939-
test(`${permission} key: search with vectors`, async () => {
940-
const client = await getClient(permission);
941-
const adminClient = await getClient("Admin");
942-
const adminKey = await getKey("Admin");
943-
944-
await fetch(`${HOST}/experimental-features`, {
945-
body: JSON.stringify({ vectorStore: true }),
946-
headers: {
947-
Authorization: `Bearer ${adminKey}`,
948-
"Content-Type": "application/json",
949-
},
950-
method: "PATCH",
951-
});
952-
953-
const { taskUid } = await adminClient
954-
.index(emptyIndex.uid)
955-
.updateEmbedders({
956-
default: {
957-
source: "userProvided",
958-
dimensions: 1,
959-
},
960-
});
961-
await adminClient.waitForTask(taskUid);
962-
963-
const response = await client.index(emptyIndex.uid).search("", {
964-
vector: [1],
965-
hybrid: {
966-
semanticRatio: 1.0,
967-
},
968-
});
969-
970-
expect(response).toHaveProperty("hits");
971-
expect(response).toHaveProperty("semanticHitCount");
972-
// Those fields are no longer returned by the search response
973-
// We want to ensure that they don't appear in it anymore
974-
expect(response).not.toHaveProperty("vector");
975-
expect(response).not.toHaveProperty("_semanticScore");
976-
});
977-
978939
test(`${permission} key: search without vectors`, async () => {
979940
const client = await getClient(permission);
980941
const response = await client.index(index.uid).search("prince", {});

0 commit comments

Comments
 (0)