@@ -90,21 +90,25 @@ export class AggregateTool extends MongoDBToolBase {
9090
9191 // Check if aggregate operation uses an index if enabled
9292 if ( this . config . indexCheck ) {
93- const usesVectorSearchIndex = await this . isVectorSearchIndexUsed ( { database, collection, pipeline } ) ;
93+ const [ usesVectorSearchIndex , indexName ] = await this . isVectorSearchIndexUsed ( {
94+ database,
95+ collection,
96+ pipeline,
97+ } ) ;
9498 switch ( usesVectorSearchIndex ) {
95- case "no -vector-search-query" :
99+ case "not -vector-search-query" :
96100 await checkIndexUsage ( provider , database , collection , "aggregate" , async ( ) => {
97101 return provider
98102 . aggregate ( database , collection , pipeline , { } , { writeConcern : undefined } )
99103 . explain ( "queryPlanner" ) ;
100104 } ) ;
101105 break ;
102- case false :
106+ case "non-existent-index" :
103107 throw new MongoDBError (
104108 ErrorCodes . AtlasVectorSearchIndexNotFound ,
105- " Could not find provided vector search index."
109+ ` Could not find an index with name " ${ indexName } " in namespace " ${ database } . ${ collection } ".`
106110 ) ;
107- case true :
111+ case "valid-index" :
108112 // nothing to do, everything is correct so ready to run the query
109113 }
110114 }
@@ -289,7 +293,7 @@ export class AggregateTool extends MongoDBToolBase {
289293 database : string ;
290294 collection : string ;
291295 pipeline : Document [ ] ;
292- } ) : Promise < boolean | "no- vector-search-query" > {
296+ } ) : Promise < [ "valid-index" | "non-existent-index" | "not- vector-search-query", string ? ] > {
293297 // check if the pipeline contains a $vectorSearch stage
294298 let usesVectorSearch = false ;
295299 let indexName : string = "default" ;
@@ -304,7 +308,7 @@ export class AggregateTool extends MongoDBToolBase {
304308 }
305309
306310 if ( ! usesVectorSearch ) {
307- return "no -vector-search-query";
311+ return [ "not -vector-search-query"] ;
308312 }
309313
310314 const indexExists = await this . session . vectorSearchEmbeddingsManager . indexExists ( {
@@ -313,7 +317,7 @@ export class AggregateTool extends MongoDBToolBase {
313317 indexName,
314318 } ) ;
315319
316- return indexExists ;
320+ return [ indexExists ? "valid-index" : "non-existent-index" , indexName ] ;
317321 }
318322
319323 private generateMessage ( {
0 commit comments