Skip to content
Draft
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
21 changes: 20 additions & 1 deletion tests/integration/tools/mongodb/mongodbHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
return waitUntilSearchIndexIs(
collection,
searchIndex,
(index) => index.name === searchIndex && index.status === "READY",
(index) => index.name === searchIndex && index.status === "READY" && index.queryable,
timeout,
interval,
(searchIndexes) => {
Expand All @@ -356,6 +356,25 @@
);
}

export async function waitUntilSearchIndexHasResults(
collection: Collection,
pipeline: Document[],
timeout: number = SEARCH_WAIT_TIMEOUT,
interval: number = 1_000
): Promise<void> {
await vi.waitFor(
async () => {
const results = await collection.aggregate(pipeline).toArray();
if (results.length === 0) {
throw new Error(

Check failure on line 369 in tests/integration/tools/mongodb/mongodbHelpers.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

[unit-and-integration] tests/integration/tools/mongodb/read/aggregate.test.ts > aggregate tool with autoEmbed text support > should emit tool event with auto-embedding usage metadata pointing to `mongot`

Error: Vector search pipeline returned no results in 69de2815598851b2996949ba.movies ❯ vi.waitFor.timeout.timeout tests/integration/tools/mongodb/mongodbHelpers.ts:369:23

Check failure on line 369 in tests/integration/tools/mongodb/mongodbHelpers.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (ubuntu-latest)

[unit-and-integration] tests/integration/tools/mongodb/read/aggregate.test.ts > aggregate tool with autoEmbed text support > should be able to query autoEmbed text index

Error: Vector search pipeline returned no results in 69de2799598851b2996949b6.movies ❯ vi.waitFor.timeout.timeout tests/integration/tools/mongodb/mongodbHelpers.ts:369:23
`Vector search pipeline returned no results in ${collection.dbName}.${collection.collectionName}`
);
}
},
{ timeout, interval }
);
}

export async function createVectorSearchIndexAndWait(
mongoClient: MongoClient,
database: string,
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/tools/mongodb/read/aggregate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
describeWithMongoDB,
getDocsFromUntrustedContent,
validateAutoConnectBehavior,
waitUntilSearchIndexHasResults,
waitUntilSearchIndexIsQueryable,
waitUntilSearchIsReady,
} from "../mongodbHelpers.js";
Expand Down Expand Up @@ -993,7 +994,7 @@

// Ensure it aborted quickly, but possibly after some processing
expect(executionTime).toBeGreaterThanOrEqual(25);
expect(executionTime).toBeLessThan(50);

Check failure on line 997 in tests/integration/tools/mongodb/read/aggregate.test.ts

View workflow job for this annotation

GitHub Actions / Run MongoDB tests (macos-latest)

[unit-and-integration] tests/integration/tools/mongodb/read/aggregate.test.ts > aggregate tool with abort signal > should abort aggregate operation during cursor iteration

AssertionError: expected 65.5934159999997 to be less than 50 ❯ tests/integration/tools/mongodb/read/aggregate.test.ts:997:35
expect(result).toBeUndefined();
expectDefined(error);
expect(error.message).toContain("This operation was aborted");
Expand Down Expand Up @@ -1052,6 +1053,25 @@
// Auto-embed indexes take longer to build because they need to call the voyage API
// to generate embeddings for the documents. Using a longer timeout (120s).
await waitUntilSearchIndexIsQueryable(collection, "auto-embed-index", 120_000);

// Even after the index reports as queryable, the Voyage AI embeddings for existing
// documents may not be applied yet on first use (cold-start). Probe the actual
// $vectorSearch until it returns results before proceeding with the tests.
await waitUntilSearchIndexHasResults(
collection,
[
{
$vectorSearch: {
index: "auto-embed-index",
path: "plot",
query: { text: "food" },
limit: 1,
numCandidates: 2,
},
},
],
60_000
);
});

it("should be able to query autoEmbed text index", { timeout: 130_000 }, async () => {
Expand Down
Loading