Filter collection before applying Atlas vector search

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.).

  "$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

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.

With the dynamic=true specified, the shopId field, of type ObjectId, should be indexed. Try using equals as the only, top-level operator, without knnBeta and see if it matches as you’d expect.

Thank you Erik!
I’ve double checked the index and noticed that it didn’t have the dynamic=true in the configuration.