Skip to content

Commit 60cf24d

Browse files
committed
add a hint to the llm that the vector may take a while to build
1 parent afde113 commit 60cf24d

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/tools/mongodb/create/createIndex.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export class CreateIndexTool extends MongoDBToolBase {
100100
throw new Error("Index definition not provided. Expected one of the following: `classic`, `vectorSearch`");
101101
}
102102

103+
let responseClarification = "";
104+
103105
switch (definition.type) {
104106
case "classic":
105107
indexes = await provider.createIndexes(database, collection, [
@@ -139,6 +141,9 @@ export class CreateIndexTool extends MongoDBToolBase {
139141
type: "vectorSearch",
140142
},
141143
]);
144+
145+
responseClarification =
146+
" Since this is a vector search index, it may take a while for the index to build. Use the `list-indexes` tool to check the index status.";
142147
}
143148

144149
break;
@@ -147,7 +152,7 @@ export class CreateIndexTool extends MongoDBToolBase {
147152
return {
148153
content: [
149154
{
150-
text: `Created the index "${indexes[0]}" on collection "${collection}" in database "${database}"`,
155+
text: `Created the index "${indexes[0]}" on collection "${collection}" in database "${database}".${responseClarification}`,
151156
type: "text",
152157
},
153158
],

tests/integration/tools/mongodb/create/createIndex.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describeWithMongoDB(
134134
{
135135
collection: "bar",
136136
database: "test",
137-
definition: [{ type: "vectorSearch", fields: [{ type: "vector", path: "foo" }] }],
137+
definition: [{ type: "vectorSearch", fields: [{ type: "vector", path: true }] }],
138138
},
139139
{
140140
collection: "bar",
@@ -190,7 +190,7 @@ describeWithMongoDB(
190190

191191
const content = getResponseContent(response.content);
192192
expect(content).toEqual(
193-
`Created the index "my-index" on collection "coll1" in database "${integration.randomDbName()}"`
193+
`Created the index "my-index" on collection "coll1" in database "${integration.randomDbName()}".`
194194
);
195195

196196
await validateIndex("coll1", [{ name: "my-index", key: { prop1: 1 } }]);
@@ -209,7 +209,7 @@ describeWithMongoDB(
209209

210210
const content = getResponseContent(response.content);
211211
expect(content).toEqual(
212-
`Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}"`
212+
`Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}".`
213213
);
214214
await validateIndex("coll1", [{ name: "prop1_1", key: { prop1: 1 } }]);
215215
});
@@ -226,7 +226,7 @@ describeWithMongoDB(
226226
});
227227

228228
expect(getResponseContent(response.content)).toEqual(
229-
`Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}"`
229+
`Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}".`
230230
);
231231

232232
response = await integration.mcpClient().callTool({
@@ -239,7 +239,7 @@ describeWithMongoDB(
239239
});
240240

241241
expect(getResponseContent(response.content)).toEqual(
242-
`Created the index "prop2_-1" on collection "coll1" in database "${integration.randomDbName()}"`
242+
`Created the index "prop2_-1" on collection "coll1" in database "${integration.randomDbName()}".`
243243
);
244244

245245
await validateIndex("coll1", [
@@ -260,7 +260,7 @@ describeWithMongoDB(
260260
});
261261

262262
expect(getResponseContent(response.content)).toEqual(
263-
`Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}"`
263+
`Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}".`
264264
);
265265

266266
response = await integration.mcpClient().callTool({
@@ -273,7 +273,7 @@ describeWithMongoDB(
273273
});
274274

275275
expect(getResponseContent(response.content)).toEqual(
276-
`Created the index "prop1_-1" on collection "coll1" in database "${integration.randomDbName()}"`
276+
`Created the index "prop1_-1" on collection "coll1" in database "${integration.randomDbName()}".`
277277
);
278278

279279
await validateIndex("coll1", [
@@ -294,7 +294,7 @@ describeWithMongoDB(
294294
});
295295

296296
expect(getResponseContent(response.content)).toEqual(
297-
`Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}"`
297+
`Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}".`
298298
);
299299

300300
response = await integration.mcpClient().callTool({
@@ -307,7 +307,7 @@ describeWithMongoDB(
307307
});
308308

309309
expect(getResponseContent(response.content)).toEqual(
310-
`Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}"`
310+
`Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}".`
311311
);
312312

313313
await validateIndex("coll1", [{ name: "prop1_1", key: { prop1: 1 } }]);
@@ -365,7 +365,7 @@ describeWithMongoDB(
365365
});
366366

367367
expect(getResponseContent(response.content)).toEqual(
368-
`Created the index "prop1_${direction}" on collection "coll1" in database "${integration.randomDbName()}"`
368+
`Created the index "prop1_${direction}" on collection "coll1" in database "${integration.randomDbName()}".`
369369
);
370370

371371
let expectedKey: object = { prop1: direction };
@@ -386,7 +386,7 @@ describeWithMongoDB(
386386
collection: "coll1",
387387
definition: [{ type: "classic", keys: { prop1: 1 } }],
388388
},
389-
expectedResponse: `Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}"`,
389+
expectedResponse: `Created the index "prop1_1" on collection "coll1" in database "${integration.randomDbName()}".`,
390390
};
391391
});
392392
},
@@ -480,7 +480,7 @@ describeWithMongoDB(
480480

481481
const content = getResponseContent(response.content);
482482
expect(content).toEqual(
483-
`Created the index "vector_1_vector" on collection "${collection}" in database "${integration.randomDbName()}"`
483+
`Created the index "vector_1_vector" on collection "${collection}" in database "${integration.randomDbName()}". Since this is a vector search index, it may take a while for the index to build. Use the \`list-indexes\` tool to check the index status.`
484484
);
485485

486486
const indexes = await provider.getSearchIndexes(integration.randomDbName(), collection);

0 commit comments

Comments
 (0)