Skip to content

Commit aa6dd8a

Browse files
committed
chore: conditional usage of vector search param
1 parent 6ab9231 commit aa6dd8a

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

src/tools/mongodb/create/insertMany.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,30 @@ export class InsertManyTool extends MongoDBToolBase {
2525
.describe(
2626
"The array of documents to insert, matching the syntax of the document argument of db.collection.insertMany()."
2727
),
28-
embeddingParameters: zSupportedEmbeddingParametersWithInput
29-
.optional()
30-
.describe(
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."
32-
),
28+
...(this.isFeatureEnabled("vectorSearch")
29+
? {
30+
embeddingParameters: zSupportedEmbeddingParametersWithInput
31+
.optional()
32+
.describe(
33+
"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."
34+
),
35+
}
36+
: {}),
3337
};
3438
public operationType: OperationType = "create";
3539

3640
protected async execute({
3741
database,
3842
collection,
3943
documents,
40-
embeddingParameters,
44+
embeddingParameters: providedEmbeddingParameters,
4145
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
4246
const provider = await this.ensureConnected();
4347

48+
const embeddingParameters = this.isFeatureEnabled("vectorSearch")
49+
? (providedEmbeddingParameters as z.infer<typeof zSupportedEmbeddingParametersWithInput>)
50+
: undefined;
51+
4452
// Process documents to replace raw string values with generated embeddings
4553
documents = await this.replaceRawValuesWithEmbeddingsIfNecessary({
4654
database,

tests/accuracy/insertMany.embeddings.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ describeAccuracyTests(
187187
},
188188
],
189189
{
190-
userConfig: { voyageApiKey: "valid-key" },
190+
userConfig: { voyageApiKey: "valid-key", previewFeatures: "vectorSearch" },
191191
clusterConfig: {
192192
search: true,
193193
},

tests/integration/tools/mongodb/create/insertMany.test.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ describeWithMongoDB("insertMany tool when search is disabled", (integration) =>
2828
"The array of documents to insert, matching the syntax of the document argument of db.collection.insertMany().",
2929
required: true,
3030
},
31-
{
32-
name: "embeddingParameters",
33-
type: "object",
34-
description:
35-
"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.",
36-
required: false,
37-
},
3831
]);
3932

4033
validateThrowsForInvalidArguments(integration, "insert-many", [
@@ -598,11 +591,42 @@ describeWithMongoDB(
598591
getUserConfig: () => ({
599592
...defaultTestConfig,
600593
voyageApiKey: process.env.TEST_MDB_MCP_VOYAGE_API_KEY ?? "",
594+
previewFeatures: ["vectorSearch"],
601595
}),
602596
downloadOptions: { search: true },
603597
}
604598
);
605599

600+
describeWithMongoDB(
601+
"insertMany tool when vector search is enabled",
602+
(integration) => {
603+
validateToolMetadata(integration, "insert-many", "Insert an array of documents into a MongoDB collection", [
604+
...databaseCollectionParameters,
605+
{
606+
name: "documents",
607+
type: "array",
608+
description:
609+
"The array of documents to insert, matching the syntax of the document argument of db.collection.insertMany().",
610+
required: true,
611+
},
612+
{
613+
name: "embeddingParameters",
614+
type: "object",
615+
description:
616+
"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.",
617+
required: false,
618+
},
619+
]);
620+
},
621+
{
622+
getUserConfig: () => ({
623+
...defaultTestConfig,
624+
voyageApiKey: "valid-key",
625+
previewFeatures: ["vectorSearch"],
626+
}),
627+
}
628+
);
629+
606630
function extractInsertedIds(content: string): ObjectId[] {
607631
expect(content).toContain("Documents were inserted successfully.");
608632
expect(content).toContain("Inserted IDs:");

0 commit comments

Comments
 (0)