11import { z } from "zod" ;
2- import { ToolArgs , ToolBase , ToolCategory , TelemetryToolMetadata } from "../tool.js" ;
2+ import { TelemetryToolMetadata , ToolArgs , ToolBase , ToolCategory } from "../tool.js" ;
33import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver" ;
44import { CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
55import { ErrorCodes , MongoDBError } from "../../errors.js" ;
@@ -10,6 +10,64 @@ export const DbOperationArgs = {
1010 collection : z . string ( ) . describe ( "Collection name" ) ,
1111} ;
1212
13+ export enum VectorFieldType {
14+ VECTOR = "vector" ,
15+ FILTER = "filter" ,
16+ }
17+ export const VectorIndexArgs = {
18+ name : z . string ( ) . describe ( "The name of the index" ) ,
19+ vectorDefinition : z
20+ . object ( {
21+ path : z
22+ . string ( )
23+ . min ( 1 )
24+ . describe (
25+ "Name of the field to index. For nested fields, use dot notation to specify path to embedded fields."
26+ ) ,
27+ numDimensions : z
28+ . number ( )
29+ . int ( )
30+ . min ( 1 )
31+ . max ( 8192 )
32+ . describe ( "Number of vector dimensions to enforce at index-time and query-time." ) ,
33+ similarity : z
34+ . enum ( [ "euclidean" , "cosine" , "dotProduct" ] )
35+ . describe ( "Vector similarity function to use to search for top K-nearest neighbors." ) ,
36+ quantization : z
37+ . enum ( [ "none" , "scalar" , "binary" ] )
38+ . default ( "none" )
39+ . optional ( )
40+ . describe (
41+ "Automatic vector quantization. Use this setting only if your embeddings are float or double vectors."
42+ ) ,
43+ } )
44+ . describe ( "The vector index definition." ) ,
45+ filterFields : z
46+ . array (
47+ z . object ( {
48+ path : z
49+ . string ( )
50+ . min ( 1 )
51+ . describe (
52+ "Name of the field to filter by. For nested fields, use dot notation to specify path to embedded fields."
53+ ) ,
54+ } )
55+ )
56+ . optional ( )
57+ . describe ( "Additional indexed fields that pre-filter data." ) ,
58+ } ;
59+
60+ type VectorDefinitionType = z . infer < typeof VectorIndexArgs . vectorDefinition > ;
61+ type FilterFieldsType = z . infer < typeof VectorIndexArgs . filterFields > ;
62+ export function buildVectorFields ( vectorDefinition : VectorDefinitionType , filterFields : FilterFieldsType ) : object [ ] {
63+ const typedVectorField = { ...vectorDefinition , type : VectorFieldType . VECTOR } ;
64+ const typedFilterFields = ( filterFields ?? [ ] ) . map ( ( f ) => ( {
65+ ...f ,
66+ type : VectorFieldType . FILTER ,
67+ } ) ) ;
68+ return [ typedVectorField , ...typedFilterFields ] ;
69+ }
70+
1371export const SearchIndexOperationArgs = {
1472 database : z . string ( ) . describe ( "Database name" ) ,
1573 collection : z . string ( ) . describe ( "Collection name" ) ,
0 commit comments