Approximate nearest-neighbor speed is useful only if access filters and candidate limits still surface relevant permitted passages.
Filtered vector search: measure ANN recall inside the permitted set
Name the reference set
Approximate nearest-neighbor search trades some exact-neighbor recall for latency and memory behavior. Evaluate it against an exact search over the same eligible documents, query embedding and distance metric. If the exact baseline includes another tenant's records, its recall number is meaningless for a permission-filtered product. Apply tenant, revision and document-state filters before ranking, or use an index layout whose filtering semantics are proven. Access policy is a hard eligibility rule.
Test selective filters
A broad tenant with millions of passages and a small tenant with 47 passages may exercise different search paths. Some engines prefilter the graph; others use postfiltering or adaptive methods. Postfiltering the global top K can return zero permitted results even when a perfect permitted answer exists just outside K. Ask the engine what it actually does, then test the behavior. A filter that removes forbidden hits after they have already entered prompt assembly is too late.
Separate relevance from system recall
Measure exact top-K overlap to quantify approximation loss, then judge whether answer-bearing passages remain in the candidate pool. A candidate can differ from the exact top K yet still answer the question; conversely, excellent vector overlap can miss a literal error code. Compare by tenant size, filter selectivity, language and document length. Hybrid retrieval can recover some exact-token cases but is not a repair for access leakage.
Set a latency budget with an exit
Tune search breadth and K on a fixed judged set while measuring p50 and p95 latency. Keep a limit on vector comparisons, rerank candidates and total response time. When filtered ANN returns too few candidates, a bounded exact fallback may be reasonable for a small eligible set. Do not retry forever with a larger global K: that raises cost and can still miss the allowed island. Record when fallback runs, so an index regression is not hidden by the safety net.
Worked contract
def recall_at_k(returned_ids: list[str], exact_ids: list[str], k: int) -> float:
if k < 1 or len(exact_ids) < k:
raise ValueError("invalid recall cutoff")
permitted_reference = set(exact_ids[:k])
return len(set(returned_ids[:k]) & permitted_reference) / k
exact_permitted = ["west-r8-p4", "west-r8-p9", "west-r8-p2"]
ann_permitted = ["west-r8-p4", "west-r8-p2", "west-r8-p11"]
assert recall_at_k(ann_permitted, exact_permitted, 3) == 2 / 3
def allowed_candidates(candidates: list[dict], tenant_id: str) -> list[dict]:
return [passage for passage in candidates if passage["tenant_id"] == tenant_id
and passage["state"] == "active"]
assert allowed_candidates([{"tenant_id": "west", "state": "active"},
{"tenant_id": "east", "state": "active"}], "west") == [
{"tenant_id": "west", "state": "active"}]Performance and operating cost
An exact scan costs O(Nd) distance work for N eligible d-dimensional vectors; an ANN index aims to reduce query work but adds build time, memory and tuning. The filter check shown costs O(K) over returned candidates and does not replace index-side authorization. Report recall and latency together at the production filter distribution.
Common Mistakes
- Computing ANN recall against a reference set that includes forbidden documents.
- Postfiltering only the global top K and calling an empty result a true no-answer.
- Treating vector-neighbor overlap as answer-bearing passage recall.
- Using an unbounded retry or exact fallback on a large tenant.
Validation drill
Create a large and a small tenant with overlapping language. Compare exact and ANN top-8 within each tenant, then revoke one document and prove it cannot appear in candidates, reranker inputs or citations.
Read next
- Embedding migrations: keep query and document vectors in one space
- Hybrid retrieval: fuse exact terms and semantic candidates by rank
- Retrieval release gates: evaluate slices before changing an index
- Retrieval index versions, eligibility filters and candidate parity
