Skip to content

Retrieval that is quietly wrong · 2 of 4

Ten asked, four returned

Step 1 · The pattern

Ask for the ten nearest documents

The app asks the vector index for the ten nearest documents to a question. The index gathers its nearest 40 candidates and returns the top ten. Results are full and relevant. (Animation numbers are illustrative.)

  • a query
  • ten results
  • fewer than asked

In short

Ten asked, four returned: how it works and how it breaks

Most retrieval is filtered: this customer's documents, this product line, this year. With an approximate vector index such as HNSW, the index first gathers a fixed number of nearest candidates, then the filter removes those that do not match. If the filter matches a small share of the data, most candidates are thrown away. pgvector's documentation gives the arithmetic: with a filter matching 10% of rows and the default search size of 40, about 4 rows come back on average. Ask for ten, get four, and nothing errors. The model answers from too little, smaller tenants get worse answers than bigger ones, and dashboards see only successful queries. Fixes: iterative index scans that keep searching until enough rows pass the filter (pgvector 0.8 and later, up to a scan limit), a larger search size, or partitions and indexes per tenant. Test recall with the filters people actually use.

What this simulation simplifies

  • Every filtered query returns exactly four results here; real counts vary around that.
  • The extra latency of iterative scans is shown as a fixed amount.

How this comes up in interviews

"Design vector search for a multi-tenant SaaS product where every query is filtered to one tenant."

Then they ask

  1. What happens to recall with filters?
  2. How would you fix small tenants getting fewer results?
  3. How do you monitor it?

A strong answer covers

  • Approximate indexes gather candidates then filter; selective filters return too few.
  • Iterative scans, larger search sizes, or per-tenant partitions or indexes.
  • Test recall with real filters, not unfiltered benchmarks.
  • Log result counts vs requested.
  • Tenant filters are also a security boundary: enforce them.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last reviewed: Official documentation

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.