Skip to content

Commit 69aa6d0

Browse files
committed
add tests
1 parent 3c59376 commit 69aa6d0

File tree

4 files changed

+407
-249
lines changed

4 files changed

+407
-249
lines changed

src/tools/mongodb/create/createIndex.ts

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,51 @@ export class CreateIndexTool extends MongoDBToolBase {
2121
type: z.literal("vectorSearch"),
2222
fields: z
2323
.array(
24-
z.object({
25-
type: z
26-
.enum(["vector", "filter"])
27-
.describe(
28-
"Field type to use to index fields for vector search. You must specify `vector` for fields that contain vector embeddings and `filter` for additional fields to filter on."
29-
),
30-
path: z
31-
.string()
32-
.describe(
33-
"Name of the field to index. For nested fields, use dot notation to specify path to embedded fields"
34-
),
35-
numDimensions: z
36-
.number()
37-
.min(1)
38-
.max(8192)
39-
.describe(
40-
"Number of vector dimensions that MongoDB Vector Search enforces at index-time and query-time"
41-
),
42-
similarity: z
43-
.enum(["cosine", "euclidean", "dotProduct"])
44-
.default("cosine")
45-
.describe(
46-
"Vector similarity function to use to search for top K-nearest neighbors. You can set this field only for vector-type fields."
47-
),
48-
quantization: z
49-
.enum(["none", "scalar", "binary"])
50-
.optional()
51-
.default("none")
52-
.describe(
53-
"Type of automatic vector quantization for your vectors. Use this setting only if your embeddings are float or double vectors."
54-
),
55-
})
24+
z.discriminatedUnion("type", [
25+
z.object({
26+
type: z.literal("filter"),
27+
path: z
28+
.string()
29+
.describe(
30+
"Name of the field to index. For nested fields, use dot notation to specify path to embedded fields"
31+
),
32+
}),
33+
z.object({
34+
type: z.literal("vector"),
35+
path: z
36+
.string()
37+
.describe(
38+
"Name of the field to index. For nested fields, use dot notation to specify path to embedded fields"
39+
),
40+
numDimensions: z
41+
.number()
42+
.min(1)
43+
.max(8192)
44+
.describe(
45+
"Number of vector dimensions that MongoDB Vector Search enforces at index-time and query-time"
46+
),
47+
similarity: z
48+
.enum(["cosine", "euclidean", "dotProduct"])
49+
.default("cosine")
50+
.describe(
51+
"Vector similarity function to use to search for top K-nearest neighbors. You can set this field only for vector-type fields."
52+
),
53+
quantization: z
54+
.enum(["none", "scalar", "binary"])
55+
.optional()
56+
.default("none")
57+
.describe(
58+
"Type of automatic vector quantization for your vectors. Use this setting only if your embeddings are float or double vectors."
59+
),
60+
}),
61+
])
5662
)
63+
.nonempty()
64+
.refine((fields) => fields.some((f) => f.type === "vector"), {
65+
message: "At least one vector field must be defined",
66+
})
5767
.describe(
58-
"Definitions for the vector and filter fields to index, one definition per document. The fields array must contain at least one vector-type field definition."
68+
"Definitions for the vector and filter fields to index, one definition per document. You must specify `vector` for fields that contain vector embeddings and `filter` for additional fields to filter on. At least one vector-type field definition is required."
5969
),
6070
}),
6171
])

0 commit comments

Comments
 (0)