From a2452499cd5f8f8398a2ae1b8028e4d914cc9ac8 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Wed, 26 Nov 2025 15:20:19 +0100 Subject: [PATCH 1/7] fix: fix the schema for embeddings parameter --- src/tools/mongodb/mongodbSchemas.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/mongodb/mongodbSchemas.ts b/src/tools/mongodb/mongodbSchemas.ts index 392273ba4..47ffadec2 100644 --- a/src/tools/mongodb/mongodbSchemas.ts +++ b/src/tools/mongodb/mongodbSchemas.ts @@ -19,10 +19,10 @@ export const zVoyageEmbeddingParameters = z.object({ outputDimension: z .preprocess( unboxNumber, - z.union([z.literal(256), z.literal(512), z.literal(1024), z.literal(2048), z.literal(4096)]) + z.union([z.literal("256"), z.literal("512"), z.literal("1024"), z.literal("2048"), z.literal("4096")]) ) .optional() - .default(1024), + .default("1024"), outputDtype: z.enum(["float", "int8", "uint8", "binary", "ubinary"]).optional().default("float"), }); From 6a78cfe845e02808017b4562084425823b1e6955 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Wed, 26 Nov 2025 15:24:46 +0100 Subject: [PATCH 2/7] chore: fix tests --- tests/unit/common/search/vectorSearchEmbeddingsManager.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/common/search/vectorSearchEmbeddingsManager.test.ts b/tests/unit/common/search/vectorSearchEmbeddingsManager.test.ts index afaf64c4e..09138a3c2 100644 --- a/tests/unit/common/search/vectorSearchEmbeddingsManager.test.ts +++ b/tests/unit/common/search/vectorSearchEmbeddingsManager.test.ts @@ -543,7 +543,7 @@ describe("VectorSearchEmbeddingsManager", () => { collection: "mycoll", path: "embedding_field", rawValues: ["oops"], - embeddingParameters: { model: "voyage-3-large", outputDimension: 1024, outputDtype: "float" } as const, + embeddingParameters: { model: "voyage-3-large", outputDimension: "1024", outputDtype: "float" } as const, inputType: "query" as const, }; From dc768449d7bea843e254d618b588c56d6a29bc09 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Wed, 26 Nov 2025 15:44:47 +0100 Subject: [PATCH 3/7] chore: use transform to pass integer at the end --- src/tools/mongodb/mongodbSchemas.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/tools/mongodb/mongodbSchemas.ts b/src/tools/mongodb/mongodbSchemas.ts index 47ffadec2..2c3912013 100644 --- a/src/tools/mongodb/mongodbSchemas.ts +++ b/src/tools/mongodb/mongodbSchemas.ts @@ -5,22 +5,10 @@ export const zVoyageModels = z .enum(["voyage-3-large", "voyage-3.5", "voyage-3.5-lite", "voyage-code-3"]) .default("voyage-3-large"); -// Zod does not undestand JS boxed numbers (like Int32) as integer literals, -// so we preprocess them to unwrap them so Zod understands them. -function unboxNumber(v: unknown): number { - if (v && typeof v === "object" && typeof v.valueOf === "function") { - const n = Number(v.valueOf()); - if (!Number.isNaN(n)) return n; - } - return v as number; -} - export const zVoyageEmbeddingParameters = z.object({ outputDimension: z - .preprocess( - unboxNumber, - z.union([z.literal("256"), z.literal("512"), z.literal("1024"), z.literal("2048"), z.literal("4096")]) - ) + .union([z.literal("256"), z.literal("512"), z.literal("1024"), z.literal("2048"), z.literal("4096")]) + .transform((value): number => Number.parseInt(value)) .optional() .default("1024"), outputDtype: z.enum(["float", "int8", "uint8", "binary", "ubinary"]).optional().default("float"), From 8fc3e9cb1390b47074d93099fed61c4d12208f3b Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Wed, 26 Nov 2025 15:46:28 +0100 Subject: [PATCH 4/7] chore: revert test fixes --- tests/unit/common/search/vectorSearchEmbeddingsManager.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/common/search/vectorSearchEmbeddingsManager.test.ts b/tests/unit/common/search/vectorSearchEmbeddingsManager.test.ts index 09138a3c2..afaf64c4e 100644 --- a/tests/unit/common/search/vectorSearchEmbeddingsManager.test.ts +++ b/tests/unit/common/search/vectorSearchEmbeddingsManager.test.ts @@ -543,7 +543,7 @@ describe("VectorSearchEmbeddingsManager", () => { collection: "mycoll", path: "embedding_field", rawValues: ["oops"], - embeddingParameters: { model: "voyage-3-large", outputDimension: "1024", outputDtype: "float" } as const, + embeddingParameters: { model: "voyage-3-large", outputDimension: 1024, outputDtype: "float" } as const, inputType: "query" as const, }; From 7d0006295a913feacd3f19e7fcb88bf38c7668ec Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Wed, 26 Nov 2025 16:09:26 +0100 Subject: [PATCH 5/7] chore: fix other relevant tests --- src/tools/mongodb/mongodbSchemas.ts | 11 +++++++++++ .../tools/mongodb/create/insertMany.test.ts | 4 ++-- .../tools/mongodb/read/aggregate.test.ts | 16 ++++++++-------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/tools/mongodb/mongodbSchemas.ts b/src/tools/mongodb/mongodbSchemas.ts index 2c3912013..deffe3bb6 100644 --- a/src/tools/mongodb/mongodbSchemas.ts +++ b/src/tools/mongodb/mongodbSchemas.ts @@ -6,6 +6,9 @@ export const zVoyageModels = z .default("voyage-3-large"); export const zVoyageEmbeddingParameters = z.object({ + // OpenAPI JSON Schema supports enum only as string so the public facing + // parameters that are fed to LLM providers should expect the dimensions as + // stringified numbers which are then transformed to actual numbers. outputDimension: z .union([z.literal("256"), z.literal("512"), z.literal("1024"), z.literal("2048"), z.literal("4096")]) .transform((value): number => Number.parseInt(value)) @@ -16,6 +19,14 @@ export const zVoyageEmbeddingParameters = z.object({ export const zVoyageAPIParameters = zVoyageEmbeddingParameters .extend({ + // Unlike, public facing parameters, `zVoyageEmbeddingParameters`, the + // api parameters need to be correct number and because we do an + // additional parsing before calling the API, we override the + // outputDimension schema to expect a union of numbers. + outputDimension: z + .union([z.literal(256), z.literal(512), z.literal(1024), z.literal(2048), z.literal(4096)]) + .optional() + .default(1024), inputType: z.enum(["query", "document"]), }) .strip(); diff --git a/tests/integration/tools/mongodb/create/insertMany.test.ts b/tests/integration/tools/mongodb/create/insertMany.test.ts index dda4ae71b..2170efb95 100644 --- a/tests/integration/tools/mongodb/create/insertMany.test.ts +++ b/tests/integration/tools/mongodb/create/insertMany.test.ts @@ -203,7 +203,7 @@ describeWithMongoDB( // embeddingParameters so that we can simulate the idea // of unknown or mismatched quantization. - // embeddingParameters: { outputDimension: 256, + // embeddingParameters: { outputDimension: "256", // outputDtype: "float", model: "voyage-3-large", input: // [ // { @@ -558,7 +558,7 @@ describeWithMongoDB( documents: [{ title: "The Matrix" }], embeddingParameters: { model: "voyage-3.5-lite", - outputDimension: 256, + outputDimension: "256", input: [{ titleEmbeddings: "The Matrix" }], }, }, diff --git a/tests/integration/tools/mongodb/read/aggregate.test.ts b/tests/integration/tools/mongodb/read/aggregate.test.ts index ff45433d1..f35ada510 100644 --- a/tests/integration/tools/mongodb/read/aggregate.test.ts +++ b/tests/integration/tools/mongodb/read/aggregate.test.ts @@ -444,7 +444,7 @@ If the user requests additional filtering, include filters in \`$vectorSearch.fi limit: 10, embeddingParameters: { model: "voyage-3-large", - outputDimension: 256, + outputDimension: "256", }, }, }, @@ -508,7 +508,7 @@ If the user requests additional filtering, include filters in \`$vectorSearch.fi limit: 10, embeddingParameters: { model: "voyage-3-large", - outputDimension: 256, + outputDimension: "256", outputDType: dataType, }, }, @@ -575,7 +575,7 @@ If the user requests additional filtering, include filters in \`$vectorSearch.fi limit: 10, embeddingParameters: { model: "voyage-3-large", - outputDimension: 256, + outputDimension: "256", outputDType: dataType, }, }, @@ -642,7 +642,7 @@ If the user requests additional filtering, include filters in \`$vectorSearch.fi limit: 10, embeddingParameters: { model: "voyage-3-large", - outputDimension: 256, + outputDimension: "256", outputDType: dataType, }, }, @@ -709,7 +709,7 @@ If the user requests additional filtering, include filters in \`$vectorSearch.fi limit: 10, embeddingParameters: { model: "voyage-3-large", - outputDimension: 256, + outputDimension: "256", outputDType: dataType, }, }, @@ -774,7 +774,7 @@ If the user requests additional filtering, include filters in \`$vectorSearch.fi limit: 10, embeddingParameters: { model: "voyage-3-large", - outputDimension: 256, + outputDimension: "256", outputDType: "float", }, filter: { name: 10 }, @@ -837,7 +837,7 @@ If the user requests additional filtering, include filters in \`$vectorSearch.fi limit: 10, embeddingParameters: { model: "voyage-3-large", - outputDimension: 256, + outputDimension: "256", outputDType: "float", }, filter: { name: 10 }, @@ -900,7 +900,7 @@ If the user requests additional filtering, include filters in \`$vectorSearch.fi limit: 10, embeddingParameters: { model: "voyage-3-large", - outputDimension: 256, + outputDimension: "256", outputDType: "float", }, filter: { name: 10 }, From 23810d5306b695af016ccbbc4b7d9df53d753e42 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Wed, 26 Nov 2025 16:12:27 +0100 Subject: [PATCH 6/7] Update src/tools/mongodb/mongodbSchemas.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/tools/mongodb/mongodbSchemas.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/mongodb/mongodbSchemas.ts b/src/tools/mongodb/mongodbSchemas.ts index deffe3bb6..8737de06c 100644 --- a/src/tools/mongodb/mongodbSchemas.ts +++ b/src/tools/mongodb/mongodbSchemas.ts @@ -19,7 +19,7 @@ export const zVoyageEmbeddingParameters = z.object({ export const zVoyageAPIParameters = zVoyageEmbeddingParameters .extend({ - // Unlike, public facing parameters, `zVoyageEmbeddingParameters`, the + // Unlike public facing parameters, `zVoyageEmbeddingParameters`, the // api parameters need to be correct number and because we do an // additional parsing before calling the API, we override the // outputDimension schema to expect a union of numbers. From 392b62064fb6e17882c6d80e2b6ba7eb02765447 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Wed, 26 Nov 2025 16:23:18 +0100 Subject: [PATCH 7/7] chore: apply default before transform --- src/tools/mongodb/mongodbSchemas.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tools/mongodb/mongodbSchemas.ts b/src/tools/mongodb/mongodbSchemas.ts index 8737de06c..d9c16a09d 100644 --- a/src/tools/mongodb/mongodbSchemas.ts +++ b/src/tools/mongodb/mongodbSchemas.ts @@ -11,9 +11,9 @@ export const zVoyageEmbeddingParameters = z.object({ // stringified numbers which are then transformed to actual numbers. outputDimension: z .union([z.literal("256"), z.literal("512"), z.literal("1024"), z.literal("2048"), z.literal("4096")]) + .default("1024") .transform((value): number => Number.parseInt(value)) - .optional() - .default("1024"), + .optional(), outputDtype: z.enum(["float", "int8", "uint8", "binary", "ubinary"]).optional().default("float"), }); @@ -25,8 +25,8 @@ export const zVoyageAPIParameters = zVoyageEmbeddingParameters // outputDimension schema to expect a union of numbers. outputDimension: z .union([z.literal(256), z.literal(512), z.literal(1024), z.literal(2048), z.literal(4096)]) - .optional() - .default(1024), + .default(1024) + .optional(), inputType: z.enum(["query", "document"]), }) .strip();