AI Engineering & LLMs (50 Qs)•Part 1: RAG Architecture, Chunking & Vector Search
Multi-Tenant Vector DB Architecture: Tenant Isolation, Pre-Filtering & Partition Keys
1. Enterprise Multi-Tenancy Patterns
In multi-tenant SaaS applications, ensuring that Customer A cannot retrieve Customer B's confidential vector chunks is a critical security and compliance requirement. There are three primary multi-tenant architectural patterns in vector stores:
less
Pattern 1: Database-per-Tenant Pattern 2: Namespace-per-Tenant Pattern 3: Metadata Pre-Filtering
┌────────────────────────────────┐ ┌────────────────────────────────┐ ┌────────────────────────────────┐
│ Tenant A DB │ Tenant B DB │ │ Tenant A Index │ Tenant B Index│ │ Shared Global Vector Index │
│ [HNSW Graph] │ [HNSW Graph] │ │ [Namespace A] │ [Namespace B] │ │ Chunks tagged: {"tenant": "A"} │
└────────────────────────────────┘ └────────────────────────────────┘ └────────────────────────────────┘
Maximum Security • High Cost Balanced Security • Medium Scale Low Cost • Strict Filter Logic Req.
2. Multi-Tenant Architectural Comparison
| Architecture | Isolation Level | Resource Overhead | Scaling Limit | Best Used In |
|---|---|---|---|---|
| Database per Tenant | Physical (Dedicated DB process/instance) | Highest (idle memory overhead per tenant) | Hard limit on hundreds of tenants | Highly regulated banking, healthcare (HIPAA) |
| Collection / Namespace per Tenant | Logical (Separate HNSW graph in shared cluster) | Moderate | Supported up to 10,000 namespaces | B2B enterprise SaaS with distinct tenant boundaries |
| Metadata Partitioning (Pre-Filtering) | Shared graph with indexed metadata filter | Lowest | Unlimited tenants (millions) | High-volume B2C or multi-user consumer apps |
3. Pre-Filtering vs. Post-Filtering Pitfall
[!CAUTION] Never use Post-Filtering for multi-tenancy!
- Post-Filtering: Runs top-$K$ vector search across the entire database, then discards items where
tenant_id != current_tenant. If Tenant A's documents only constitute 1% of the database, the top 100 vector hits may contain 0 items for Tenant A, returning an empty result!- Pre-Filtering (Iterative Single-Stage): The vector index traverses the HNSW graph while restricting candidate nodes to those matching the tenant bitmap, guaranteeing $K$ results for the target tenant.
python
# Correct Production Pre-Filter Query (Qdrant / Pinecone style)
search_results = vector_client.search(
collection_name="enterprise_documents",
query_vector=query_embedding,
query_filter={
"must": [
{"key": "tenant_id", "match": {"value": current_user.tenant_id}},
{"key": "department", "match": {"value": current_user.department}},
{"key": "is_confidential", "match": {"value": False}}
]
},
limit=5
)