ModelRefs / Metadata Filtering — AI Glossary
Metadata Filtering — AI Glossary
Pre- or post-filtering retrieved documents by structured metadata fields (date, source, author, category) to improve precision.
Overview
Metadata filtering combines vector similarity search with structured constraints: 'find semantically similar chunks AND published after 2024 AND source=documentation'. Reduces the effective search space and prevents stale or off-topic chunks from polluting context. Supported by Pinecone, Weaviate, Qdrant, pgvector, and Chroma.
Reference details
| Topic | rag |
|---|---|
| Last reviewed | 2026-06-24 |
Related terms
How it works
- Each vector is stored with structured fields alongside it — source, date, author, language, document type — and those fields are indexed separately from the embedding.
- A query combines a similarity target with a predicate over those fields, and the engine must decide where in the search to apply the predicate. That decision, not the predicate itself, determines whether the result is any good.
- Pre-filtering restricts the candidate set before the similarity search, so every vector considered already satisfies the predicate. It gives correct recall and requires the index to support filtered traversal.
- Post-filtering runs the similarity search over everything, then discards non-matching results. It is trivial to implement and loses recall in proportion to how selective the predicate is.
- Engines in practice do something in between — traversing the graph while rejecting non-matching neighbours — which degrades as the predicate becomes more selective, because the traversal spends its budget on vectors it cannot return.
- So selectivity is the number that decides the design: a predicate matching most of the corpus is nearly free, and one matching a tiny fraction demands either real pre-filtering or a separate partition.
Example: Where post-filtering stops working
You need the top 10 results and the filter matches 5% of the corpus. Post-filtering retrieves the top k by similarity and then discards non-matches, so of a top-100 retrieval roughly 100 x 0.05 = 5 survive — half of what you asked for. To expect 10 survivors you must over-fetch 10 / 0.05 = 200 candidates, which is still affordable. Now make the filter match 0.1%: the required over-fetch becomes 10 / 0.001 = 10,000 candidates, so the engine ranks ten thousand vectors to return ten, and the approximate index was supposed to avoid exactly that. At 0.01% it is 100,000. The cost grows as the reciprocal of selectivity, which is why there is no over-fetch multiplier that works for all queries: a filter matching 'language = English' on a mostly-English corpus needs almost no over-fetch, and one matching a single customer id in a large tenant table cannot be post-filtered at all. The latter belongs in a partition, where the vectors of other tenants are not in the structure being searched.
Commonly confused with
Metadata filtering is not the same as a namespace or collection, and the difference is a guarantee rather than a degree. A filter is a predicate evaluated against candidates, so whether it is applied before, during or after scoring is an engine detail that determines recall — and, for tenancy, whether another tenant's vector can reach the result set at all. A partition is a separate index: the excluded vectors are not present in the search. Use filters for attributes you narrow by and partitions for boundaries that must hold, because a filter's correctness depends on an implementation detail you would have to verify.
When to use it
Reach for it when:
- Attribute narrowing within one logical corpus — date ranges, document types, languages, sources.
- Predicates with low selectivity, matching a substantial fraction of the corpus, where the recall cost is small.
- Freshness constraints, which are among the most valuable filters because stale chunks are confidently wrong rather than merely irrelevant.
- Combined with a partition for tenancy, so isolation is structural and the filter handles everything inside it.
Reach for something else when:
- Highly selective predicates under post-filtering, where the required over-fetch grows as the reciprocal of selectivity.
- Tenant isolation, where correctness should not depend on where the engine applies the predicate.
- On fields not captured at ingestion. Metadata cannot be filtered on retroactively without re-indexing, which is why the ingestion schema is the decision.
- As a substitute for retrieval quality. A filter removes wrong candidates; it does not make the remaining ranking good.
Continue your research
Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to Metadata Filtering — AI Glossary.
Frequently asked questions
What is Metadata Filtering?
Pre- or post-filtering retrieved documents by structured metadata fields (date, source, author, category) to improve precision.
What concepts are related to Metadata Filtering?
Closely related concepts include namespace, dense retrieval, retrieval pipeline.