Prevent cached evidence and follow-up questions from crossing tenant, principal or document-revision boundaries.
Retrieval caches and conversation turns: recheck access every time
Key on authorization context
A cache entry keyed by query text alone is unsafe. Include tenant, principal or authorization scope, policy version, corpus generation, query normalization and retrieval configuration. Even then, a revoked document can invalidate an old answer before TTL expires. Revalidate cached passage IDs against current access and deletion state, or invalidate them on revocation. Document lifecycle defines the invalidation event.
Carry resolved conversation state
A follow-up like ‘What about the other case?’ needs a specific, permitted antecedent. Store document and revision IDs, not an indiscriminate replay of previous passages. Recheck access before reuse. If two antecedents fit, ask for clarification. A conversation ID is not an authorization token; shared browser sessions and role changes expose that mistake.
Separate candidate and answer caches
Cached candidates depend on index generation, access scope and search configuration. A cached final answer also depends on the prompt, model, evidence packet and answer policy. Give these caches separate lifetimes. Never serve a final answer whose citations no longer resolve, and avoid storing user secrets in a shared cache.
Prove revocation works
Test identical query text from two tenants, role change mid-session, document deletion and index swap. Each must produce only a newly permitted answer or an explicit no-answer. Log cache hit, authorization recheck and corpus generation without private text in metric labels. Index swaps need matching invalidation.
Worked contract
from hashlib import sha256
def retrieval_cache_key(tenant_id: str, principal_id: str, policy_revision: str,
corpus_generation: str, query: str) -> str:
fields = (tenant_id, principal_id, policy_revision, corpus_generation,
" ".join(query.casefold().split()))
if any(not field for field in fields):
raise ValueError("incomplete cache scope")
return sha256("\x1f".join(fields).encode("utf-8")).hexdigest()
base = retrieval_cache_key("west", "analyst-47", "acl-r8", "index-r8", " AX-47 status ")
assert base != retrieval_cache_key("east", "analyst-47", "acl-r8", "index-r8", "AX-47 status")
assert base != retrieval_cache_key("west", "analyst-47", "acl-r9", "index-r8", "AX-47 status")Performance and operating cost
Key construction is O(q) for query length q. Rechecking K cached passage IDs is O(K) plus authorization lookup cost. That recheck adds latency but prevents stale permissions from leaking. If it becomes expensive, use a policy-version or revocation index with a measured freshness bound.
Common Mistakes
- Caching by query text without tenant or principal scope.
- Assuming TTL handles emergency revocation.
- Using previous-turn passages after the user's role changes.
- Serving a cached answer after its citations disappear.
Validation drill
Run the same 19 questions as two principals with different access. Revoke a document after a warm cache and prove no old passage, claim or citation appears next.
Read next
- Retrieval query routing: preserve exact constraints before search
- Retrieval corpus contracts: identity, permissions and document lifecycle
- Index freshness: publish complete revisions and remove stale chunks
- Retrieved text as untrusted data: keep instructions and tools separate
