Metadata Filtering Strategies for Selective Similarity Search
Practical strategies for metadata filtering in vector search: partitioning, hybrid indexes, selective fallbacks, and schema design that keeps recall intact.
Published on • November 22, 2026
AI Assistant

Introduction
Pure similarity search answers “what’s closest?” Products need “what’s closest among the ones that matter?” — same tenant, published this year, in stock, visible to this user. Metadata filtering turns a geometric query into a business query, and the strategy you choose decides whether recall survives.
Start With the Schema
Good filtering begins at write time:
- Filterable fields typed properly — enums for categories, numeric ranges for dates/prices, booleans for flags. Strings that should be enums become enums.
- Separate identity from payload —
tenant_id,user_id,visibilitylive as first-class fields, not buried JSON. - Know your cardinality —
status: 5 valuesbehaves nothing likedocument_id: 10M values. Cardinality drives which strategy works. - Selectivity profile — for each filter, what fraction of the corpus does it typically keep? 80% filters and 0.01% filters need different machinery.
The Strategy Menu
1. Post-filter with overfetch
Run ANN, fetch k × n candidates, drop non-matching, keep k.
- Best for: loose filters (keep ≥ 50% of data)
- Risk: underfilled results when selectivity is high; raise overfetch adaptively (loop: double n until k results or a cap)
2. Pre-filter / filtered traversal
Restrict the index to the eligible set during search.
- Best for: selective filters on engines with native filtered-ANN
- Risk: engine quality varies hugely — measure recall under filter, not just speed
3. Partitioned indexes (the “route by filter” play)
One index (or segment) per filter value: per-tenant, per-language, per-category.
- Best for: low-cardinality fields used alone (tenant, region, language)
- Gains: filter becomes index selection — no approximation at all; also gives natural isolation
- Risk: cardinality explosion — 10k tenants = 10k tiny indexes; cross-partition queries need fan-out
4. Filtered scan fallback
When the filter keeps a tiny slice (say < 1%), scan only those vectors exactly.
- Best for: highly selective filters — brute force over 0.01% of data is faster and exact
- Pattern: many engines auto-select this plan; verify yours does
5. Two-phase retrieve-and-verify
ANN for candidates → precise filter check → expand search if underfilled. Essentially an adaptive loop combining the above.
Combining Filters
- AND of one selective + loose filters — drive execution from the selective one.
- OR filters — often fan out per branch and merge; partitioning helps.
- Range filters (dates, prices) resist partitioning — favour engines with good range-aware filtered traversal, or partition by coarse bucket + range post-filter.
- Always fuse ranking after filtering — filter first on membership, then rank by similarity (or by a blended score).
How to Validate
- Build test queries at realistic selectivities: 90%, 10%, 1%, 0.1%.
- Measure recall@k under filter against exact filtered ground truth — unfiltered recall lies.
- Track p95 latency per selectivity bucket; the worst bucket is your SLO.
- Re-run after every index or engine upgrade.
Conclusion
Metadata filtering is a design problem, not a where-clause: type your fields, know their cardinality and selectivity, then match strategy to shape — partition low-cardinality fields, filtered-traverse medium ones, and fall back to filtered scans for the razor-selective cases. Do that, and semantic search keeps both its relevance and its business rules.