How does metadata filtering interact with ANN indexes? Explain pre- vs post-filtering.
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Filtering ("only tenant=42", "only docs from 2025") looks trivial but is one of the genuinely hard problems in vector search, because ANN indexes are built over the whole vector distribution, not over arbitrary filtered subsets.
Full worked answer with diagram
Filtering ("only tenant=42", "only docs from 2025") looks trivial but is one of the genuinely hard problems in vector search, because ANN indexes are built over the whole vector distribution, not over arbitrary filtered subsets.
Post-filtering: run ANN for top-k, then drop results failing the filter. Fast, but with a selective filter you get starvation - ask for k=20, filter matches 1% of the corpus, and after filtering you might hold 0-2 results. Compensating by over-fetching (k=2000 to keep 20) destroys the latency advantage and still gives no guarantee.
Pre-filtering: restrict search to qualifying vectors first. With an exact scan this is perfect - scan only the filtered subset, and if the filter matches a few thousand rows, brute force is fast and 100% recall. But pre-filtering inside an HNSW graph is nasty: the graph's connectivity assumed all nodes exist; if only 1% qualify, the qualifying nodes are sparsely connected islands and greedy traversal can't navigate between them - recall collapses or the search degenerates into scanning.
Production engines therefore implement filter-aware strategies: traverse the full graph but only score/return qualifying nodes while still routing through non-qualifying ones (works down to moderate selectivity); switch adaptively to brute force when the filter is highly selective (many engines do this cost-based flip); or partition the index by the filter key - per-tenant indexes/namespaces turn the filter into index selection, which is the standard answer for multi-tenancy. IVF has an easier time (apply filters within probed lists) but shares the fundamental issue.
What interviewers want: recognition that "just add a WHERE clause" changes recall behaviour, knowledge of the selectivity spectrum (loose filter → post-filter fine; tight filter → brute-force the subset; known-in-advance key → partition), and the instinct to ask "what's the filter's selectivity distribution?" before choosing.
Worth sketching. The selectivity fork is the whole answer, and it is far easier drawn than said - especially the starvation arrow.
flowchart TD
Q["Query plus filter"] --> S{"Filter selectivity"}
S -->|"loose, most rows match"| P["Post-filter: ANN top-k,<br/>then drop non-matches"]
S -->|"tight, ~1% match"| B["Brute-force scan<br/>of the filtered subset"]
S -->|"known key such as tenant"| N["Partition: the filter becomes<br/>index selection"]
P -->|"starvation: ask for 20,<br/>keep 0-2"| B
P --> R["Results"]
B --> R
N --> R
What a good answer covers
- Filtering ("only tenant=42", "only docs from 2025") looks trivial but is one of the genuinely hard…
- Post-filtering: run ANN for top-k, then drop results failing the filter
- Fast, but with a selective filter you get starvation - ask for k=20, filter matches 1% of the corpus,…
- Compensating by over-fetching (k=2000 to keep 20) destroys the latency advantage and still gives no guarantee
- Pre-filtering: restrict search to qualifying vectors first
Key terms: whole · Post-filtering · Pre-filtering · filter-aware strategies · partition the index
Interviewer follow-ups to expect
Why does a 1%-selectivity filter break HNSW traversal specifically?
Design indexing for 10k tenants where the largest is 10M vectors and the median is 5k. How does your vector DB decide between filtered-ANN and brute force - what would a cost model look at?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep