Skip to content

Commit f9ddea1

Browse files
committed
chore: add some integration tests with voyage AI
1 parent 2e4e049 commit f9ddea1

File tree

4 files changed

+122
-14
lines changed

4 files changed

+122
-14
lines changed

.github/workflows/code-health.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
run: npm ci
3535
- name: Run tests
3636
run: npm test
37+
env:
38+
TEST_MDB_MCP_VOYAGE_API_KEY=${{ secrets.TEST_MDB_MCP_VOYAGE_API_KEY }}
3739
- name: Upload test results
3840
if: always() && matrix.os == 'ubuntu-latest'
3941
uses: actions/upload-artifact@v4

src/common/search/embeddingsProvider.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class VoyageEmbeddingsProvider implements EmbeddingsProvider<VoyageModels> {
4848
): Promise<Embeddings[]> {
4949
const voyageParameters = {
5050
inputType: parameters.inputType,
51-
outputDimensions: parameters.numDimensions,
52-
quantization: "float", // it is hardcoded on purpose as we don't do quantization yet
51+
outputDimension: parameters.numDimensions,
52+
outputDtype: "float", // it is hardcoded on purpose as we don't do quantization yet
5353
};
5454

5555
const model = this.voyage.textEmbeddingModel(modelId);
@@ -61,15 +61,6 @@ class VoyageEmbeddingsProvider implements EmbeddingsProvider<VoyageModels> {
6161

6262
return embeddings;
6363
}
64-
65-
async embedOne<Model extends VoyageModels>(
66-
modelId: Model,
67-
content: EmbeddingsInput,
68-
parameters: EmbeddingParameters
69-
): Promise<Embeddings> {
70-
const embeddings = await this.embed(modelId, [content], parameters);
71-
return embeddings[0] ?? [];
72-
}
7364
}
7465

7566
export function getEmbeddingsProvider(userConfig: UserConfig): EmbeddingsProvider<VoyageModels> | undefined {

src/tools/mongodb/read/aggregate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const AggregateArgs = {
6060
pipeline: z
6161
.array(z.union([AnyStage, VectorSearchStage]))
6262
.describe(
63-
"An array of aggregation stages to execute. $vectorSearch can only appear as the first stage of the aggregation pipeline or as the first stage of a $unionWith subpipeline."
63+
"An array of aggregation stages to execute. $vectorSearch can only appear as the first stage of the aggregation pipeline or as the first stage of a $unionWith subpipeline. When using $vectorSearch, unless the user explicitly asks for the embeddings, $unset any embedding field to avoid reaching context limits."
6464
),
6565
responseBytesLimit: z.number().optional().default(ONE_MB).describe(`\
6666
The maximum number of bytes to return in the response. This value is capped by the server’s configured maxBytesPerQuery and cannot be exceeded. \

tests/integration/tools/mongodb/read/aggregate.test.ts

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ import {
44
validateThrowsForInvalidArguments,
55
getResponseContent,
66
defaultTestConfig,
7+
getDataFromUntrustedContent,
78
} from "../../../helpers.js";
89
import { beforeEach, describe, expect, it, vi, afterEach } from "vitest";
9-
import { describeWithMongoDB, getDocsFromUntrustedContent, validateAutoConnectBehavior } from "../mongodbHelpers.js";
10+
import {
11+
createVectorSearchIndexAndWait,
12+
describeWithMongoDB,
13+
getDocsFromUntrustedContent,
14+
validateAutoConnectBehavior,
15+
waitUntilSearchIsReady,
16+
} from "../mongodbHelpers.js";
1017
import * as constants from "../../../../../src/helpers/constants.js";
1118
import { freshInsertDocuments } from "./find.test.js";
1219

@@ -21,7 +28,7 @@ describeWithMongoDB("aggregate tool", (integration) => {
2128
{
2229
name: "pipeline",
2330
description:
24-
"An array of aggregation stages to execute. $vectorSearch can only appear as the first stage of the aggregation pipeline or as the first stage of a $unionWith subpipeline.",
31+
"An array of aggregation stages to execute. $vectorSearch can only appear as the first stage of the aggregation pipeline or as the first stage of a $unionWith subpipeline. When using $vectorSearch, unless the user explicitly asks for the embeddings, $unset any embedding field to avoid reaching context limits.",
2532
type: "array",
2633
required: true,
2734
},
@@ -378,3 +385,111 @@ describeWithMongoDB(
378385
getUserConfig: () => ({ ...defaultTestConfig, maxDocumentsPerQuery: -1, maxBytesPerQuery: -1 }),
379386
}
380387
);
388+
389+
const WEBSCALE_DOCUMENT_EMBEDDING = [
390+
-0.119673342, 0.028537489, 0.050937884, -0.093283832, 0.050631031, 0.008438504, -0.006635733, -0.082850769,
391+
-0.056768127, -0.06443949, 2.637e-5, 0.014422172, -0.087146744, -0.04173224, 0.039277405, 0.029304625, 0.004717892,
392+
0.117832206, 0.031759463, 0.019945556, 0.031606037, -0.155882195, -0.02086612, -0.090828992, -0.026849788,
393+
0.010126205, 0.009512496, 0.130106404, 0.042039096, -0.06658747, -0.055847559, -0.038663693, -0.072110862,
394+
0.073338278, 0.034521155, -0.058302399, -0.052472156, -0.036975995, 0.004602821, -0.06443949, -0.008093293,
395+
-0.061984655, 0.098807223, -0.1429943, 0.012197475, 0.003567186, -0.099420927, 0.087146744, -0.085305609,
396+
0.011737193, 0.02086612, -0.022707248, 0.04173224, 0.052779011, -0.005523385, 0.045721356, -0.094511256,
397+
-0.09512496, 0.086533032, -0.028844343, -0.042039096, -0.006750803, -0.050324172, 0.125810429, -0.052472156,
398+
-0.02147983, -0.013808462, 0.019945556, -0.072417714, 0.047869336, -0.03958426, -0.016877009, 0.071804009,
399+
0.017797574, 0.010816629, -0.144221723, -0.004986389, 0.089601576, -0.10985399, 0.101262063, -0.022707248,
400+
0.001006867, -0.002358946, 0.067508034, 0.124583013, -0.154654771, 0.031606037, -0.165701538, 0.003202796,
401+
-0.009512496, 0.080395937, 0.106171735, 0.004756248, 0.123969309, -0.01396189, 0.024088096, -0.013118039,
402+
0.02792378, 0.026849788, 0.020098984, -0.113536254, 2.3973e-5, -0.111081414, 0.051858447, -0.053392723, 0.060757235,
403+
0.044800788, -0.049403612, -0.075179406, 0.03958426, -0.013808462, -0.013578322, -0.079782225, -0.16447413,
404+
0.007594654, 0.039277405, 0.042039096, -0.035595149, 0.034828011, 0.006022024, 0.038356841, 0.045107644,
405+
0.084078193, -0.044493936, 0.024548376, 0.008822073, 0.027003214, -0.0487899, 0.067201182, -0.053392723,
406+
0.108012855, 0.070883438, 0.022553822, 0.110467695, -0.055540707, -0.030685471, -0.146676555, 0.064746343,
407+
-0.036669139, -0.046948772, 0.020559266, -0.142380595, -0.010049492, 0.015112595, 0.091442712, 0.022707248,
408+
-0.050937884, 0.026849788, -0.075486265, 0.018181141, 0.014192032, 0.041118532, -0.038049985, -0.011813907,
409+
0.067201182, 0.005293244, -0.059222963, -0.088374153, -0.098193504, 0.012350903, -0.030838897, 0.113536254,
410+
-0.035595149, 0.073338278, 0.146676555, -0.013271467, -0.043266516, -0.061984655, -0.054006428, 0.120287046,
411+
0.052472156, 0.022860678, -0.018948279, 0.007671368, -0.008822073, 0.021786686, 0.033447165, -0.065666914,
412+
0.025162086, 0.005715169, 0.042345952, 0.006520663, -0.025775796, 0.060757235, -0.044800788, 0.052779011,
413+
0.033140309, -0.033293735, -0.01856471, 0.045107644, -0.052779011, 0.038049985, -0.086533032, -0.077327386,
414+
-0.051244736, -0.155882195, 0.010356346, -0.15956445, 0.019331846, -0.04756248, -0.0145756, 0.130720109,
415+
-0.007096016, 0.041425385, -0.042652804, 0.005600099, -0.017030437, 0.002493195, 0.032219745, -0.054313287,
416+
0.044493936, -0.011813907, 0.025622368, 0.054006428, -0.010586488, -0.055847559, 0.034981437, 0.077327386,
417+
0.024548376, 0.106171735, 0.032066315, 0.069962874, 0.059836671, -0.031452607, -0.00027569, -0.022246968,
418+
0.058302399, -0.005369958, -0.101875767, 0.032986883, 0.09512496, -0.085919321, 0.005408315, -0.037436277,
419+
0.034367729, 0.077941097, -0.04756248, 0.000110276, -0.02792378, -0.059836671, 0.02086612, 0.060450379,
420+
-0.045107644, 0.002627444, 0.081623361, 0.054313287, -0.022400394, 0.065053202, 0.074565701, 0.04081168,
421+
-0.021786686, 0.044493936, 0.073338278, 0.003221974, 0.001419203, 0.00740287,
422+
];
423+
424+
describeWithMongoDB(
425+
"aggregate tool with atlas search enabled",
426+
(integration) => {
427+
it.skipIf(!process.env.TEST_MDB_MCP_VOYAGE_API_KEY)(
428+
"should be able to return elements from within a vector search query",
429+
async () => {
430+
await waitUntilSearchIsReady(integration.mongoClient());
431+
432+
const collection = integration.mongoClient().db(integration.randomDbName()).collection("databases");
433+
await collection.insertOne({ name: "mongodb", description_embedding: WEBSCALE_DOCUMENT_EMBEDDING });
434+
435+
await createVectorSearchIndexAndWait(
436+
integration.mongoClient(),
437+
integration.randomDbName(),
438+
"databases",
439+
[
440+
{
441+
type: "vector",
442+
path: "description_embedding",
443+
numDimensions: 256,
444+
similarity: "euclidean",
445+
quantization: "none",
446+
},
447+
]
448+
);
449+
450+
// now query the index
451+
await integration.connectMcpClient();
452+
const response = await integration.mcpClient().callTool({
453+
name: "aggregate",
454+
arguments: {
455+
database: integration.randomDbName(),
456+
collection: "databases",
457+
pipeline: [
458+
{
459+
$vectorSearch: {
460+
index: "default",
461+
path: "description_embedding",
462+
queryVector: "webscale",
463+
embeddingModel: "voyage-3-large",
464+
numCandidates: 10,
465+
limit: 10,
466+
},
467+
},
468+
{
469+
$project: {
470+
description_embedding: 0,
471+
},
472+
},
473+
],
474+
},
475+
});
476+
477+
const responseContent = getResponseContent(response);
478+
expect(responseContent).toContain("The aggregation resulted in 1 documents. Returning 1 documents.");
479+
const untrustedDocs = getDocsFromUntrustedContent<{ name: string }>(responseContent);
480+
expect(untrustedDocs).toHaveLength(1);
481+
expect(untrustedDocs[0].name).toBe("mongodb");
482+
}
483+
);
484+
},
485+
486+
{
487+
getUserConfig: () => ({
488+
...defaultTestConfig,
489+
voyageApiKey: process.env.TEST_MDB_MCP_VOYAGE_API_KEY,
490+
maxDocumentsPerQuery: -1,
491+
maxBytesPerQuery: -1,
492+
}),
493+
downloadOptions: { search: true },
494+
}
495+
);

0 commit comments

Comments
 (0)