Filtered Search Optimization
Optimize pgvector queries that combine vector similarity with metadata filters using partial and composite indexing strategies.
The Filtered Search Problem
Real queries often combine a vector search with a metadata WHERE filter. Naive combinations can defeat the vector index and become slow.
SELECT id FROM docs
WHERE category = 'news'
ORDER BY embedding <=> '[...]'::vector
LIMIT 10;Why Filters Hurt Recall
ANN indexes return approximate nearest neighbors before the filter applies. If most candidates are filtered out, you may get fewer than LIMIT results — this is over-filtering.
All lessons in this course
- IVFFlat Indexing for Speed
- HNSW Indexing for Recall
- Query Performance Tuning
- Filtered Search Optimization