The interview problem

Practice prompt

A vector search must return ten relevant documents that match tenant, language and access filters. Design retrieval when only a tiny fraction of the index is eligible.

Original practice, not a reported company interview. All worked numbers are illustrative. Interview date: not applicable. Written October 3, 2026.

1. Scope and assumptions

Distinguish approximate nearest neighbors within the eligible set from retrieving globally and discarding disallowed results. Recall is measured against an exact filtered baseline. Authorization must hold regardless of retrieval strategy.

2. Architecture and decisions

Identity and filter → eligibility estimate → filtered ANN or exact scan → permission check → top-k

Estimate eligible-set size using index statistics, with conservative fallback when estimates are stale. Use an engine-supported filtered approximate search for broad eligible sets and consider an exact distance scan when the set is small. Partition by a stable high-value boundary such as tenant only when it does not create excessive tiny indexes.

Keep a final permission check as defense in depth, but do not depend on post-filtering alone to fill the result list. If bounded retrieval cannot find ten eligible documents, return fewer with the correct completeness contract. Track recall, latency and returned-count distribution by filter selectivity; global averages conceal the worst cases.

3. Work through the example

If eligible documents independently make up 1% of global candidates, fetching 100 candidates yields only one eligible result in expectation. Fetching 1,000 yields ten in expectation, not a guarantee of ten and not a recall guarantee. An exact scan over 400 eligible vectors may be cheaper than expanding a global ANN search repeatedly.

4. Failure cases and trade-offs

Eligibility and distance are often correlated, invalidating the independence estimate. Post-filtering can return no hits even when relevant eligible documents exist. Per-tenant indexes improve isolation but complicate balancing and updates. An exact fallback is predictable only if the eligible set and vector dimensions fit the latency budget.

5. Validation and acceptance

Build exact filtered top-k labels for sampled queries at several selectivities. Include an adversarial case where all globally closest documents are forbidden. Test permission revocation during index lag and require final filtering to prevent disclosure.

6. Follow-ups and self-review

How would you tune candidate expansion without a latency spiral? Reward filtered ground truth, selectivity-aware routing and permission correctness independent of recall.

Sources and related practice

Elasticsearch documents filtered kNN behavior; the routing thresholds and example are original design choices.

Read the primary technical reference

Reference retrieved October 3, 2026. Retrieval date is not an interview or source publication date. The reference supports the named concept; scenario, architecture, examples and rubric are original.

Continue with Combine rankings from incompatible retrievers; Migrate an embedding model without mixing vector spaces.

Continue your preparation

Choose a connected learning path or browse more ML system design questions. Read our editorial method and attribution policy.