Skip to content

Commit f0d4a38

Browse files
committed
chore: some improvements from the PR comments
1 parent 90435b1 commit f0d4a38

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/tools/mongodb/read/aggregate.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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({

tests/integration/tools/mongodb/read/aggregate.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ describeWithMongoDB(
430430
});
431431

432432
const responseContent = getResponseContent(response);
433-
expect(responseContent).toContain("Error running aggregate: Could not find provided vector search index.");
433+
expect(responseContent).toContain(
434+
`Error running aggregate: Could not find an index with name "non_existing" in namespace "${integration.randomDbName()}.databases".`
435+
);
434436
});
435437

436438
for (const [dataType, embedding] of Object.entries(DOCUMENT_EMBEDDINGS)) {

0 commit comments

Comments
 (0)