How does the metadata filtering combines with embedding search?

Let’s say I have an index of people “Bob, Alice, John” with metadata “location, age, sex, job”

User query: “The software engineer guy from Barcelona”

In this scenario I have “NER augmented search” and detect “Barcelona” as location

embeddings = ... # something
index.query(
    vector=embeddings,
    filter={
        "location": {"$eq": "Barcelona"},
    },
    top_k=5,
    include_metadata=True
)

Not sure about Filtering: The Missing WHERE Clause in Vector Search | Pinecone

Does it pre-filter then? If there is no Barcelona in the document, it’s filtered out?
What if I want to fall back to semantic search even if Barcelona is not in the document?

Thanks :slight_smile:

Hi Louis,
Pinecone will pre-filter vectors containing ‘Barcelona’ before performing the query. It then searches only vectors where that metadata key:value pair exists. If you want to ‘fall back’ to another query without the metadata filter, then you must perform second query.