Metadata Filtering

Semantic Search with Precise Control

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.

Why it matters

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.

How It Works

Each stored vector is accompanied by a metadata payload — a dictionary of key-value pairs describing the source document. Common fields:

1

source — The document URL or filename the chunk came from.

2

date / timestamp — When the document was published or last updated.

3

category — Topic area, department, or product line.

4

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.

Pre-filtering vs Post-filtering

Pre-filtering

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.

Post-filtering

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.

Metadata Design Tips

Design for your query patterns

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.

Need Help?

Ask the AI assistant about metadata filtering, how to design metadata schemas, or pre-filtering vs post-filtering strategies.