Metadata filtering restricts a vector search to vectors that match specific attributes — by source, date, author, category, language, or any other field stored alongside the embedding. It gives you the meaning-awareness of vector search plus the precision of a traditional database filter.
A customer support bot without metadata filtering might return documentation for the wrong product — semantically similar, but useless. A filter on product: "Product A" ensures only relevant documents are searched.
Each stored vector is accompanied by a metadata payload — a dictionary of key-value pairs describing the source document. Common fields:
source — The document URL or filename the chunk came from.
date / timestamp — When the document was published or last updated.
category — Topic area, department, or product line.
status — Draft, published, verified, or archived.
At query time, you pass both a query vector and a filter expression. The database returns the top-k semantically similar vectors that also satisfy the filter.
Apply filter first, then run ANN over the matching subset. Efficient when the filter is highly selective (matching few vectors). Can hurt performance when the filter matches most vectors.
Run ANN over full index, then filter results. Faster ANN traversal, but may return fewer than k results if many top candidates are filtered out.
Most modern vector databases use filtered ANN — integrating the filter into the index traversal — which is the most efficient approach.
Only store metadata that you will actually filter on. Metadata that changes frequently is problematic — updating it may require re-indexing. Store stable attributes (category, source, language) rather than volatile runtime state.
Ask the AI assistant about metadata filtering, how to design metadata schemas, or pre-filtering vs post-filtering strategies.