TL;DR: In a multi-tenant healthtech help center, a chatbot that answers from the wrong document usually has a retrieval-scope defect before it has a generation defect. Put tenant, product, locale, publication state, and revision metadata on every chunk, then apply those constraints before vector ranking. Prefer prefiltering over postfiltering at 10 million chunks: postfiltering pays to rank inadmissible rows and may return too few eligible results. Record the effective filter with every answer.
The bill is made of embedded chunks stored, candidates examined, index copies retained, and revisions re-embedded. Model storage as retained chunks x vector bytes per chunk x index and replica overhead; measure the last term in the selected implementation rather than borrowing a generic estimate. Consider a capacity model with 500 tenants, 4,000 published product articles per tenant, and 5 chunks per article. That produces 10,000,000 active chunks. Keeping three complete revisions raises the logical count to 30,000,000, although ordinary chat retrieval needs the revision effective for the requesting tenant.
Keep immutable source documents and change events in the system of record, while the serving index holds current searchable revisions plus a bounded replay window. The index is a projection. If a disputed answer falls outside that window, investigation must rebuild the historical projection; slower recovery is the honest cost of not retaining every vector.
Why does a RAG chatbot answer from the wrong document?
Similarity asks which indexed vectors resemble a query. It does not prove that the caller owns a document, that the article applies to the requested product, or that the revision is published. Retrieval-augmented generation conditions output on retrieved material, so an irrelevant item admitted upstream can become persuasive context [1].
Here, tenant_id is an authorization boundary. product_id, locale, status, and revision are applicability boundaries. The quiet failure is dangerous: embedding succeeds, neighbors look plausible, and the answer cites a real but obsolete article or one owned by another tenant.
Start with the trace, not the prompt. For one failing question, capture the authenticated tenant, requested product and locale, normalized retrieval filter, returned candidate IDs, and each source revision. Compare them at ingestion, index write, retrieval, and citation rendering. A field absent at ingestion cannot be repaired by prompt wording; a correct field dropped during query construction is a separate, auditable failure.
One invariant dominates: every returned chunk must satisfy the effective scope.
Put scope inside the retrieval contract
An untyped metadata map permits misspelled keys and accidental widening. A typed contract makes the boundary reviewable and testable. This Go interface requires scope before search; a storage adapter translates it into its native predicate without changing its meaning.
package retrieval import ( "context" "errors" ) type Scope struct { TenantID string ProductID string Locale string PublishedOnly bool } type Hit struct { ChunkID, DocumentID string Revision int64 Score float64 Scope Scope } type Index interface { Search(context.Context, []float32, Scope, int) ([]Hit, error) } func SearchScoped(ctx context.Context, idx Index, query []float32, s Scope, limit int) ([]Hit, error) { if s.TenantID == "" || s.ProductID == "" || s.Locale == "" { return nil, errors.New("tenant, product, and locale are required") } if !s.PublishedOnly { return nil, errors.New("chat retrieval requires published content") } if limit < 1 || limit > 50 { return nil, errors.New("limit must be between 1 and 50") } return idx.Search(ctx, query, s, limit) } Fetching the global top 20 and discarding other tenants afterward is postfiltering. It may leave one eligible hit even if good tenant-local hits sit just below the global cutoff. Ranking the top 20 from the eligible tenant, product, locale, and publication population is prefiltering. Its latency and recall still need measurement with the chosen index, but its ranking population matches the content contract.
Validate hits again at the return boundary and fail closed on mismatch. This is defense in depth, not a replacement for prefiltering. The audit event should contain a correlation ID, non-reversible query fingerprint, effective scope, index generation, document and chunk IDs, revisions, ranks, and scores. Do not log embeddings, full questions, or article bodies merely because diagnosis is hard. Retention and access must follow the organization's applicable compliance policy; that policy supplies the limit, not a duration copied from another system.
Make the failure reproducible
Treat retrieval testing like reconciliation: given request scope and index generation, account for every returned identifier. Unit tests catch an omitted field. Integration tests seed near-duplicate wording across two tenants and prove that the other tenant never appears. Offline evaluation then measures eligible-document retrieval, while adversarial cases cover missing locale, unpublished revisions, deleted products, and tenant IDs differing by one character.
Use a small fixture first. Create two nearly identical product articles for tenants A and B, publish a newer revision only for A, and issue the same question under both identities. Assert the exact document and revision set before examining generated prose. Fluent output can hide a broken candidate set.
During index rebuilds, send a fixed evaluation set to current and candidate projections. Scope violations form a zero-tolerance class; eligible-document recall remains separate from answer quality, so an average cannot conceal cross-tenant leakage. Give each source revision a stable ingestion key, make writes idempotent on that key, and advance the searchable generation only when its manifest is complete. Retries then preserve an exactly-once outcome without assuming execution happens once.
The diagnostic order is compact:
- Confirm request identity and product context before embedding.
- Inspect the effective prefilter, including locale and publication state.
- Prove every returned chunk matches that scope.
- Resolve citations through the same document and revision IDs.
- Only then inspect chunking, embeddings, ranking, or prompting.
Re-embedding 10 million chunks cannot repair a dropped tenant_id.
Retention changes cost and evidence
Active-only indexing often moves the dominant cost term more than tuning the candidate limit, because retained revisions multiply storage and rebuild work. Deletion has a price. A later audit may need the exact chunks visible when an answer was produced, and a current-only index cannot provide them after revision.
Use separate clocks. The serving projection follows publication state; the immutable content ledger follows the organization's record policy; the retrieval audit follows its own access and retention policy. Join them with stable document IDs, increasing revisions, an index-generation ID, and a content digest. This keeps reconstruction possible without pretending that the low-latency vector index is the authoritative ledger.
The deliberate trade is to stop keeping every historical embedding in the serving index while retaining source events and manifests needed to rebuild an authorized historical view. Storage and recurring rebuild work fall with active vector count. Investigations outside the replay window become slower, so restoration needs a tested procedure.
Choose prefiltering when scope defines correctness
Tenant and publication constraints are not ranking preferences. They define the admissible set. Prefilter them, represent scope as a typed contract, reject mismatched hits, and attach an audit trail before tuning semantic relevance. Postfiltering is acceptable for optional presentation preferences where a short result set is harmless; it is the wrong boundary for ownership, release state, or product applicability.
Prefiltering has limitations. A highly selective predicate can leave a tiny candidate population, and an index whose filtering strategy is poorly matched to that population may require more capacity or a different partition layout. It is also not appropriate for soft preferences, such as favoring one content format, when broader retrieval followed by reranking preserves useful alternatives. The trade-off is deliberate: use prefiltering for hard admissibility, then reserve postfiltering or reranking for preferences that may safely relax.
RAG supplies retrieved context to generation [1], but the first question after a wrong-document answer is concrete: which admissible set did retrieval rank? If that set is wrong, the model is downstream of the defect. Fix scope, reconcile the trace, and prevent the next index generation from accepting the same error silently.

