Choose shared or separate indexes using permission boundaries, shard fanout, tenant size and deletion requirements.
Multi-tenant retrieval: isolate indexes, routes and noisy neighbors
Tenant filtering is a security boundary
A multi-tenant retriever serves several organizations from one application. Every query, suggestion, cache entry and evidence citation must carry the authenticated tenant, regardless of any tenant value typed into the search box. A filter added after candidate generation may already be too late if the vector backend explores or logs unauthorized candidates. Where supported, constrain the index or shard search before ranking and recheck document permissions before returning evidence. Corpus permissions still apply within a tenant; tenancy alone is not document authorization.
Choose an index layout from workload facts
A separate index per tenant gives a clear deletion and capacity boundary, but thousands of tiny indexes can waste metadata, shards and warm memory. A shared index with an indexed tenant key reduces per-tenant overhead; it demands strict filtering and makes one large tenant a possible noisy neighbor. A hybrid layout puts large or regulated tenants in their own indexes and small tenants in a shared pool. Document the migration path for a tenant that grows. Do not choose the layout from row count alone: query volume, vector memory, update rate and retention policy matter.
Use routing to limit work, not to grant access
Routing records for one tenant to a subset of shards can reduce query fanout, but a routing key is not an authorization check. A malicious or mistaken client can provide another key unless the server derives it from the authenticated identity. Very large tenants may overload one shard, so size routing buckets and rebalance with measured limits. Queries across allowed shared collections may need several shard keys and an explicit merge policy. Shard fanout explains the latency and partial-result behavior once a request crosses partitions.
Keep generations and caches tenant-scoped
A lexical index migration, vector model upgrade or deletion replay may finish for one tenant before another. Record generation and watermark per tenant, not as a misleading global number. Cache keys need tenant, permission revision, query, filters and index generation; otherwise a cached answer can cross an access boundary after a cutover. Permission-aware caching provides the full revocation contract. Trace storage deserves the same isolation as the content index because raw queries may contain private identifiers.
Test failures that look like success
Seed two tenants with the same document title but different contents. Search by title, use autocomplete, paginate and revoke a document while holding a cursor. None of the surfaces should disclose the other tenant's title, count or snippet. Then send a burst from the large tenant and measure the smaller tenant's p95 latency to expose noisy-neighbor effects. Test deletion and rollback too; a tenant moved to a new index must not leave an older copy searchable. Index cutovers need this per-tenant deletion proof.
Worked contract
from dataclasses import dataclass
@dataclass(frozen=True)
class TenantPassage:
tenant: str
passage_id: str
words: frozenset[str]
def authorized_candidates(passages: list[TenantPassage],
authenticated_tenant: str,
query_words: set[str]) -> list[str]:
return sorted(passage.passage_id for passage in passages
if passage.tenant == authenticated_tenant
and passage.words & query_words)
index = [
TenantPassage("north", "north-p47", frozenset({"seal", "limit"})),
TenantPassage("south", "south-p47", frozenset({"seal", "contract"})),
]
assert authorized_candidates(index, "north", {"seal"}) == ["north-p47"]
assert authorized_candidates(index, "south", {"seal"}) == ["south-p47"]Performance and operating cost
The list scan takes O(N) time for N passages and O(K) output space for K authorized matches. An indexed tenant partition or routed shard narrows the scanned candidates, but per-tenant indexes add fixed metadata and operational cost. The example shows the invariant that the tenant comes from authentication; it does not provide a secure search index. Enforce the same tenant scope at suggestion, aggregation, cache and citation boundaries, then measure tail latency under competing tenants.
Common Mistakes
- Trusting a tenant ID supplied in a search parameter.
- Using routing as the only permission check.
- Moving a tenant between indexes without replaying deletions and clearing old caches.
- Testing average latency only while one tenant saturates a shared shard.
Validation drill
Populate two tenants with 41 similarly named documents. Exercise search, facets, suggestions, pagination, rollback and deletion; assert zero cross-tenant IDs while one tenant generates five times the query load.
