advanced26 min studyLesson 678 in Engineering

Retrieval caches: validate the model, corpus, and access dependencies

Distinguish embedding, retrieval, context, and answer caches, with version-aware keys and explicit freshness and revocation behavior.

On this page

What you’ll understand

  • Identify dependencies at each retrieval-generation cache layer.
  • Distinguish cache-key equality from current authorization and evidence validity.
  • Plan corpus and ACL invalidation without assuming TTLs establish correctness.

A cache can reuse a costly embedding, a ranked identity list, a packed context, or a completed answer. Those objects depend on different versions and permissions. Reusing one under an incomplete key can produce a fast but stale or unauthorized result. Name the cached artifact, its dependencies, and its serving contract before optimizing the hit rate.

Different cache layers need different identities

A document embedding depends on source content, preprocessing, and the embedding model artifact. A retrieval result additionally depends on query representation, index generation, retrieval configuration, filters, and principal scope. A packed context depends on selected source versions, order, rendering, tokenizer, and packing policy. A generated answer depends on those inputs plus the generation model, prompt, decoding configuration, and any tools or conversational state affecting the result. Store these dependencies explicitly rather than reusing one query-only key at every stage.

Canonicalize key fields carefully and retain enough structured metadata to detect incompatible reuse. A content hash can identify immutable text but does not imply matching permissions, model behavior, or source authority. A model alias that changes behind an unchanged name can invalidate reproducibility assumptions. Some dependencies can be represented by a conservative pipeline version or corpus generation, at the cost of more misses. Finer invalidation can improve reuse only when its dependency tracking is complete and its compatibility rules are tested.

Kanswer=H(qcanon,vscope,vcorpus,vretrieve,vpack,vprompt,vmodel,vdecode)K_{\rm answer}=H(q_{\rm canon},v_{\rm scope},v_{\rm corpus},v_{\rm retrieve},v_{\rm pack},v_{\rm prompt},v_{\rm model},v_{\rm decode})
This illustrative key includes explicit versions for the artifact's relevant dependencies; H is a deterministic identity encoding or checked digest, not an authorization mechanism. Additional conversational/tool inputs must be included when they affect output. Query canonicalization must preserve meaning and scope.↔ Scroll wide equations horizontally.

Version misses and authoritative rechecks address different problems

A matching key is a candidate for reuse, not proof that current permission remains valid. Validate the artifact's source dependencies and required access policy before delivery to each consumer. A changed ACL can revoke access without changing document text, while a changed corpus can alter the top results even for a query whose previous result did not mention the updated document. Invalidation based only on old result membership can therefore miss newly relevant additions or ranking changes. Negative-result caches need updates too.

A TTL bounds age only under its actual enforcement rules; it does not establish correctness until expiration or immediate revocation. Event-based invalidation can be delayed or lost, so use an authoritative version or validation mechanism that meets the serving contract. Distinguish immutable historical snapshots, which may remain valid for an authorized historical request, from answers claiming to reflect the current corpus. HTTP cache directives in RFC 9111 have specific semantics; an application-level RAG cache still needs its own source and permission dependency design.

Reuse⁡(x)⟹CompatibleVersions⁡(x,Vrequired)∧⋀d∈Deps⁡(x)Allow⁡(u,d,vArequired)\operatorname{Reuse}(x)\Longrightarrow \operatorname{CompatibleVersions}(x,\mathcal V_{\rm required})\land\bigwedge_{d\in\operatorname{Deps}(x)}\operatorname{Allow}(u,d,v_A^{\rm required})
This desired reuse condition combines declared version compatibility with current required source authorization. Complete dependencies, a defined decision point, and an implemented consistency policy are necessary; writing this predicate does not make asynchronous invalidation atomic.↔ Scroll wide equations horizontally.

Measure valid reuse and test stale paths

Test a content edit, new relevant document, source deletion, permission-only change, embedding-model replacement, prompt update, and generator change. Include caches populated by another principal and in-flight invalidation races. Verify that citation resolution and derived summaries follow the same snapshot and policy rules as answer serving. Report valid-hit rate separately from raw key matches, alongside stale-response and authorization failures. A lower hit rate after correct invalidation can be the intended outcome rather than a performance regression.

The cache lab demonstrates only deterministic LRU replacement. Reset, set C=2 and s=4, predict zero hits among sixteen initial requests, then Play or Step. Separately Reset, set C=4 and s=4, predict twelve initial hits, then Play or Step. Both cycle over four addresses, and only the larger capacity holds them all. The instrument has no corpus generations, ACLs, model versions, TTLs, or invalidation events. Use it for capacity-versus-working-set intuition while testing dependency validity in the actual pipeline.

A matching query is not a matching answer artifact

One cached answer has dependency tuple (corpus=7, access-scope=4, generator=2), with all other fields fixed. Four requests require tuples [(7,4,2),(8,4,2),(7,5,2),(7,4,3)]. Use exact-version matching for this teaching cache.

  1. Only the first request has the same tuple. The second changes corpus generation, the third access scope, and the fourth generator version.

  2. There is one candidate key match among four requests, or 25%; the other three are dependency misses even though the query text is identical.

  3. The matching request still requires the stated authoritative permission and provenance validation before serving. A candidate match is not automatically a valid hit or proof that the cached evidence remains accessible.

The result

The example has a 25% candidate-match rate under exact-version keys. Valid reuse adds the required current checks.

Explore the model

Interactive lab

Interactive lab · cache

Capacity hits do not validate a cache artifact

Reset, set C=2 and s=4, predict zero initial hits in 16 requests, then Play or Step. Separately Reset, set C=4 and s=4, predict 12 initial hits, then Play or Step. The modulo-16 LRU model has no corpus, access scope, versions, TTL, or invalidation channel.

Capacity hits do not validate a cache artifactA fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Current readings: Hits / requests: 0 / 16; Hit rate: 0%; Address-stream period: 16 addresses. All parameters are adjustable with the labeled controls below.Fully associative LRU cache after 16 deterministic requests: 0 hits and 16 misses.Most recent 16 requestsaddress = i × 3 mod 160M3M6M9M12M15M2M5M8M11M14M1M4M7M10M13MCurrent cache order · oldest → newest471013Latest address 13 · miss: inserted as newestToy address stream · period 16 · starts empty
Cached addressMiss / evictionMost recent request
Hits / requests
0 / 16
Hit rate
0%
Address-stream period
16 addresses
t = 0 s

A fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forOptimize only reuse that satisfies the artifact's version and permission contract.

Check your understanding

Why can a corpus addition invalidate a cached ranked list even if none of its old results changed?

Try it yourself

An answer cache has a 300-second TTL. A source permission is revoked thirty seconds after insertion. If the application relies only on TTL and serves the entry until expiry, how long can that stale-permission window remain?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Subtract elapsed age from the TTL; then distinguish a duration bound from authorization validity.

Compare with the solution

The remaining interval is 300−30=270 seconds. This hypothetical behavior does not meet an immediate-revocation contract merely because it has a finite bound. Apply the actual permission consistency and validation policy; TTL age is a different condition from source access.

Take it with you

  • Embedding, retrieval, context, and answer caches have different dependencies.
  • Matching keys and unexpired TTLs do not establish current authorization.
  • Corpus additions and negative results require invalidation beyond old-result membership.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.