RAG
RAG vs Long Context: Which Should You Use?
Context windows now run past a million tokens. That doesn't make RAG obsolete. Here's how to actually choose between them.
Updated · 5 min read

Context windows have grown fast enough that it's a fair question: if a model can read a million tokens at once, why bother retrieving anything? Just paste the whole document collection in and let the model figure out what's relevant. It's a tempting shortcut, and for some tasks it's the right one. For most production agent workloads, it isn't.
This is the RAG vs long context question, and the honest answer is that it isn't really a competition, it's a matter of matching the mechanism to the shape of the problem. This guide walks through when each approach wins, what the tradeoffs actually cost, and where combining both beats picking one.
How the two approaches differ
Retrieval-augmented generation retrieves a small, ranked set of relevant chunks before generation, so the model only ever sees what a retriever judged relevant to the current query. Long context skips retrieval entirely and passes a much larger volume of raw text directly into the prompt, leaving the model to find what matters on its own.
The difference isn't just architectural, it changes what each approach is good at. RAG scales to enormous document collections, since retrieval narrows millions of documents down to a handful before the model ever sees them. Long context is bounded by the window size, but within that bound it gives the model everything at once, with no retrieval step that could miss something relevant.
When long context wins
Long context is the better fit for single-document or tightly bounded analysis: summarizing one long report, reviewing one codebase file by file, or answering questions that require reasoning across an entire document rather than pulling isolated facts from it. In these cases, a retrieval step could accidentally exclude a passage that turns out to matter, and the document set is small enough that reading all of it is affordable.
It's also simpler to build: no index to maintain, no chunking strategy to get right, no retrieval quality to tune. For a bounded, single-shot task where the whole relevant document set fits comfortably in the window, that simplicity is a real advantage.
When RAG wins
RAG wins whenever the total knowledge base is larger than what fits in a context window, which is most production knowledge bases, and whenever most of a request's context is irrelevant to the current query. A support agent doesn't need every ticket ever filed in its context, it needs the handful relevant to the current customer's issue, and retrieval is what finds those without the cost of processing the rest.
Cost is the other deciding factor. Inference cost scales with the number of input tokens, so re-reading a huge document collection on every single request gets expensive fast, and the attention mechanism's quadratic scaling means a longer context isn't just costlier, it's disproportionately costlier. RAG only pays for the tokens that are actually relevant to the question being asked, which is also why retrieval-augmented generation stays affordable as a knowledge base grows into the millions of documents while a long-context approach to the same corpus does not.
The problem long context doesn't solve
A bigger window doesn't guarantee better attention to what's inside it. The "Lost in the Middle" research found that models tend to attend more reliably to information near the start or end of a long context and less reliably to information buried in the middle, which means simply fitting more text into the window doesn't guarantee the model will actually use all of it correctly.
That finding cuts against the "just use a bigger window" instinct. Extending context length increases the odds of including irrelevant or noisy information alongside anything genuinely useful, and noise competes for the model's attention even when it technically fits. Retrieval exists specifically to keep that noise out before it reaches the model.
How to decide: a RAG vs long context checklist
In practice, the RAG vs long context decision comes down to three questions. First, does the whole relevant document set fit comfortably inside a single context window today, and will it still fit in a year? If not, long context alone won't scale, no matter how large the window gets. Second, is most of what you'd pass in relevant to a typical query, or is it mostly noise the model has to sift through? A knowledge base where any given question only touches a small fraction of the content is exactly what retrieval was built for.
Third, what does a wrong answer cost you? For low-stakes, exploratory tasks, the simplicity of long context is often worth the occasional missed detail. For anything where an agent's answer drives a real action, a support response, a code change, a decision logged as fact, the RAG vs long context tradeoff tips firmly toward retrieval, because narrowing the input to what's actually relevant is also what makes an answer easier to trust and audit after the fact.
Measuring retrieval quality once you pick RAG
Choosing RAG over long context is only the first decision; retrieval quality is what determines whether it actually performs better in practice. Start by measuring recall on a fixed set of representative queries: for each one, does the retriever surface the passage that actually answers it, and does it surface that passage near the top rather than buried on page two of the results? A vector database that returns technically-similar but practically-useless text will make RAG perform worse than a well-tuned long-context approach on the same task.
It's also worth measuring how retrieval quality changes as the underlying corpus grows. A vector database that performs well at ten thousand documents can degrade at ten million without changes to indexing, chunking, or the addition of keyword and graph-based retrieval alongside vector similarity. Re-testing recall periodically, not just once at launch, is the difference between a RAG system that stays reliable and one that quietly gets worse as it scales.
Why most production systems use both
In practice, the strongest systems don't pick one architecture, they use long context for what's naturally bounded, like the current conversation and the specific document a user is working on, and retrieval for everything else, the broader knowledge base an agent might need to draw on. That's effectively what AI agent memory systems do: the active session is long context, and everything durable gets retrieved on demand.
stored's hybrid retrieval fits into that pattern directly: rather than choosing RAG or long context up front, every query retrieves a compact, ranked set of relevant memories, graph relationships, vector matches, and keyword hits combined, so the model gets exactly what it needs without either an unbounded context or a single-strategy retriever missing something.
That combination also sidesteps a subtler cost of long context: even a model with a huge window still has to pay attention over everything included in it, and every additional irrelevant token is a small tax on latency and accuracy alike. Keeping the active context small and letting retrieval do the work of narrowing a much larger memory store down to what's relevant is what lets an agent stay both fast and grounded as the amount it has learned keeps growing.
Frequently asked questions
Has long context made RAG obsolete?
No. Long context works well for bounded, single-document tasks, but most production knowledge bases are larger than any context window and mostly irrelevant to a given query, which is exactly the situation retrieval is built for.
Is RAG cheaper than long context?
Usually. Inference cost scales with input tokens, and attention cost scales worse than linearly with context length, so retrieving only the relevant chunks is typically far cheaper per request than re-processing an entire document collection.
Does a longer context window mean better recall of what's inside it?
Not reliably. Research on long-context models has found attention degrades for information buried in the middle of a long context, so simply including more text doesn't guarantee the model uses all of it correctly.
Can I use RAG and long context together?
Yes, and most production systems do. A common pattern is long context for the current session or document, plus retrieval for everything durable an agent might need from a broader knowledge base or memory store.
Related reading

Retrieval-Augmented Generation (RAG): A Practical Guide
RAG is the default way to ground an LLM in facts it wasn't trained on. Here's how it actually works and where it breaks down.

Context Window: What It Is and Why It Isn't Enough
A million-token context window sounds like enough. Here's why it still isn't a substitute for real AI agent memory.

Context Compression: Fitting More Into a Finite Window
A January 2026 paper cut token usage 22.7% with no accuracy loss. Here's how context compression actually works.
See what your agents remember.
Connect an agent and stored starts building the live memory graph this post describes, free to try.
No credit card required · Free plan available · Bring your own OpenAI key