Skip to content

Commit 92d5840

Browse files
chore: another test case
1 parent 998e6aa commit 92d5840

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,69 @@ describeWithMongoDB(
799799
"Error running aggregate: Vector search stage contains filter on fields that are not indexed by index default - name"
800800
);
801801
});
802+
803+
it("should succeed the validation if the pre-filter are also indexed as part of vector search index", async () => {
804+
await waitUntilSearchIsReady(integration.mongoClient());
805+
806+
const collection = integration.mongoClient().db(integration.randomDbName()).collection("databases");
807+
await collection.insertOne({ name: "mongodb", description_embedding: DOCUMENT_EMBEDDINGS.float });
808+
809+
await createVectorSearchIndexAndWait(
810+
integration.mongoClient(),
811+
integration.randomDbName(),
812+
"databases",
813+
[
814+
{
815+
type: "vector",
816+
path: "description_embedding",
817+
numDimensions: 256,
818+
similarity: "euclidean",
819+
quantization: "none",
820+
},
821+
{
822+
type: "filter",
823+
path: "name",
824+
},
825+
]
826+
);
827+
828+
// now query the index
829+
await integration.connectMcpClient();
830+
const response = await integration.mcpClient().callTool({
831+
name: "aggregate",
832+
arguments: {
833+
database: integration.randomDbName(),
834+
collection: "databases",
835+
pipeline: [
836+
{
837+
$vectorSearch: {
838+
index: "default",
839+
path: "description_embedding",
840+
queryVector: DOCUMENT_EMBEDDINGS.float,
841+
numCandidates: 10,
842+
limit: 10,
843+
embeddingParameters: {
844+
model: "voyage-3-large",
845+
outputDimension: 256,
846+
outputDType: "float",
847+
},
848+
filter: { name: 10 },
849+
},
850+
},
851+
{
852+
$project: {
853+
description_embedding: 0,
854+
},
855+
},
856+
],
857+
},
858+
});
859+
860+
expect(!!response.isError).toBe(false);
861+
expect(JSON.stringify(response.content)).toContain(
862+
"The aggregation resulted in 0 documents. Returning 0 documents."
863+
);
864+
});
802865
});
803866
},
804867
{

0 commit comments

Comments
 (0)