I’m building an aggregation pipeline in mongodb and I’m encountering some unexpected behaviour.
The pipeline is as follow:
[{
"$search":{
"index":"vector_index",
"knnBeta":{
"vector":[
-0.30345699191093445,
0.6833441853523254,
1.2565147876739502,
-0.6364057064056396
],
"path":"embedding",
"k":10,
"filter":{
"compound":{
"filter":[
{
"text":{
"path":"my.field.name",
"query":[
"value1",
"value2",
"value3",
"value4"
]
},
{
"text":{
"path":"my.field.name2",
"query":"something_else",
}
}
]
}
}
}
}
},
{
"$project":{
"score":{
"$meta":"searchScore"
},
"embedding":0
}
}
]
The pipeline (should) do a vector search according (vector_index, embedding, vector) (it work correctly it seems. With a filter, in particular the filter should limit the vector search to documents having my.field.name
equal to value1
or value2
or ...
and my.field.name2
equal to something_else
.
Instead, only the second filter works, or at least it seems (the value of the second filter is a single letter).
I tried using the must
clause as well in place of the filter inside the compound
clause but the outcome remains the same.
I tried also removing the second filtering (the one without the list) and I still get unfiltered results.
Am I doing something wrong? how can it correctly?