Multi-Tenant RAG Zero-Recall Collapse & Cross-Tenant ACL Leakage
Prevent cross-tenant data leakage and small-tenant recall collapse by enforcing pre-filtered tenant_id and acl_groups inside pgvector and Qdrant ANN indexes.
Enterprise customers with smaller document corpora report empty RAG answers (0 citations), while a red-team audit flags a prompt-injection bypass that surfaced another tenant’s contract snippet.
rag_retrieval_empty_context_ratio{tenant_tier="smb"} > 0.20 OR rag_acl_guardrail_violations_total > 0Running global top-K (e.g., K=20) vector search first and filtering by tenant_id in Python afterward causes catastrophic recall collapse: if large tenants dominate the top 20 nearest neighbors, all 20 rows are discarded and the small tenant gets 0 results.
Worse, relying on LLM prompt instructions ("only answer using Acme docs") instead of database-enforced pre-filtering fails open under indirect prompt injection inside retrieved chunks.
Secure multi-tenant RAG enforces tenant_id and acl_groups inside the vector database query planner (Qdrant payload_m + is_tenant, or pgvector partitioned/iterative HNSW + PostgreSQL Row-Level Security).
Small tenants get 0 RAG results after switching to Python post-filtering after top-20 vector retrieval. Raising top-K to 200 helps slightly but latency spikes. What is the Principal fix?
- Run automated cross-tenant red-team evals verifying 0 cross-tenant chunks ever enter the LLM context window.
- Benchmark recall@10 on a tenant representing < 0.1% of total corpus size and confirm >= 95% recall.
- Ensure application DB role is NOT a superuser or BYPASSRLS role so RLS cannot be silently skipped.
What does pgvector 0.8 hnsw.iterative_scan solve?
Standard HNSW stops after traversing ef_search nodes; if selective WHERE filters discard most visited nodes, fewer than K results are returned. Iterative scan keeps traversing the graph until K matching rows are found.
Why use current_setting('app.tenant_id', false) instead of true in RLS?
Passing false (missing_ok=false) fails closed with a PostgreSQL error if any code path forgets to set app.tenant_id, instead of silently evaluating to NULL.
How should hybrid BM25 + vector search handle tenant ACLs?
Both the lexical BM25 leg and the dense vector leg MUST enforce the exact same tenant_id + acl_groups pre-filter BEFORE Reciprocal Rank Fusion (RRF) merges candidates.