Skip to content

Commit 7a4644f

Browse files
chore: make pipeline description relevant to feature flag
1 parent aa2162d commit 7a4644f

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

src/tools/mongodb/read/aggregate.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
type VectorSearchIndex,
1919
} from "../../../helpers/assertVectorSearchFilterFieldsAreIndexed.js";
2020

21-
const pipelineDescription = `\
21+
const pipelineDescriptionWithVectorSearch = `\
2222
An array of aggregation stages to execute.
2323
\`$vectorSearch\` **MUST** be the first stage of the pipeline, or the first stage of a \`$unionWith\` subpipeline.
2424
### Usage Rules for \`$vectorSearch\`
@@ -34,11 +34,13 @@ If the user requests additional filtering, include filters in \`$vectorSearch.fi
3434
- If no requested filters are valid prefilters, omit the filter key from $vectorSearch.\
3535
`;
3636

37+
const genericPipelineDescription = "An array of aggregation stages to execute.";
38+
3739
export const getAggregateArgs = (vectorSearchEnabled: boolean) =>
3840
({
3941
pipeline: z
4042
.array(vectorSearchEnabled ? z.union([AnyAggregateStage, VectorSearchStage]) : AnyAggregateStage)
41-
.describe(pipelineDescription),
43+
.describe(vectorSearchEnabled ? pipelineDescriptionWithVectorSearch : genericPipelineDescription),
4244
responseBytesLimit: z.number().optional().default(ONE_MB).describe(`\
4345
The maximum number of bytes to return in the response. This value is capped by the server's configured maxBytesPerQuery and cannot be exceeded. \
4446
Note to LLM: If the entire aggregation result is required, use the "export" tool instead of increasing this limit.\

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

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,7 @@ describeWithMongoDB("aggregate tool", (integration) => {
2727
...databaseCollectionParameters,
2828
{
2929
name: "pipeline",
30-
description: `An array of aggregation stages to execute.
31-
\`$vectorSearch\` **MUST** be the first stage of the pipeline, or the first stage of a \`$unionWith\` subpipeline.
32-
### Usage Rules for \`$vectorSearch\`
33-
- **Unset embeddings:**
34-
Unless the user explicitly requests the embeddings, add an \`$unset\` stage **at the end of the pipeline** to remove the embedding field and avoid context limits. **The $unset stage in this situation is mandatory**.
35-
- **Pre-filtering:**
36-
If the user requests additional filtering, include filters in \`$vectorSearch.filter\` only for pre-filter fields in the vector index.
37-
NEVER include fields in $vectorSearch.filter that are not part of the vector index.
38-
- **Post-filtering:**
39-
For all remaining filters, add a $match stage after $vectorSearch.
40-
### Note to LLM
41-
- If unsure which fields are filterable, use the collection-indexes tool to determine valid prefilter fields.
42-
- If no requested filters are valid prefilters, omit the filter key from $vectorSearch.`,
30+
description: "An array of aggregation stages to execute.",
4331
type: "array",
4432
required: true,
4533
},
@@ -406,6 +394,34 @@ describeWithMongoDB(
406394
await integration.mongoClient().db(integration.randomDbName()).collection("databases").drop();
407395
});
408396

397+
validateToolMetadata(integration, "aggregate", "Run an aggregation against a MongoDB collection", [
398+
...databaseCollectionParameters,
399+
{
400+
name: "pipeline",
401+
description: `An array of aggregation stages to execute.
402+
\`$vectorSearch\` **MUST** be the first stage of the pipeline, or the first stage of a \`$unionWith\` subpipeline.
403+
### Usage Rules for \`$vectorSearch\`
404+
- **Unset embeddings:**
405+
Unless the user explicitly requests the embeddings, add an \`$unset\` stage **at the end of the pipeline** to remove the embedding field and avoid context limits. **The $unset stage in this situation is mandatory**.
406+
- **Pre-filtering:**
407+
If the user requests additional filtering, include filters in \`$vectorSearch.filter\` only for pre-filter fields in the vector index.
408+
NEVER include fields in $vectorSearch.filter that are not part of the vector index.
409+
- **Post-filtering:**
410+
For all remaining filters, add a $match stage after $vectorSearch.
411+
### Note to LLM
412+
- If unsure which fields are filterable, use the collection-indexes tool to determine valid prefilter fields.
413+
- If no requested filters are valid prefilters, omit the filter key from $vectorSearch.`,
414+
type: "array",
415+
required: true,
416+
},
417+
{
418+
name: "responseBytesLimit",
419+
description: `The maximum number of bytes to return in the response. This value is capped by the server's configured maxBytesPerQuery and cannot be exceeded. Note to LLM: If the entire aggregation result is required, use the "export" tool instead of increasing this limit.`,
420+
type: "number",
421+
required: false,
422+
},
423+
]);
424+
409425
it("should throw an exception when using an index that does not exist", async () => {
410426
await waitUntilSearchIsReady(integration.mongoClient());
411427

0 commit comments

Comments
 (0)