Home / Insights / Generative AI and LLMs
Generative AI and LLMs
Long Context Windows vs Retrieval: When to Stuff the Prompt and When to Search
Context windows have grown from a few thousand tokens to hundreds of thousands, and some teams now ask whether retrieval is still needed. The honest answer depends on corpus size, question type, cost and how much accuracy you can afford to lose in the middle.
Key takeaways
- Long context is the simplest design when the material for one task fits comfortably in the window and changes per request, such as one contract or one case file.
- Retrieval wins when the corpus is larger than any window, when permissions vary by user, or when per-question cost and latency matter at volume.
- Advertised window size is not effective window size: research shows accuracy drops for information buried in the middle and as tasks get more complex.
- Cost scales with every token sent on every request; a prompt of 150,000 tokens costs about 30 times more than one of 5,000 at the same price per token.
- Most production systems end up hybrid: retrieve to narrow the material, then use a generous window for the selected documents.
On this page
- What has changed with long context windows?
- Where does long context fall short?
- How do long context and retrieval compare?
- How do you decide which approach fits your feature?
- How do you implement a hybrid design?
- What risks should you plan for, and what is the checklist?
- Frequently asked questions
- Sources and methodology
In early 2023 most production language models could read a few thousand tokens at a time, so retrieval-augmented generation (RAG) was the only practical way to answer questions over company documents. By mid-2024 the picture has changed. Anthropic’s Claude 3 models launched in March with a 200,000-token window, and Google introduced Gemini 1.5 Pro with an experimental window of up to 1 million tokens. Product teams now reasonably ask: why build a retrieval pipeline at all if we can put everything in the prompt?
This article is for CTOs, product leads and engineering managers designing LLM features. It explains what long context actually delivers, where it falls short, how cost and latency compare, and a decision framework for choosing long context, retrieval or a combination. The goal is a design you can defend on accuracy, cost and maintainability, not the one that sounds most modern.
What has changed with long context windows?
A context window is the amount of text, measured in tokens, a model can take in for a single request, including your instructions, the material and the conversation so far. Larger windows open up genuinely new options.
- Anthropic Claude 3 (March 2024). All three models launched with a 200,000-token context window, and Anthropic reported that Claude 3 Opus achieved near-perfect recall, above 99% accuracy, on its “needle in a haystack” evaluation.
- Google Gemini 1.5 Pro (February 2024). Google announced a standard 128,000-token window and an experimental window of up to 1 million tokens, which it described as roughly 1 hour of video, 11 hours of audio, codebases of more than 30,000 lines or over 700,000 words. Google also warned early testers to expect longer latency with the experimental window.
Practically, this means a full contract, a long technical specification, a quarter’s worth of support tickets for one customer, or a medium-sized codebase can now be read in one request. Tasks that previously needed careful chunking and retrieval can sometimes be solved by sending the whole thing.
What it does not change
Context is per request. A model does not remember last week’s prompt, so long context does not replace a knowledge base. Every request pays for every token sent. And as the next section shows, being able to accept a million tokens is not the same as using all of them well.
Where does long context fall short?
Accuracy is not uniform across the window
The widely cited “Lost in the Middle” study (Liu et al., 2023) tested models on multi-document question answering and key-value retrieval. It found that performance is often highest when relevant information occurs at the beginning or end of the input, and degrades significantly when that information sits in the middle, even for models built for long contexts.
Needle-in-a-haystack tests, where a single planted sentence must be found, are the easiest case. The RULER benchmark (Hsieh et al., 2024) extended them with multiple needles, multi-hop tracing and aggregation tasks. Across 17 long-context models, almost all scored near-perfectly on the simple test, but performance dropped substantially as length grew, and only half of the models claiming 32,000 tokens or more maintained satisfactory performance at 32,000 tokens. The lesson is that effective context, the length at which a model still reasons reliably for your kind of task, is usually shorter than the advertised window.
Cost grows with every request
Input tokens are billed on every call. At the Claude 3 Sonnet launch price of $3 per million input tokens, a 150,000-token prompt costs about $0.45 per question before any output, while a 5,000-token retrieved context costs about $0.015. For an illustrative internal assistant answering 2,000 questions a day, that is roughly $900 a day against $30 a day for input alone. Prices vary by model and fall over time, but the ratio stays: you pay for what you send.
Latency grows too
Models must process every input token before producing the first output token. A long prompt makes the user wait longer, which matters for chat interfaces and for agent loops that make many calls.
Some needs are structural, not size-related
- Permissions. If users may only see some documents, you must select content per user anyway. That selection is retrieval.
- Freshness. A corpus that changes daily must be re-selected for every request.
- Traceability. Citing the exact passage behind an answer is easier when the system knows which passages it supplied.
How do long context and retrieval compare?
| Criterion | Long context (send everything) | Retrieval (RAG) | Hybrid (retrieve, then generous context) |
|---|---|---|---|
| Corpus size it suits | Fits within the effective window | Unlimited | Unlimited |
| Build effort | Low | Moderate to high (ingestion, indexing, evaluation) | Moderate to high |
| Cost per question | High, scales with material size | Low | Medium |
| Latency | Higher | Lower generation time, plus search time | Medium |
| Cross-document reasoning | Strong when everything is present | Limited to what is retrieved | Good within the selected set |
| Risk of missing information | Lost-in-the-middle effects | Retrieval misses | Both, at lower severity |
| Per-user permissions | Requires pre-selection anyway | Natural fit | Natural fit |
| Citations | Possible but harder to verify | Natural fit | Natural fit |
The table shows why the debate is usually a false choice. Long context and retrieval solve different parts of the problem: retrieval decides what the model sees; the window decides how much of it can be seen at once.
How do you decide which approach fits your feature?
Five questions settle most designs.
- How large is the material for one task? If the documents needed for one request fit well inside the effective window, for example a single 60-page agreement, long context is a strong default. If the material is a whole document library, you need retrieval.
- Is the material fixed per task or chosen from a corpus? Reviewing an uploaded file is a long-context task. Answering any question about any policy is a retrieval task.
- What type of question is it? Summaries, comparisons across a whole document, and “find all clauses that…” questions benefit from seeing everything. Narrow factual look-ups are well served by retrieval.
- What volume and latency are expected? A few hundred analyst requests a day can absorb long-context cost. Thousands of chat questions an hour usually cannot.
- Do permissions or freshness vary? If yes, you need a selection step, so build retrieval in from the start.
Typical outcomes
- Long context: contract review, due diligence on a single data room folder, meeting transcript analysis, code review of one repository module.
- Retrieval: internal knowledge assistants, customer help search, policy Q&A across hundreds of documents.
- Hybrid: research assistants, case-based support where the assistant retrieves the relevant customer’s history and then reads it in full.
For example, an illustrative legal operations team might use long context for “summarise the obligations in this agreement” and retrieval for “which of our 4,000 supplier contracts have a change-of-control clause?”. Same users, same model, two designs.
How do you implement a hybrid design?
Most production systems we build end up hybrid. The pattern below keeps cost predictable while using larger windows where they help.
Step-by-step
- Retrieve at document level first. Use search to identify the handful of documents relevant to the question, not just isolated chunks.
- Expand intelligently. Pass whole sections or whole documents for the top results rather than small fragments, within a token budget you set per feature.
- Order the context deliberately. Because models attend best to the start and end of the input, put the most relevant material and the instructions in those positions, and the question at the end.
- Set a budget and enforce it. Define a maximum input size per request type, and truncate or summarise lower-ranked material rather than letting prompts grow without limit.
- Ask for citations. Label each supplied passage with an ID and ask the model to cite IDs, then validate that the cited passages exist.
- Re-use repeated context where providers support it. When the same large document is queried many times, check whether your provider offers context caching, which some have begun to introduce, and test whether it reduces cost for your access pattern.
Keep the two concerns separate in code
Treat “select the material” and “generate the answer” as separate components with their own interfaces and tests. The selection component might be a no-op that passes the uploaded file through, a search call, or a two-stage retrieve-and-expand step. The generation component receives a bounded list of labelled passages regardless. This separation lets you change the balance between retrieval and context size as models and prices change, without rewriting the feature. It also gives you one place to enforce permissions, token budgets and logging, which matters more as features multiply.
Measure before you commit
Build a small evaluation set from real questions, then run three configurations on it: long context only, retrieval only and hybrid. Record accuracy, cost per question and latency. This usually takes days, not weeks, and turns a debate into a decision. Our guide to building a test set for enterprise knowledge search describes how to build the question set, and reducing LLM token costs covers the cost side in more depth.
What risks should you plan for, and what is the checklist?
Risks
| Risk | Where it appears | Mitigation |
|---|---|---|
| Missed information in the middle of long prompts | Long context, hybrid | Order context deliberately; test with answers placed at different positions |
| Retrieval misses the right passage | Retrieval, hybrid | Hybrid keyword and vector search; measure recall on a test set |
| Runaway token cost | Long context | Per-feature token budgets, monitoring, alerts |
| Slow responses | Long context | Streaming output; smaller budgets for interactive features |
| Leaking content across users | Any design that pre-loads shared context | Select content per user before it reaches the prompt |
| Prompt injection hidden in long documents | Both, more surface in long context | Treat document text as data; validate outputs and tool calls |
Decision checklist
- Estimate the token size of the material needed for a typical request and the largest realistic request.
- Confirm the model’s effective, not advertised, context for your task type with your own tests.
- Calculate input cost per request and per month at expected volume for each design.
- Agree a latency target per feature (interactive chat versus background analysis).
- Decide whether permissions or freshness require per-request selection.
- Run long-context, retrieval and hybrid variants on the same evaluation set.
- Set token budgets, logging and cost alerts before launch.
PoliteTech’s LLM application development team builds production features with retrieval pipelines, typed outputs, fallback models and cost dashboards, and compares models and prompts on quality, cost and speed before recommending a design. The choice between long context and retrieval is one we make with evidence from your own data.
Frequently asked questions
If models accept a million tokens, is RAG obsolete?
No. Large windows are useful for reading one big document or a bounded set, but retrieval is still needed when the corpus is larger than any window, when users have different permissions, or when cost and latency per question matter at volume. Most systems combine both.
Is long context more accurate than retrieval?
Not reliably. Research such as Lost in the Middle and RULER shows accuracy depends on where information sits and how complex the task is, and effective context is often shorter than the advertised window. Test both on your own questions.
How much more does long context cost?
Input cost scales with tokens sent. At the same price per token, a 150,000-token prompt costs about 30 times more than a 5,000-token one, on every request. Whether that matters depends on your volume.
Which approach is faster to build?
Long context is faster to prototype because there is no ingestion or index. Retrieval takes longer to build but is usually cheaper to run at scale. A prototype with long context can be a good way to validate the use case before investing in retrieval.
Can we start with long context and add retrieval later?
Yes, if you design for it. Keep documents and metadata in a store you control, log questions and answers, and build an evaluation set early. Adding a retrieval step later is then an architectural change, not a rewrite.
Sources and methodology
Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.
- Liu et al.: Lost in the Middle: How Language Models Use Long Contexts (arXiv 2023; TACL) — accessed 9 November 2026. Accuracy is highest when relevant information is at the start or end of the input and drops in the middle.
- Hsieh et al.: RULER: What’s the Real Context Size of Your Long-Context Language Models? (arXiv, April 2024) — accessed 9 November 2026. 17 models on 13 tasks; only half of models claiming 32K+ tokens perform satisfactorily at 32K.
- Google: Our next-generation model: Gemini 1.5 (15 February 2024) — accessed 9 November 2026. Gemini 1.5 Pro standard 128K window, experimental 1M window, what 1M tokens holds, and latency caveat.
- Anthropic: Introducing the next generation of Claude (4 March 2024) — accessed 9 November 2026. 200K context window at launch, needle-in-a-haystack recall result, and per-million-token prices used in the cost example.
Related reading
Continue your research
Should your LLM feature read everything or search first?
We can test long-context, retrieval and hybrid designs on your own documents and show the accuracy, cost and latency of each.
