The hard part of a multi-tenant help center is not producing an answer from a PDF. It is proving that the retrieved passages belong to the requesting tenant before latency pressure turns a shortcut into a disclosure. Short answer: enforce tenant scope before retrieval, carry it through every index and cache key, and treat an empty authorized result as a valid answer state. For a logistics SaaS system answering questions over carrier contracts and warehouse procedures, retrieval quality matters only after that privacy invariant holds.

This is a constraint problem. A broad search can improve recall while quietly crossing a tenant boundary; a narrow pre-filter can protect isolation while missing the paragraph that explains a surcharge. The architecture has to make the unsafe choice difficult to express in code.

Start with the data boundary, not the embedding model

Each PDF needs an immutable tenant identifier, document identifier, revision, and policy version at ingestion. Store those fields beside every chunk, not only on a parent table that a later query might forget to join. A chunk copied into a vector index without its authorization attributes is no longer safely searchable.

The ingestion path should extract text, retain page coordinates for citations, and attach a content hash. A revision becomes searchable only after all chunks and their metadata are committed. If OCR quality is uncertain, mark the document for review; silently indexing a bad page changes retrieval quality without giving operations a way to explain the answer.

Keep the policy explicit:

type Scope struct { TenantID string UserID string Roles []string } type Chunk struct { TenantID string DocumentID string Revision int Page int Text string PolicyEpoch int64 } 

The vector itself is not an authorization decision. It is a ranking aid. Authorization remains a deterministic predicate over TenantID, document state, and the caller's role, evaluated before a chunk enters the answer context.

How can retrieval architecture balance privacy, quality, and latency?

Use a two-stage query. First derive an allow-list from the tenant policy service or database, then apply that scope to lexical and vector retrieval. Reranking may reorder authorized candidates, but it must not add new documents. This makes the quality-versus-latency decision measurable: candidate count, filter time, recall on an approved evaluation set, and end-to-end p95 can be recorded separately.

For a small tenant, a shared index with a mandatory metadata predicate is usually simpler than one index per tenant. A very large tenant or a regulation requiring physical separation can justify dedicated indexes, but that choice adds deployment, migration, and monitoring work. The catch is that “one index per tenant” does not solve application bugs in authorization, while a shared index does not excuse missing predicates.

Cache keys must include tenant, user or role policy, query normalization, index revision, and policy epoch. A cache hit from another tenant is a privacy incident even when the underlying text is identical. Cache less aggressively if policy changes are frequent; stale answers are a correctness issue, not merely a freshness annoyance.

I once expected a strict tenant filter to be the expensive part. The surprise was a different boundary: a reranker received the unfiltered top 50 candidates because the filter was applied only in the first search call. The final answer looked plausible, and the audit log showed a tenant-safe query, but the intermediate payload was already too broad. The fix was to type the candidate set as authorized data and make the reranker accept that type only.

What should an auditable answer pipeline record?

Record the request tenant, policy epoch, authorized document IDs, retrieval strategy, candidate scores, selected chunk IDs, model identifier, and answer hash. Keep the prompt and response retention period aligned with contractual and regulatory limits; a ledger-minded system should be able to reconstruct why a passage was eligible without retaining more customer text than necessary.

An empty result needs a distinct status from a system failure. “No authorized source found” can trigger a clarifying question or a human route. A timeout, malformed PDF, or index lag needs an operational signal. Conflating those states encourages retries that bypass policy checks and makes incident review unreliable.

Test isolation as a matrix, not as one happy-path unit test: tenant A asking about tenant B's known phrase, revoked role after indexing, deleted document revision, cache reuse, and concurrent policy updates. Property tests can assert that every emitted context chunk has the request scope. A red-team fixture with identical text in two tenants is useful because content equality must never make authorization equality implicit.

The following generic adapter shows the important shape. The concrete search engine can be lexical, vector, or hybrid; the caller cannot omit the scope.

package retrieval import ( "context" "errors" ) var ErrNoAuthorizedSource = errors.New("no authorized source") type Candidate struct { TenantID string DocumentID string Text string Score float64 } type Searcher interface { Search(ctx context.Context, tenantID, query string, limit int) ([]Candidate, error) } func Retrieve(ctx context.Context, s Searcher, scope Scope, query string) ([]Candidate, error) { if scope.TenantID == "" || query == "" { return nil, ErrNoAuthorizedSource } candidates, err := s.Search(ctx, scope.TenantID, query, 20) if err != nil { return nil, err } for _, candidate := range candidates { if candidate.TenantID != scope.TenantID { return nil, errors.New("searcher violated tenant scope") } } if len(candidates) == 0 { return nil, ErrNoAuthorizedSource } return candidates, nil } 

The defensive check is intentional. It turns an index configuration mistake into a visible failure before generation. In production, add role and document-state predicates inside the search implementation and emit a structured audit event for both the accepted scope and the rejected candidate count. That event should carry a correlation ID shared by ingestion, retrieval, generation, and the eventual user-visible response, because a compliance reviewer usually asks for the chain rather than one isolated query. Retain enough metadata to reproduce the decision while redacting document text according to the retention policy; auditability is not a license to build a second unrestricted document store.

Measure twice.

Rollout decisions and limits

Start with a shadow query that computes the new scoped result beside the existing result, then compare recall on tenant-labeled questions without exposing the shadow passages to users. Promote by tenant, watch p95 latency and false-empty rates, and keep a kill switch that disables generation while preserving the authorized retrieval audit trail.

This design is not suitable when a single answer intentionally combines data from several tenants; use an explicit cross-tenant service account and a separate policy review for that workflow. It is also a poor fit for teams unable to maintain tenant metadata through ingestion and re-indexing. Stick with a simpler document portal when the source set is tiny and every read can be checked synchronously against the primary database.

I am not sure a universal candidate count exists: PDFs with dense tables behave differently from short FAQ pages, and your mileage may vary. Measure with a tenant-stratified set, then choose the smallest candidate budget that meets the recall target without making policy filtering an afterthought.

References