添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Trying out the new vector search feature in Mongodb vCore. Not able to find a lot of documentation in usage but basically trying to search on vector content but filter on or have exact match on a specific id in addition to the vector search. The below code returns empty array as result.

			{$search: {
                "cosmosSearch": {
                    "vector": queryVector,
                    "path": "vectorContent",
                    "k": 2
                "returnStoredSource": true
            {$match: { customer_id: "597846e76b573e0011897dcdd1" }}
											

Hi,@Reza S Welcome to Microsoft Q&A forum and thanks for reaching out here

If I understand correctly you are trying to use the new vector search feature in MongoDB vCore and having trouble filtering on or having an exact match on a specific ID

can you try as to filter on a specific ID in addition to the vector search using the Cosmos DB API for MongoDB.

{$search: {
    "cosmosSearch": {
        "vector": queryVector,
        "path": "vectorContent",
        "k": 2
    "filter": {
        "customer_id": "597846e76b573e0011897dcdd1"
    "return": {
        "score": true,
        "payload": true

Regards

Geetha

Hi Reza,

This might be related to the Aggregation Pipeline stage is only available in MongoDB Atlas as an Atlas Search 37 index is required.

Please refer the comment from alexbevi in the below link,

https://www.mongodb.com/community/forums/t/unrecognized-pipeline-stage-name-search/111883/3

Can you please try as per the suggestion in the above link?

@Reza S Did you get a chance to check the above community response? is your issue resolved

Regards

Geetha

result = list(collection.aggregate(pipeline))

I'm also looking for the same solution , first to filter and then loop on the filtered results..

The above query resulting in below exception

OperationFailure: Unrecognized $search option: filter, full error: {'ok': 0.0, 'errmsg': 'Unrecognized $search option: filter', 'code': 40324, 'codeName': 'UnrecognizedCommand'}

Looking at: https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/compatibility we see that $filter is not supported, but $match is.

Here is a tested and validated answer that actually works.

    pipeline = [
            "$search": {
                "cosmosSearch": {
                    "vector": myVector,
                    "path": "myVectorField",
                    "k": limit
                "returnStoredSource": True
            "$match": { 
                "myOtherField": { 
                    "$eq": "myValue"