Pre-filter or post-filter on metadata: which one can leave you with fewer than k results?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Post-filtering ranks the top-k first then drops non-matching rows, so a selective filter can leave fewer than k results; pre-filtering ranks within the eligible set and returns a full k.
Imagine looking for the 10 closest restaurants to you, but you only want ones open right now. Pre-filtering is like telling the map 'show only open places, then pick the 10 nearest.' You always get 10. Post-filtering is like asking for the 10 nearest of anything, then crossing out the closed ones. If 8 of your 10 happen to be closed, you are left with just 2. Same idea with metadata in a search system: filter before you count, and you keep a full basket; filter after you count, and a strict rule can empty most of it.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
State the order of operations for each strategy and why post-filtering under-returns when the predicate is selective. Give the per-tenant example. Then lift to the production nuance: pre-filtering is correct on count but interacts with ANN indexes, and filtered ANN is the modern resolution. Close by framing it as a three-way trade rather than a binary.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Assuming you always get k results back. Post-filtering can return fewer than k — even zero — whenever the metadata predicate is selective relative to the top-k similarity slice.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.