Skip to content

Commit ab71348

Browse files
committed
chore: fix tests
1 parent 43c4d6c commit ab71348

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed

src/common/search/vectorSearchEmbeddingsManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class VectorSearchEmbeddingsManager {
105105
}
106106
}
107107

108-
private async findFieldsWithWrongEmbeddings(
108+
public async findFieldsWithWrongEmbeddings(
109109
{
110110
database,
111111
collection,

src/tools/mongodb/create/insertMany.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class InsertManyTool extends MongoDBToolBase {
2828
embeddingParameters: zSupportedEmbeddingParametersWithInput
2929
.optional()
3030
.describe(
31-
"The embedding model and its parameters to use to generate embeddings for fields that have vector search indexes. When a field has a vector search index and contains a plain text string in the document, embeddings will be automatically generated from that string value. Note to LLM: If unsure which embedding model to use, ask the user before providing one."
31+
"The embedding model and its parameters to use to generate embeddings for fields with vector search indexes. Note to LLM: If unsure which embedding model to use, ask the user before providing one."
3232
),
3333
};
3434
public operationType: OperationType = "create";

tests/unit/common/search/vectorSearchEmbeddingsManager.test.ts

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, vi, beforeEach } from "vitest";
1+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
22
import type { MockedFunction } from "vitest";
33
import { VectorSearchEmbeddingsManager } from "../../../../src/common/search/vectorSearchEmbeddingsManager.js";
44
import type {
@@ -411,20 +411,65 @@ describe("VectorSearchEmbeddingsManager", () => {
411411
);
412412
});
413413

414-
describe("when atlas search is not available", () => {
414+
describe("assertVectorSearchIndexExists", () => {
415415
beforeEach(() => {
416416
embeddings = new VectorSearchEmbeddingsManager(
417417
embeddingValidationEnabled,
418418
connectionManager,
419419
new Map(),
420420
getMockedEmbeddingsProvider
421421
);
422+
});
423+
424+
afterEach(() => {
425+
provider.getSearchIndexes.mockReset();
426+
});
427+
428+
it("does not throw an exception when index is available for path", async () => {
429+
provider.getSearchIndexes.mockResolvedValue([
430+
{
431+
id: "65e8c766d0450e3e7ab9855f",
432+
name: "vector-search-test",
433+
type: "vectorSearch",
434+
status: "READY",
435+
queryable: true,
436+
latestDefinition: {
437+
fields: [
438+
{
439+
type: "vector",
440+
path: embeddingToGenerate.path,
441+
numDimensions: 1024,
442+
similarity: "euclidean",
443+
},
444+
],
445+
},
446+
},
447+
]);
448+
await expect(
449+
embeddings.assertVectorSearchIndexExists({
450+
database,
451+
collection,
452+
path: embeddingToGenerate.path,
453+
})
454+
).resolves.not.toThrowError();
455+
});
422456

457+
it("throws an exception when atlas search is not available", async () => {
423458
provider.getSearchIndexes.mockRejectedValue(new Error());
459+
await expect(
460+
embeddings.assertVectorSearchIndexExists({
461+
database,
462+
collection,
463+
path: embeddingToGenerate.path,
464+
})
465+
).rejects.toThrowError();
424466
});
425467

426-
it("throws an exception", async () => {
427-
await expect(embeddings.generateEmbeddings(embeddingToGenerate)).rejects.toThrowError();
468+
it("throws an exception when no index is available for path", async () => {
469+
provider.getSearchIndexes.mockResolvedValue([]);
470+
await expect(
471+
embeddings.assertVectorSearchIndexExists({ database, collection, path: embeddingToGenerate.path })
472+
).rejects.toThrowError();
428473
});
429474
});
430475

@@ -459,12 +504,6 @@ describe("VectorSearchEmbeddingsManager", () => {
459504
);
460505
});
461506

462-
describe("when no index is available for path", () => {
463-
it("throws an exception", async () => {
464-
await expect(embeddings.generateEmbeddings(embeddingToGenerate)).rejects.toThrowError();
465-
});
466-
});
467-
468507
describe("when index is available on path", () => {
469508
beforeEach(() => {
470509
provider.getSearchIndexes.mockResolvedValue([

0 commit comments

Comments
 (0)