Long context vs RAG: when a big prompt replaces retrieval, and what caching changes
Million-token context windows tempt teams to skip retrieval and paste everything into the prompt. This guide works out the cost, latency and break-even point of long context versus RAG, shows how prompt and KV caching move the line, and explains why long inputs still lose facts.
- Reading time
- 14 min
- Sections
- 7
- Code examples
- 2
- Tables
- 2
- Sources
- 8
- Published
- 24 Nov 2026
- What changed
- LMCache 0.5.8 extends KV reuse for long-context and RAG workloads
- Why it matters
- Long context did not make RAG obsolete; it moved the boundary.
- What to do
- Measure your corpus in tokens
Every few months a model ships with a larger context window, and the same question returns: if the model can read a million tokens, why build a retrieval system at all? Paste the handbook, the codebase or the contract set into the prompt and ask. No chunking, no embeddings, no vector database, no missed passages.
For some workloads that is now the right answer. For many others it is a slow and expensive way to get a slightly worse result. The difference comes down to three numbers that can be computed in advance: how big the corpus is, how many questions you ask of the same text, and how much of the prompt can be cached. This article works through those numbers, explains how prompt caching and the newer KV-cache reuse layers change them, summarises what research says about accuracy over long inputs, and ends with a decision rule.
An analogy: long context is handing an expert the whole binder every time you ask a question. Caching is letting them keep the binder on their desk between questions. RAG is a good index that tells them which three pages to read. Which is best depends on how thick the binder is and how many questions you ask.
What happened
LMCache 0.5.8 extends KV reuse for long-context and RAG workloads (22 November 2026)
LMCache, an open-source KV cache management layer for LLM inference, released 0.5.8 on PyPI on 22 November 2026. Its project description says it "reduces TTFT (time-to-first-token) and improves throughput, especially for long-context agentic, multi-turn conversation, and knowledge-augmented workloads (e.g., RAG)". It lists persistent, tiered offloading of KV caches from GPU memory to CPU memory, local disk and remote backends, and "non-prefix KV reuse", which reuses cached KV blocks "at any position in the prompt" using CacheBlend to "selectively recompute tokens for quality recovery". For RAG this matters because retrieved chunks appear in different orders and positions in different prompts, which ordinary prefix caching cannot reuse.
vLLM 0.34.0 released (16 November 2026)
vLLM, the open-source serving engine, released 0.34.0 on 16 November 2026. Its project description lists prefix caching and chunked prefill among core features, alongside PagedAttention memory management. Prefix caching is what makes "same long document, many questions" affordable on self-hosted models: the document's key and value tensors are computed once and reused while they stay in cache.
The arithmetic: cost and latency per question
Take three options for answering questions over a corpus:
- Long context, uncached: send the whole corpus plus the question every time.
- Long context, cached: send the same, but the corpus prefix is read from cache. The Anthropic cookbook on contextual embeddings describes cached reads at a 90 percent discount, so this example bills cached tokens at 10 percent of the normal price.
- RAG: retrieve about 3,000 tokens of relevant chunks per question.
Example prices: 3 dollars per million input tokens, 15 dollars per million output tokens, 300 output tokens per answer, 1,000 questions per day, and a prefill speed of 20,000 tokens per second for computing new (uncached) prompt tokens.
PRICE_IN = 3.00 / 1e6
CACHED = 0.10 * PRICE_IN # 90 percent discount on cache reads
OUT = 15.00 / 1e6
Q, ANSWER, PREFILL_TPS = 1000, 300, 20_000
def per_question(corpus_tokens, mode, rag_context=3_000):
if mode == "long, uncached": cost, new = corpus_tokens * PRICE_IN, corpus_tokens
elif mode == "long, cached": cost, new = corpus_tokens * CACHED, 50
else: cost, new = rag_context * PRICE_IN, rag_context
return cost + ANSWER * OUT, new / PREFILL_TPS
for corpus in (20_000, 100_000, 300_000, 1_000_000):
for mode in ("long, uncached", "long, cached", "RAG"):
c, s = per_question(corpus, mode)
print(corpus, mode, round(c, 4), round(c * Q, 2), round(s, 3))
print("break-even:", int(3_000 * PRICE_IN / CACHED), "tokens")
| Corpus size | Mode | Dollars per question | Dollars per day (1,000 questions) | New-token prefill time |
|---|---|---|---|---|
| 20,000 | Long, uncached | 0.0645 | 64.50 | 1.000 s |
| 20,000 | Long, cached | 0.0105 | 10.50 | 0.003 s |
| 20,000 | RAG | 0.0135 | 13.50 | 0.150 s |
| 100,000 | Long, uncached | 0.3045 | 304.50 | 5.000 s |
| 100,000 | Long, cached | 0.0345 | 34.50 | 0.003 s |
| 300,000 | Long, uncached | 0.9045 | 904.50 | 15.000 s |
| 300,000 | Long, cached | 0.0945 | 94.50 | 0.003 s |
| 1,000,000 | Long, uncached | 3.0045 | 3,004.50 | 50.000 s |
| 1,000,000 | Long, cached | 0.3045 | 304.50 | 0.003 s |
| any size | RAG (3,000 tokens) | 0.0135 | 13.50 | 0.150 s |
Read it in four steps.
- Uncached long context scales linearly and painfully. At one million tokens, each question costs about 3 dollars and needs 50 seconds of prefill at the example speed. That is a research tool, not a chat product.
- Caching changes the picture by an order of magnitude. With a 90 percent discount, cached long context beats RAG on cost for small corpora; at 20,000 tokens it is 0.0105 dollars per question against 0.0135.
- The break-even point is simple. Cached long context costs the same as RAG when corpus × cached price = RAG context × normal price. With a 3,000-token RAG prompt and a 10 percent cached rate, that is 30,000 tokens. Above it, RAG is cheaper per question; at 300,000 tokens it is seven times cheaper.
- Caching removes most prefill latency, not all latency. Only the new question needs prefill, but each generated token still attends over the whole cached context, so decoding over a million-token cache is slower than over 3,000 tokens.
The table ignores three things that push against long context: cache writes (the first request pays to create the cache, often at a premium), cache lifetimes (entries expire after minutes or hours, so bursty traffic misses), and per-user content (a corpus filtered by permissions cannot be shared in one cache). It also ignores what pushes against RAG: the cost of running an index, embedding updates, and engineering time. The site's article on context prices and prefix caching and the prompt cache simulation explore hit rates in detail.
Accuracy: does the model actually use long context?
Cost is only half of the question. The other half is whether a model answers as well from a 300,000-token prompt as from 3,000 well-chosen tokens. Research says: not reliably.
Position matters. "Lost in the Middle" (Liu and colleagues, arXiv 2307.03172) found that models used information best when it appeared at the beginning or end of the input, and performance dropped when the relevant passage sat in the middle of a long context. The U-shaped curve has softened in newer models but not vanished.
Advertised length is not effective length. RULER (Hsieh and colleagues at NVIDIA, arXiv 2404.06654) tested models on synthetic tasks beyond simple needle retrieval, such as multi-hop tracing and aggregation, and found that many models fell well short of their claimed context length on these harder tasks, even when they passed basic needle-in-a-haystack tests.
Retrieval and long context can combine. "Retrieval meets Long Context Large Language Models" (Xu and colleagues at NVIDIA, arXiv 2310.03025) found that a model with a 4K context window plus retrieval could match a 16K-context model on long-context tasks, and that adding retrieval improved long-context models too. Retrieval is not only a workaround for short windows; it also focuses attention.
Why does this happen? Attention spreads probability across every token. With 3,000 tokens of relevant chunks, most of that attention lands on useful text. With 300,000 tokens, the relevant sentence competes with everything else, including passages that look similar but answer a different question. The site's KV cache simulation, the explainers on the KV cache and on RoPE scaling for longer contexts cover the mechanics that make long contexts possible and costly.
Where each approach wins
| Situation | Better choice | Reason |
|---|---|---|
| Small, stable corpus (under roughly 30,000 to 100,000 tokens) with many questions | Long context with caching | Cheaper or close to RAG, no retrieval misses |
| One-off deep analysis of a long document | Long context, uncached | No index to build; cost paid once |
| Questions needing the whole document at once (summaries, cross-references) | Long context | Retrieval would fragment the evidence |
| Large or growing corpus (millions of tokens) | RAG | Cost and latency per question stay flat |
| Per-user permissions on documents | RAG | Filter at retrieval; shared caches leak or miss |
| Frequent updates | RAG | Re-index changed chunks; long-context caches must rebuild |
| Exact citations required | RAG, or long context with citation prompts | Chunk IDs make citations simple |
Hybrids are common and sensible. Retrieve the 10 to 20 most relevant documents rather than chunks, and pass them whole into a long context: retrieval narrows the corpus, long context avoids fragmenting documents. Or keep a fixed cached prefix of core material, such as policies or an API reference, and retrieve only the variable part. KV reuse layers such as LMCache aim to make that second pattern cheaper on self-hosted models by reusing the cached state of frequently retrieved chunks even when they appear in different positions.
What it means in practice
Long context did not make RAG obsolete; it moved the boundary. For small, stable corpora with steady traffic, a cached long prompt, one tool in the wider practice of context engineering, is now often the simplest and cheapest design, and it removes an entire class of retrieval failures. Past a few tens of thousands of tokens of shared material, the arithmetic favours retrieval again, and the accuracy research gives a second reason to keep prompts focused.
Caching is the variable most teams underuse. Whether you use long context or RAG, stable instructions, tool definitions and core reference text should sit at the start of the prompt so they cache. In self-hosted stacks, engine-level prefix caching in vLLM and add-on layers such as LMCache extend this to longer documents and, increasingly, to reused chunks in the middle of prompts. The site's prompt caching page, the article on open models with million-token attention and the article on MemOnce compact memory show other ways the field is attacking long-context cost.
Measure before choosing. Run the same 100 questions through both designs, record accuracy, cost and latency, and include questions whose answer sits in the middle of long documents.
Continue learning
How this article connects
7 pages link to or from it. Drag to turn, click a dot to open it.
- vLLM
- Prompt caching
- Context engineering
- Context has a price: why trimming a coding agent's prompt can double its
- How open models reach 1M tokens: Kimi K3, GLM-5.3-Flash and MiniMax-M3 c
- Extending context windows with RoPE scaling: position interpolation, NTK
- MemOnce explained: a 25 MB memory that beats full context for a 4B model
What to do now
- Measure your corpus in tokens. Count the tokens of the material questions draw on; the break-even calculation starts here.
- Compute your break-even size. Divide your RAG prompt cost by the cached input price to find the corpus size where the two cost the same.
- Estimate cache hit rates honestly. Account for cache lifetimes, traffic gaps and per-user content; a 50 percent hit rate halves the benefit.
- Put stable content first. Order prompts as instructions, tools, fixed reference text, then retrieved or per-question content, so the prefix caches.
- Test accuracy by position. Place known answers at the start, middle and end of long prompts and compare with RAG on the same questions.
- Use retrieval to narrow, long context to read. Retrieve whole documents or sections and let the model read them in full when fragmentation hurts.
- Keep permissions in retrieval. Do not put documents a user cannot see into a shared cached prompt.
- Try KV reuse on self-hosted stacks. Enable prefix caching in your serving engine and evaluate layers such as LMCache for repeated chunks.
Risks and open questions
Accuracy can degrade silently. A model may answer fluently from a long prompt while missing a key passage in the middle. Without position-aware tests you will not notice.
Cache economics depend on provider terms. Discounts, write premiums and cache lifetimes differ by provider and change over time; recompute break-even points when they do.
Long prompts raise data exposure. Sending a whole corpus with every request moves more data through more systems and logs than sending three chunks.
Non-prefix KV reuse trades quality for speed. Methods like CacheBlend recompute only some tokens; how much quality they recover varies by model and workload and needs testing.
Benchmarks lag models. Needle tests are easy to pass; harder long-context tasks change faster than published results, so check recent evaluations for the models you use.
Watch next: whether providers extend cache lifetimes and discounts further, and whether position-independent KV reuse becomes a standard serving feature that makes retrieved chunks almost as cheap to reuse as a fixed prefix.
Frequently asked questions
Does long context make RAG obsolete?
No. Long context with caching is now competitive for small, stable corpora with many questions, but for large or changing corpora, per-user permissions and tight latency budgets, RAG remains cheaper and often more accurate. Many systems combine the two.
What is the break-even point between long context and RAG?
It is the corpus size where cached long-context cost per question equals RAG cost per question: RAG prompt tokens times the normal price divided by the cached price. With a 3,000-token RAG prompt and cached reads at 10 percent of the normal price, it is 30,000 tokens.
Does prompt caching make long prompts fast?
It removes most prefill time for the cached part, so time to first token drops sharply. Each generated token still attends over the whole context, so decoding is slower than with a short prompt, and the first request still pays to build the cache.
Why do models miss information in long prompts?
Attention is spread over every token, and research such as "Lost in the Middle" found models use information at the start and end of the input better than in the middle. Benchmarks like RULER show effective context is often shorter than the advertised window on harder tasks.
What is KV cache reuse for RAG?
It stores the key and value tensors computed for frequently used text, such as popular chunks, and reuses them in later prompts instead of recomputing them. Prefix caching only reuses a shared beginning; newer methods such as CacheBlend in LMCache aim to reuse chunks at any position with partial recomputation.
Summary
Long context and RAG are two ways to put knowledge in front of a model, and the choice can be computed. Uncached long context scales linearly: at the example prices a million-token prompt costs about 3 dollars and 50 seconds of prefill per question. Caching at a 90 percent discount cuts cost tenfold and makes long context cheaper than a 3,000-token RAG prompt for corpora under about 30,000 tokens; above that, RAG wins on cost, and at 300,000 tokens by a factor of seven. Research from "Lost in the Middle" to RULER adds that long prompts do not guarantee the model uses every fact. With LMCache 0.5.8 and vLLM 0.34.0 extending KV reuse this month, the practical rule is: cache stable prefixes, use long context for small stable corpora and whole-document reasoning, and use retrieval to keep large, changing or permissioned corpora focused.
Sources
- Code PyPI: lmcache project description and release history
- Code PyPI: vllm project description and release history
- Code GitHub: Anthropic contextual embeddings cookbook guide
- Paper arXiv: Lost in the Middle: How Language Models Use Long Contexts (Liu et al.)
- Paper arXiv: RULER: What's the Real Context Size of Your Long-Context Language Models? (Hsieh et al.)
- Paper arXiv: Retrieval meets Long Context Large Language Models (Xu et al.)
- Paper arXiv: CacheBlend: Fast Large Language Model Serving for RAG with Cached Knowledge Fusion (Yao et al.)
- Paper arXiv: Efficient Memory Management for Large Language Model Serving with PagedAttention (Kwon et al.)
Cite this article
Kelahmet, Ö. C. (2026, November 24). Long context vs RAG: when a big prompt replaces retrieval, and what caching changes. Özer Cem KELAHMET. https://www.ozercemkelahmet.com/articles/long-context-vs-rag-caching-break-even
BibTeX
@online{kelahmet2026long,
author = {Kelahmet, {\"O}zer Cem},
title = {{Long context vs RAG: when a big prompt replaces retrieval, and what caching changes}},
year = {2026},
month = {nov},
url = {https://www.ozercemkelahmet.com/articles/long-context-vs-rag-caching-break-even}
}Version historyfirst version
- Published
Factual corrections are listed here with what changed. Wording and formatting edits are not listed.