All posts

Long context vs RAG: when can you skip retrieval and put everything in the prompt?

Long context vs RAG is a size, cost and accuracy decision. When stuffing the whole knowledge base into the prompt works, when it breaks, and how to choose.

CodeKrypt 5 min read

You have a pile of documents and you want an AI feature that answers questions about them. Someone on the team points out that models now accept very large prompts, so why build a retrieval pipeline at all? That question, long context vs RAG, is a real architecture decision, and for some products the honest answer is that you can skip retrieval.

This post covers when that is true, where it stops being true, and a short test for choosing. It is about the domain, not any particular deployment; claims are linked to the sources they come from.

When can you skip RAG and use a long context window?

Anthropic's write-up on contextual retrieval gives a concrete rule of thumb: if your knowledge base is smaller than 200,000 tokens (about 500 pages of material), you can include the entire thing in the prompt and skip RAG. That is a vendor figure for one model family, so check the current window of whichever model you use, but it frames the right question: how big is the corpus in tokens?

Skipping retrieval is attractive because it removes whole components: no chunking, no embeddings, no vector store, no reranker, no re-indexing when you change embedding models. Every one of those is a place retrieval can quietly miss the right passage. A small, stable corpus such as one product's handbook, a policy set or a single contract bundle is the best case for just passing it in.

When does long context break down?

Four situations push you back toward retrieval:

  1. The corpus is bigger than the window. Past the limit there is no choice.
  2. The data changes constantly. Re-sending a large, shifting prompt on every call is expensive and defeats caching.
  3. Different users may see different data. If access depends on the asker, putting everything in the prompt means filtering before the model sees it, which is exactly what retrieval-time filters do. See multi-tenant RAG data isolation.
  4. Accuracy drops as the prompt grows. This one is easy to miss.

On the last point, the "Lost in the Middle" paper (Liu et al., arXiv:2307.03172) found that performance can degrade significantly when the position of relevant information changes, is often highest when it appears at the beginning or end of the input, and drops when the model must use information in the middle. The authors concluded that language models of that time did not robustly use information in long inputs. Newer models may do better, and the paper does not say how much, so treat it as a reason to test your own model on your own documents, not as a verdict.

Two approaches. Long context sends the whole corpus plus the question to the model. RAG retrieves a few relevant passages first and sends only those plus the question.Long contextWhole corpus + questionLLMRAGRetrieveTop passages + questionLLM

How does cost compare?

Long context sends many more input tokens per question; RAG sends few but adds infrastructure. The lever that changes the long-context picture is prompt caching. Anthropic states that caching frequently used prompts between API calls can cut latency by more than 2x and cost by up to 90%. That makes the "stuff it all in" design viable when the same knowledge base prefix is reused across many requests.

The caveat is the word reused. Caching rewards a stable prefix. If your corpus is per-user or edited constantly, you pay for the full input far more often. Our posts on prompt caching and reducing LLM API costs cover the mechanics, and the arithmetic is simple to run yourself: tokens per query, times queries per month, times your provider's current input price, with and without a cache hit rate you have actually measured.

Latency moves the same way. Large inputs add processing time before the first token, which matters for interactive features; see LLM latency and time to first token.

Long context vs RAG: a side-by-side comparison

FactorLong context (no retrieval)RAG
Corpus sizeMust fit the model's windowEffectively unbounded
Moving partsPrompt assembly onlyChunking, embeddings, index, reranking
Data freshnessInstant if you rebuild the promptDepends on re-indexing
Per-user access controlYou filter before building the promptFilter at retrieval time
Cost per queryHigh input tokens; caching helps if stableLow input tokens plus retrieval infra
Main failure modeAnswers degrade as the prompt growsRetrieval misses the right passage
CitationsHarder; you must ask for themNatural: you know which chunks were sent

How do you decide? A four-question test

  1. How many tokens is the corpus today, and in a year? Count with your provider's tokenizer. If it is comfortably under the window with headroom for growth, long context is on the table.
  2. How often does it change? Rarely: caching works. Hourly: probably not.
  3. Does access vary by user? If yes, lean toward retrieval-time filtering.
  4. What does a query cost at your volume? Model it with real token counts and a measured cache hit rate.

Then run an evaluation. Take 30 to 50 real questions with known answers, run them through both designs, and compare accuracy, cost and latency. Put answer positions in the middle of the corpus on purpose. The process for building that set is in LLM evals in CI and prompt regression testing.

There is also a middle path: use retrieval to select the few most relevant documents, then pass those whole rather than as small chunks. It trades some of RAG's cost savings for fewer chunking mistakes. If you stay with chunks, see RAG chunking strategy and hybrid search and reranking. For the broader choice between grounding approaches, read RAG vs fine-tuning.

What should you do next?

If you are building a document-grounded feature into a product and want help choosing the architecture, see our AI SaaS development service and get in touch.

CodeKrypt avatar

CodeKrypt

Drafted by CodeKrypt's AI writing pipeline, built and maintained by our engineers, under fixed rules on sources and claims. How we write

Frequently asked questions

Can a long context window replace RAG?
Sometimes. Anthropic's guidance says that if your knowledge base is smaller than about 200,000 tokens (roughly 500 pages), you can include it all in the prompt and skip RAG. Above that size, or when the data changes constantly or must be access-controlled per user, retrieval is usually still needed.
Do models use long contexts reliably?
Not uniformly. The 'Lost in the Middle' paper found performance can degrade significantly when relevant information sits in the middle of a long input, and is often highest at the beginning or end. Test your own model and documents rather than assuming the full window is usable.
Does prompt caching make long-context prompts cheap?
It helps a lot for a stable knowledge base. Anthropic says caching can reduce latency by more than 2x and cost by up to 90% for frequently reused prompts. It does not help when the context changes on every request.
How do I decide between long context and RAG?
Check four things: knowledge base size, how often it changes, whether users may only see parts of it, and cost per query at your expected volume. Then run the same question set through both approaches and compare.

Related reading

Chat on WhatsApp