Skip to content

Commit 5221d92

Browse files
committed
add numPartitions
1 parent 3c88363 commit 5221d92

File tree

7 files changed

+63
-17
lines changed

7 files changed

+63
-17
lines changed

.vscode/launch.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"name": "Attach by Process ID",
9+
"processId": "${command:PickProcess}",
10+
"request": "attach",
11+
"skipFiles": ["<node_internals>/**"],
12+
"type": "node"
13+
},
714
{
815
"type": "node",
916
"request": "launch",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"dist"
3434
],
3535
"scripts": {
36-
"start": "node dist/index.js --transport http --loggers stderr mcp",
36+
"start": "node dist/index.js --transport http --loggers stderr mcp --previewFeatures vectorSearch",
3737
"start:stdio": "node dist/index.js --transport stdio --loggers stderr mcp",
3838
"prepare": "npm run build",
3939
"build:clean": "rm -rf dist",

src/tools/args.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ export const ALLOWED_CLUSTER_NAME_CHARACTERS_ERROR =
1818
const ALLOWED_PROJECT_NAME_CHARACTERS_REGEX = /^[a-zA-Z0-9\s()@&+:._',-]+$/;
1919
export const ALLOWED_PROJECT_NAME_CHARACTERS_ERROR =
2020
"Project names can't be longer than 64 characters and can only contain letters, numbers, spaces, and the following symbols: ( ) @ & + : . _ - ' ,";
21+
22+
// Zod does not undestand JS boxed numbers (like Int32) as integer literals,
23+
// so we preprocess them to unwrap them so Zod understands them.
24+
function unboxNumber(v: unknown): number {
25+
if (v && typeof v === "object" && typeof v.valueOf === "function") {
26+
const n = Number(v.valueOf());
27+
if (!Number.isNaN(n)) return n;
28+
}
29+
return v as number;
30+
}
31+
2132
export const CommonArgs = {
2233
string: (): ZodString => z.string().regex(NO_UNICODE_REGEX, NO_UNICODE_ERROR),
2334

@@ -27,6 +38,11 @@ export const CommonArgs = {
2738
.min(1, `${fieldName} is required`)
2839
.length(24, `${fieldName} must be exactly 24 characters`)
2940
.regex(/^[0-9a-fA-F]+$/, `${fieldName} must contain only hexadecimal characters`),
41+
numberEnum: <Options extends Readonly<[z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]>>(
42+
values: Options
43+
): z.ZodEffects<z.ZodUnion<Options>> => {
44+
return z.preprocess(unboxNumber, z.union(values));
45+
},
3046
};
3147

3248
export const AtlasArgs = {

src/tools/mongodb/create/createIndex.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { type ToolArgs, type OperationType } from "../../tool.js";
55
import type { IndexDirection } from "mongodb";
66
import { quantizationEnum } from "../../../common/search/vectorSearchEmbeddingsManager.js";
77
import { similarityValues } from "../../../common/schemas.js";
8+
import { CommonArgs } from "../../args.js";
89

910
export class CreateIndexTool extends MongoDBToolBase {
1011
private vectorSearchIndexDefinition = z
@@ -121,6 +122,11 @@ export class CreateIndexTool extends MongoDBToolBase {
121122
.describe(
122123
"Document describing the index to create. Either `dynamic` must be `true` and `fields` empty or `dynamic` must be `false` and at least one field must be defined in the `fields` document."
123124
),
125+
numPartitions: CommonArgs.numberEnum([z.literal(1), z.literal(2), z.literal(4)])
126+
.default(1)
127+
.describe(
128+
"Specifies the number of sub-indexes to create if the document count exceeds two billion. If omitted, defaults to 1."
129+
),
124130
})
125131
.describe("Definition for an Atlas Search (lexical) index.");
126132

@@ -204,6 +210,7 @@ export class CreateIndexTool extends MongoDBToolBase {
204210
definition: {
205211
mappings: definition.mappings,
206212
analyzer: definition.analyzer,
213+
numPartitions: definition.numPartitions,
207214
},
208215
type: "search",
209216
},

src/tools/mongodb/mongodbSchemas.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
import z from "zod";
2-
import { zEJSON } from "../args.js";
2+
import { CommonArgs, zEJSON } from "../args.js";
33

44
export const zVoyageModels = z
55
.enum(["voyage-3-large", "voyage-3.5", "voyage-3.5-lite", "voyage-code-3"])
66
.default("voyage-3-large");
77

8-
// Zod does not undestand JS boxed numbers (like Int32) as integer literals,
9-
// so we preprocess them to unwrap them so Zod understands them.
10-
function unboxNumber(v: unknown): number {
11-
if (v && typeof v === "object" && typeof v.valueOf === "function") {
12-
const n = Number(v.valueOf());
13-
if (!Number.isNaN(n)) return n;
14-
}
15-
return v as number;
16-
}
17-
188
export const zVoyageEmbeddingParameters = z.object({
19-
outputDimension: z
20-
.preprocess(
21-
unboxNumber,
22-
z.union([z.literal(256), z.literal(512), z.literal(1024), z.literal(2048), z.literal(4096)])
23-
)
9+
outputDimension: CommonArgs.numberEnum([
10+
z.literal(256),
11+
z.literal(512),
12+
z.literal(1024),
13+
z.literal(2048),
14+
z.literal(4096),
15+
])
2416
.optional()
2517
.default(1024),
2618
outputDtype: z.enum(["float", "int8", "uint8", "binary", "ubinary"]).optional().default("float"),

tests/accuracy/aggregate.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,26 @@ describeAccuracyTests([
421421
},
422422
},
423423
},
424+
{
425+
prompt: "Run a search query on mflix.movies to find all movies that mention 'space travel' in the plot.",
426+
expectedToolCalls: [
427+
{
428+
toolName: "aggregate",
429+
parameters: {
430+
database: "mflix",
431+
collection: "movies",
432+
pipeline: [
433+
{
434+
$search: {
435+
index: "default",
436+
text: {
437+
query: "space travel",
438+
},
439+
},
440+
},
441+
],
442+
},
443+
},
444+
],
445+
},
424446
]);

tests/accuracy/createIndex.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ describeAccuracyTests(
173173
mappings: {
174174
dynamic: true,
175175
},
176+
numPartitions: Matcher.anyOf(Matcher.undefined, Matcher.number()),
176177
},
177178
],
178179
},
@@ -204,6 +205,7 @@ describeAccuracyTests(
204205
},
205206
},
206207
},
208+
numPartitions: Matcher.anyOf(Matcher.undefined, Matcher.number()),
207209
},
208210
],
209211
},

0 commit comments

Comments
 (0)