passdrill
AI & LLM Engineering · RAG & Embeddings · Card 012/012 hard

A vector index supports post-filtering: for a query with a metadata filter such as department = 'legal', it first runs an approximate nearest-neighbor search to find the top-k candidates by similarity alone, and only afterward discards any of those candidates whose metadata does not match the filter. For a query whose filter matches only a tiny fraction of the total documents, this approach can return far fewer than k results even though plenty of matching documents exist elsewhere in the index. What causes this shortfall, and what is the general alternative that avoids it?

  1. The approximate nearest-neighbor search itself is broken, so the fix is to replace it with an exact, brute-force search that still applies the filter only after retrieving its top-k results
  2. The vector embeddings are miscalibrated for filtered fields, so the fix is to embed each document's metadata directly into the same vector used for its semantic content
  3. This is expected behavior with no available fix, so applications should only ever use filters broad enough to match at least half of the index
  4. Because the similarity search collects only a fixed-size pool of top-k candidates before any filtering happens, a filter that matches only a sparse subset of the index causes most of that fixed pool to be discarded, leaving too few results; pre-filtering avoids this by restricting the candidate set to metadata-matching vectors before or during the similarity search itself, so the search only ever ranks documents that could pass the filter in the first place
Next card → Shuffle