keepcalculator

06 Numbers and Powers

RAG vs Long-Context Models for AI Agents

Card No. 06·52852 · Updated · Standard formula, shown below

RAG and long-context models give AI agents access to information in different ways: retrieval-augmented generation (RAG) finds relevant material and adds it to a request, while a long-context model can accept a much larger amount of text at once. Neither is universally better; the right choice depends on how much information an agent must use, how often it changes, and the cost and reliability requirements.

What RAG and long context mean

A language model does not automatically know the contents of a company’s private documents, current product catalogue, or a user’s files. An agent needs those materials supplied at the point of use, or exposed through tools it can call.

RAG is a method for supplying relevant external information. A system searches a collection of documents, selects passages that appear useful, and includes them in the model’s input. “Long context” describes a model’s capacity to process a comparatively large input, often measured in tokens. Tokens are pieces of text, not exactly words; their number depends on the language and formatting.

These approaches are not opposites. A RAG system can provide selected passages to a long-context model, and a long-context model can process a document set after retrieval has narrowed it down. The distinction is chiefly about how information is selected and delivered.

How each approach works

A typical RAG pipeline prepares documents by splitting them into passages, converting passages into searchable representations, and storing them in an index. When an agent receives a question, the system searches for likely matches, may rerank them, and sends selected passages along with the question. The model then generates an answer from the supplied context. Some systems include source references so a reader can inspect the evidence.

A long-context workflow instead places a large amount of source material directly into the model’s prompt. This might be a lengthy report, a conversation history, or several reference files. The model can reason across the provided material without a separate retrieval step, provided the material fits within the model’s context limit and the application has assembled it correctly.

Both workflows involve more than a model’s nominal context window. Applications may reserve room for instructions, the user’s request, tool results, and the model’s response. An agent that makes several tool calls may also need to manage accumulated history rather than repeatedly sending everything.

Where RAG tends to fit

RAG is useful when an agent needs to search a large or frequently updated collection but usually needs only a small part of it for any one question. A support agent, for example, could retrieve the current return-policy passage and a relevant product guide rather than send every company document with every request.

  • Large collections: The full library may be too large or wasteful to include in each prompt.
  • Changing information: Updating an indexed source can make new material available without retraining the language model. Indexing and caching may still introduce a delay.
  • Traceability: Retrieved passages can be shown as evidence, though citations must be checked against the actual answer.
  • Targeted access: Search can limit what enters a request, but permissions must be enforced before retrieval, not assumed from the model’s behavior.

RAG adds operational work: document extraction, passage boundaries, indexing, search quality, metadata, access controls, and refresh schedules all affect results. It can fail by retrieving irrelevant text, missing the right passage, or returning fragments that omit necessary context.

Where long context tends to fit

Long context can be convenient when the relevant material is already known and can be assembled as a manageable set. An agent reviewing one long contract, comparing a few lengthy reports, or analyzing a conversation may benefit from seeing the material together rather than relying on a search system to select passages.

Putting related material in one input can help preserve relationships between sections. It may also avoid a separate retrieval pipeline. But a large context window is capacity, not a guarantee that the model will use every detail correctly. Models can overlook information, confuse similar passages, or give more attention to some parts than others. Long inputs can also increase processing time and usage costs, depending on the model and service.

Context limits are model- and service-specific, and providers may count input and output tokens together or apply other limits. Check the current documentation for the model being used rather than assuming that a stated maximum means an application can send that much source text on every call.

How to choose or combine them

Start with the information pattern, not a headline context-window number. Ask whether the agent must search an expansive library, whether the relevant documents are known in advance, how quickly sources change, and whether users need evidence they can verify.

  1. Use RAG first when the corpus is large, questions vary, and each answer needs only a few passages.
  2. Use long context directly when the source set is limited, known, and important to consider as a whole.
  3. Combine them when retrieval can identify a useful subset and the model needs enough room to compare those passages in context.
  4. Test representative tasks with real documents, including questions whose answers are absent, contradictory, or spread across multiple sources.
  5. Measure more than answer fluency: check factual accuracy, source support, retrieval misses, latency, token use, and behavior when evidence is insufficient.

For example, an internal policy assistant might retrieve the current policy and relevant jurisdictional guidance, then pass those passages to a model with room to compare them. Sending the entire archive every time may be inefficient; retrieving just one sentence may omit an exception. The system should make the source and date visible and avoid presenting an unsupported answer as certain.

Common problems, cost, and safety

RAG’s central risk is that the answer can only be as grounded as the retrieved evidence. Search can miss a document because of poor extraction, vague wording, incorrect metadata, or an index that has not been refreshed. Increasing the number of retrieved passages is not automatically a fix: extra material can distract the model or crowd out useful context.

Long-context systems avoid some retrieval misses but can still misread or fail to use relevant details. They also do not remove the need to manage source versions, conflicting documents, or untrusted text. A document may contain instructions that conflict with the agent’s intended task; treat retrieved or supplied content as data, not as authority to override system rules or trigger actions.

Cost comparisons depend on the model, provider, input size, caching, retrieval infrastructure, and how often requests run. RAG has engineering and maintenance costs; long prompts can require more model processing. A fair comparison measures the full application on the same tasks, rather than comparing only storage costs or the advertised context limit.

For either design, apply access controls at the data layer, avoid sending sensitive material to services not approved for it, and log enough information to investigate failures without retaining unnecessary private content. Retrieval should respect each user’s permissions, and model output should not be treated as proof that a source was authorized or correctly interpreted.

Frequently Asked Questions

Is RAG better than a long context window?
Not in every case. RAG is often practical for searching large collections; long context can suit a known, bounded set of material. Test the approach against the agent’s actual tasks.

Can RAG and long context be used together?
Yes. A system can retrieve relevant passages and provide them to a model with enough context to compare sources, instructions, and conversation history.

Does a longer context window prevent hallucinations?
No. More room lets a model receive more material, but it does not ensure the model will interpret it correctly or distinguish evidence from unsupported claims.

Does RAG require fine-tuning?
Usually not. RAG supplies external material at request time and is distinct from changing model weights through fine-tuning. The retrieval system still needs to be built and maintained.

How many documents should a RAG system retrieve?
There is no universal number. It depends on passage size, task complexity, search quality, and the model’s input budget. Evaluate different settings using questions with known evidence and answers.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →