RAG vs long context: which to choose (and when to combine them)
When you want an LLM to answer about your documents there are two main paths: retrieve only the relevant fragments and give them to the model (RAG), or put whole documents into a very large context window (long context). Today’s models accept huge contexts, so the question is a legitimate one: is RAG still worth it?
The honest answer: it depends on four factors, and often the best solution combines both.
Quick reminder
- RAG: you index your documents, search for the most relevant fragments for each question and only those go into the prompt. I explained it in RAG: giving LLMs memory.
- Long context: you put the whole document (or set of documents) in the prompt and ask the question.
The four decision factors
1. Data volume
- A few pages or a manual: long context works and is much simpler.
- Thousands of documents or a knowledge base that keeps growing: it doesn’t fit in a prompt. RAG.
2. Cost and latency per query
With long context, every question pays for processing all the documents. With RAG, only for the retrieved fragments. Two nuances:
- With prompt caching, repeating the same long document becomes much cheaper, which greatly improves long context for sessions with several questions about the same text.
- Processing huge contexts increases the latency of the first response.
3. Answer quality
- With very long contexts, models can overlook information located in the middle of the text or lose precision; performance is not uniform.
- RAG reduces noise but introduces another point of failure: if the search doesn’t retrieve the right fragment, the model can’t get it right.
That is why you need to measure, not assume (LLM evals).
4. Rate of change and traceability
- Data that changes daily: RAG lets you reindex only what was modified.
- If you need to cite the exact source and control which documents each user can see, RAG offers more control (filtering by permissions and metadata).
Decision table
| Situation | Recommendation |
|---|---|
| Analysing a specific contract or report | Long context |
| Repeated questions about the same document | Long context + cache |
| Large, changing knowledge base | RAG |
| Different permissions per user | RAG with filters |
| You need to cite precise fragments | RAG |
| Quick prototype with few documents | Long context |
A minimal example of each approach
Long context (the whole document in the prompt):
document = open("returns_policy.md", encoding="utf-8").read()
prompt = f"""Answer only with the information in the document.
If it isn't there, say you don't know.
<document>
{document}
</document>
Question: How many days do I have to return a product?"""
RAG (only the relevant fragments):
fragments = searcher.search("return window", k=4) # your vector search
context = "\n\n".join(f.text for f in fragments)
prompt = f"""Answer only with this context. Cite the source.
{context}
Question: How many days do I have to return a product?"""
The hybrid approach
Many good systems combine both:
- RAG to find the relevant documents or sections among thousands.
- Long context to give the model the whole document or chapter (not just a snippet) so it can reason with the full context.
It is especially useful when small fragments lose the context needed to understand the answer.
Common mistakes
- Building RAG when pasting the document was enough. Unnecessary complexity.
- Putting 500 pages in the prompt “because it fits” and expecting perfect accuracy.
- Not evaluating retrieval: if the search fails, no model can fix it.
- Ignoring the cost per query at scale.
Conclusion
Long context for what is small and one-off; RAG for what is large, changing and with permissions; hybrid when you need the best of both. And in any case, measure with your own questions before deciding.
If you want to design an assistant over your company’s documentation, ask me for a call.