Vector DBs & RAG (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What are the differences between Pre-Filtering, Post-Filtering, and Single-Stage Filtered Search?
senior LevelSystem Design
In Simple Words: When searching vectors with scalar metadata filters:
- Post-Filtering: Runs vector ANN search first to find top 100 matches, then discards items that don't match metadata. Problem: If the filter is selective (e.g. only 0.1% of items match), post-filtering may return 0 results!
- Pre-Filtering: Filters items by metadata first, then brute-force searches the remaining vectors. Problem: Cannot leverage the pre-computed HNSW graph index.
- Single-Stage Filtered Search (Modern Standard): Traverses the HNSW graph while dynamically ignoring nodes that fail the metadata predicate during graph exploration.