Skip to main content
Interactive qdrant-rag Configurator →Open Architecture Blueprint ↗
P0 INCIDENTL7 BARM08 · 6 MIN READ

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.

PRODUCTION SYMPTOM & ALERT SIGNATURE

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 > 0
01 · ROOT-CAUSE MECHANICS (WHY IT HAPPENS)

Running 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).

02 · LIVE TRIAGE COMMANDS (COPY & RUN)
Verify PostgreSQL RLS and iterative scan settings on pgvector chunks
$ psql -c "SELECT relname, relrowsecurity, relforcerowsecurity FROM pg_class WHERE relname = 'rag_chunks';"
Smoking gun: relrowsecurity=true and relforcerowsecurity=true must BOTH be enabled.
Inspect EXPLAIN ANALYZE on a small-tenant vector query for filter starvation
$ psql -c "SET hnsw.iterative_scan = relaxed_order; EXPLAIN (ANALYZE, BUFFERS) SELECT id FROM rag_chunks WHERE tenant_id = 't_small' AND acl_groups && ARRAY['eng'] ORDER BY embedding <=> '[0.1,...]'::vector LIMIT 10;"
Smoking gun: Iterative Index Scan returning full 10 rows for small tenant without scanning unrelated tenants.
Check Qdrant tenant payload index configuration
$ curl -s http://qdrant:6333/collections/enterprise_docs | jq ".result.payload_schema"
Smoking gun: tenant_id indexed with is_tenant: true and acl_groups indexed as keyword.
03 · PRODUCTION DIFF (BROKEN VS HARDENED)
BROKEN · Broken Python Post-Filtering (zero recall for small tenants + fail-open risk)
# DANGER: Global top-20 search BEFORE tenant_id check!
candidates = vector_db.search(query_vec, limit=20)
# If another tenant owns the top 20 vectors, small_tenant gets []!
allowed = [doc for doc in candidates if doc.tenant_id == user.tenant_id]
HARDENED · Pre-Filtered Database-Enforced Tenant + ACL Retrieval (pgvector 0.8 + RLS)
-- Enforce tenant isolation inside PostgreSQL Row-Level Security (fail-closed)
ALTER TABLE rag_chunks ENABLE ROW LEVEL SECURITY;
ALTER TABLE rag_chunks FORCE ROW LEVEL SECURITY;

CREATE POLICY tenant_isolation ON rag_chunks
  USING (tenant_id = current_setting('app.tenant_id', false));

-- Per-transaction query with pgvector 0.8 iterative HNSW scan (prevents recall collapse)
SET LOCAL app.tenant_id = 'tenant_acme';
SET LOCAL hnsw.iterative_scan = 'relaxed_order';

SELECT id, content, 1 - (embedding <=> $1::vector) AS cosine_sim
FROM rag_chunks
WHERE acl_groups && $2::text[]
ORDER BY embedding <=> $1::vector
LIMIT 12;
04 · MINUTE-24 BAR-RAISER CHECKPOINT (L7 · M08)TEST YOUR INSTINCT · ZERO SIGNUP

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?

05 · POST-FIX VERIFICATION CHECKLIST
  • 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.
06 · FREQUENTLY ASKED ENGINEERING QUESTIONS

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.