Filtered Vector Search
You can combine vector search with scalar filters to restrict results to a subset of documents — just like adding a WHERE clause to a similarity search.
Prerequisites
This guide assumes you:
- Have already opened a
collectioninstance. - Are familiar with vector querying and conditional filtering.
Performing Filtered Vector Search
To combine vector similarity search with filters, pass both a VectorQuery and a filter expression to the query() method.
import zvec
result = collection.query(
zvec.VectorQuery(
field_name="dense_embedding",
vector=[0.1] * 768, # Replace with real embedding
),
filter="publish_year > 1936", # Only consider books published after 1936
topk=10,
)
print(result)This returns the top-10 most similar documents that satisfy publish_year > 1936, sorted by similarity score.