MM Huq 7 min readAs AI products accumulate instructions, documents, tool results, and conversation history, context becomes an architectural resource. Sending everything to the model preserves information, but it also consumes computation, increases latency, and can bury the relevant evidence beneath unrelated text.
Three approaches address this pressure: prompt caching reuses computation for repeated prefixes; context compression condenses material before inference; retrieval-augmented generation, or RAG, selects a small body of evidence from a larger corpus. They are often treated as substitutes. In practice, each controls a different form of waste.
The three approaches solve different context problems
| Approach | Core mechanism | Best at | Primary risk |
|---|---|---|---|
| Prompt caching | Reuses model-side processing for an identical or reusable prompt prefix | Repeated, stable context | Low reuse when prefixes change |
| Context compression | Transforms source material into a shorter representation | Long histories and verbose intermediate output | Discarding details needed later |
| RAG | Indexes a corpus and retrieves selected passages for each request | Large, evolving knowledge collections | Failing to retrieve the decisive evidence |
Prompt caching asks, “Have we processed this text before?” Compression asks, “Can we represent this material more economically?” RAG asks, “Which material belongs in this request at all?” That distinction should govern the design.
Prompt caching: preserve the text, reuse the work
Prompt caching is the least transformative option. The application still sends or references substantial context, and the model still reasons over that context. The efficiency gain comes from avoiding repeated processing of a stable prefix.
Consider a contract-review assistant. Every request may begin with a long system policy, an organization’s negotiation playbook, and a standard clause library. Users then append a particular contract and question. If the stable material occupies the beginning of the prompt, a compatible inference system may reuse its prior computation while processing only the changing suffix.
Where it excels
- High fidelity: no summarizer decides which details survive.
- Minimal application logic: the product need not maintain a retrieval index or compressed memory representation.
- Predictable semantics: the model sees the same source text it would have seen without caching.
Where it breaks down
Cacheability depends on stability. Inserting a timestamp, request identifier, personalized instruction, or reordered document near the start may prevent reuse beyond that point. Even semantically equivalent prefixes can be computationally different if their tokens differ.
Prompt caching also does not resolve context-window pressure. A cached policy manual may be cheaper or faster to process, but it still occupies attention space alongside the user’s task. Caching optimizes repeated computation; it does not make the prompt more selective.
Context compression: trade textual completeness for continuity
Context compression replaces verbose material with a smaller representation. The simplest form is summarization: after a conversation grows beyond a threshold, older turns become a compact account of decisions, preferences, unresolved questions, and commitments.
More structured variants extract entities, constraints, state changes, or tool results. A travel-planning assistant, for example, might reduce twenty turns to: destination, date range, traveler count, accessibility requirements, rejected options, budget posture, and open decisions. That representation is shorter and more useful than a generic prose recap.
The central design choice
Compression can be lossy or selective. Lossy compression produces a general summary. Selective compression preserves fields chosen for the workflow. The latter requires more design work but makes omissions easier to detect.
Imagine a support agent compressing a troubleshooting session. “The customer tried standard fixes” is compact but unsafe: the next agent cannot know whether a factory reset occurred. A structured record listing each attempted action is longer, yet preserves operationally significant detail.
The hidden cost
Compression creates a derived source of truth. Once the original exchange falls outside the active context, the model acts on the summary’s interpretation. Errors can compound when one summary is later summarized again. Strong implementations retain the original record, attach provenance to compressed facts, and regenerate summaries when the schema changes.
RAG: choose evidence rather than carrying history
RAG separates stored knowledge from active context. Documents are divided into retrievable units, represented in an index, and selected in response to a query. The model receives only the passages judged relevant, often with identifiers that permit attribution.
This is the natural architecture for a product answering questions across thousands of policies, manuals, cases, or research notes. It can also respond to changing information without rewriting a static prompt: update the source collection and its index, then retrieve from the revised corpus.
RAG’s difficulty lies before generation. A model cannot reason over evidence that retrieval failed to supply. Vocabulary mismatch, poor chunk boundaries, missing metadata, ambiguous queries, and excessive top results can all degrade the answer.
A worked retrieval example
Suppose an employee asks whether parental leave affects bonus eligibility. Pure similarity search may retrieve the leave policy but miss the compensation policy where eligibility is defined. A stronger pipeline can rewrite the question into separate retrieval intents, search both policy domains, filter by jurisdiction and effective date, then rerank the resulting passages before generation.
This reveals RAG’s real character: it is not merely a database attached to a model. It is an evidence-selection system whose quality depends on corpus design, query interpretation, metadata, ranking, and abstention behavior.
Fidelity, latency, and failure modes
The approaches should be compared by what happens when they fail, not merely by their ideal behavior.
| Criterion | Prompt caching | Context compression | RAG |
|---|---|---|---|
| Information fidelity | Highest when source text is preserved | Depends on what compression removes | High for retrieved passages; absent for missed passages |
| Freshness | Requires cache invalidation when stable content changes | Requires recompression when state changes | Requires index updates and version controls |
| Latency profile | Can reduce repeated prefix processing | Adds compression work periodically | Adds retrieval and often reranking on each request |
| Operational complexity | Relatively low | Moderate, especially with schemas and provenance | High because retrieval is a separate quality surface |
| Typical failure | Cache miss or invalid stale prefix | Important detail disappears | Relevant evidence never reaches the model |
These failures demand different tests. Prompt caching needs cache-hit diagnostics and invalidation checks. Compression needs fact-retention tests over long sequences. RAG needs retrieval evaluation that asks whether the necessary passage appears before answer quality is measured.
Worked architecture choices
A coding assistant with repository conventions
Use prompt caching for stable coding standards and tool instructions. Use RAG to fetch relevant files, symbols, and documentation for the current task. Compress the interaction history into accepted decisions and outstanding errors. No single approach covers all three forms of context.
A meeting companion
Compression should carry the evolving state: decisions, owners, deadlines, objections, and unresolved items. Prompt caching may help with stable extraction instructions. RAG becomes useful when the assistant must connect the current meeting to earlier transcripts or organizational documents.
A regulated policy adviser
RAG should select versioned, jurisdiction-specific source passages. Prompt caching can preserve a stable reasoning protocol and output schema. Compression should be used cautiously for case history, with links back to original statements. Here, traceability matters more than maximal reduction.
The strongest systems compose the three
A mature context architecture often has layers:
- Cache the invariant: stable system instructions, schemas, reference examples, and commonly reused documents.
- Compress the accumulated: conversation history, completed tool traces, and resolved workflow state.
- Retrieve the contingent: evidence whose relevance depends on the current question.
Ordering matters. Stable cached content belongs early in the prompt so that changing material does not disrupt the reusable prefix. Retrieved passages should carry source and version metadata. Compressed state should distinguish facts, user preferences, model inferences, and unresolved uncertainty rather than blending them into fluent prose.
The application should also retain an escape route. If compressed memory appears insufficient, recover the original transcript. If retrieval confidence is weak, broaden the search or request clarification. If cached instructions change, invalidate the affected prefix deliberately.
Which approach should you choose?
Choose prompt caching when a substantial block of context repeats exactly or predictably across requests, fidelity is important, and the primary problem is repeated processing rather than context size.
Choose context compression when continuity matters across long interactions, much of the history becomes operationally obsolete, and you can define what must survive. Prefer structured state over unconstrained summaries for consequential workflows.
Choose RAG when the relevant evidence sits inside a corpus too large or dynamic to place in every prompt, and when your team can treat retrieval quality as a first-class product discipline.
Combine them when the product has stable rules, accumulating state, and external knowledge. The revealing principle is simple: cache what remains the same, compress what has already happened, and retrieve what matters now.
This post was drafted with AI assistance and reviewed against our editorial policy before publication. Corrections are made at the source, on the page, with the date shown.
From our own rounds
Measured on The Curator, from real sessions people played on this site — not a third-party dataset.
- Rounds played here
- 126
- Questions per round
- 1.7
Rate this article
Discussion
Comments are moderated. Read our editorial policy.