Hello,
I’ve created a vector index on our collection with the following definition:
{
"mappings": {
"dynamic": true,
"fields": {
"embedding": {
"dimensions": 1536,
"similarity": "cosine",
"type": "knnVector"
}
}
}
}
it is built on a single field called “embedding”.
However before performing the vector search I want to filter the records by shopId parameter, which is an ObjectId.
If I try a vector search without a filter parameter, it works properly. When I add the filter, it always returns an empty set regardless of what properties I filter by (tried text, range, in, etc.).
db.products.aggregate([
{
"$search": {
"knnBeta": {
vector: [-0.01169421,...,-0.026038546],
path: "embedding",
k: 2,
"filter": {
"equals": {
"value": ObjectId("64c3a5b888c08fe892282bbd"),
"path": "shopId"
}
}
}
}}
])
I can’t figure out why it doesn’t work. It is clearly indicated in the documentation that the pre-filter condition can be applied before a vector search https://www.mongodb.com/docs/atlas/atlas-search/knn-beta/.
Do I have to include the shopId ObjectId property into the vector index definition? I can’t see a way to create a compound index from vector and regular properties at the same time.
Any help or assistance would be appreciated.
Thanks in advance.