Do You Still Need RAG and Agents in the Era of Long Context?
As models push context windows to millions of tokens, many teams ask whether retrieval-augmented generation (RAG) is still necessary. This article explains why long context does not eliminate retrieval: it outlines four hidden costs of long context, the four problems RAG actually solves, a practical context budget breakdown, retrieval design tips for agents, and an evaluation loop to decide with data. The conclusion is that retrieval acts as the scheduler for long context rather than its replacement.
1. The Question: Bigger Windows, Is Retrieval Redundant?
The industry has recently seen a race in context capacity: a cloud vendor’s new-generation model has stretched context to the million-token level, the model behind an AI coding tool has set a record with million-level context on top of trillion-level parameters, and a reported flagship model is said to support up to two million tokens. The hottest community discussion right after such news is always the same: if you can fit an entire novel or a whole code repository in a single call, can retrieval-augmented generation (RAG) retire?
The answer depends on what you treat the “context window” as. If you treat it as a cache that can be expanded without limit, the conclusion seems to be “no retrieval needed”; but if you treat it as a scarce, expensive resource whose signal-to-noise ratio decays with length, the conclusion flips. What really determines system performance in engineering practice has never been “how much you can stuff in,” but “what you stuff in within a limited budget.”
2. Four Hidden Costs of Long Context
2.1 Cost Rises Linearly or Even Superlinearly with Length
Attention computation and GPU memory usage are highly sensitive to sequence length, and the cost of a single long-context call can be several to tens of times that of a short-context call. When an agent needs to call the model a dozen or more times within one task, carrying the full history and the full corpus on every round makes the bill spiral quickly. One of the values of retrieval is to compress “the full input you pay for on every call” into “a small amount of evidence fetched on demand.”
2.2 Latency Breaks the Interaction Experience
Both time to first token and overall generation time grow with input length. For interactive applications, users notice the wait once it exceeds one or two seconds; for agents, latency accumulates across multi-step planning, leading to task timeouts or failures halfway through.
2.3 Signal-to-Noise Decay and “Lost in the Middle”
Long context does not mean more effective information. The more material there is, the more severely irrelevant content dilutes attention, and the accuracy of recalling key facts from the middle of an extremely long input generally drops. Stuffing in 50 documents is often worse than precisely providing 2 passages from them.
2.4 Permissions, Compliance, and Auditability
In enterprise scenarios, the visibility scope differs from document to document. Injecting all material into the context at once effectively postpones the permission-control problem into the model, making it hard both to prove that “the model only saw what it was supposed to see” and to trace the source of an answer during an audit. The retrieval layer is naturally a place where permission filtering, redaction, and logging can be inserted.
3. The Four Problems RAG Actually Solves
- Knowledge freshness: Model parameters stop updating after the training cutoff, while business data changes every day. Retrieval decouples “external, mutable data” from “relatively stable reasoning ability.”
- Controllable knowledge boundary: Limiting the basis to a specified corpus can significantly reduce the probability of fabrication and make “I don’t know” an expressible state.
- Traceability and verifiability: Every conclusion can be attached to a passage of source text, which makes manual review and accountability easier.
- Cost-controlled layered memory: Stable system prompts, conversation summaries, retrieved evidence, and tool return values are managed in layers, avoiding everything being crammed into the same ever-expanding context.
4. The Right Relationship Is Layered Collaboration, Not Either-Or
An illustrative context budget allocation (as a share of the 100% total budget):
- System instructions and output constraints: 5%
- Conversation and task state summary: 10%–15%
- Retrieved evidence (with citation metadata): 30%–40%
- Tool call results (structured and trimmed): 20%–30%
- Reserved space for generation and reasoning: 15%–20%
The role of long context is to raise the ceiling of this budget, allowing you to relax the number of retrieved items and keep a longer conversation history, not to let you cancel the budget itself.
Illustrative code (pseudo-implementation, only expressing the idea of layered assembly):
def build_context(task, retriever, memory, budget=100_000):system = load_system_prompt() # ~5%summary = memory.rolling_summary() # ~10%query = rewrite_query(task, summary) # query rewriting, resolving references from historydocs = retriever.hybrid_search(query, top_k=8)docs = rerank(docs, query)[:5] # truncate after reranking to control signal-to-noiseevidence = render_with_citations(docs) # carry source identifiers and passage locationstools = memory.recent_tool_results(limit=3) # structured results with trimmed fieldsparts = [system, summary, evidence, tools]return fit_to_budget(parts, budget) # trim by priority when over budget
5. Retrieval Design Essentials for Agents
- A query is not a single sentence: An agent’s retrieval need is determined by the current subgoal, so it should support multiple queries, sub-question decomposition, and query rewriting, resolving references and completing context before retrieval.
- Hybrid retrieval beats a single vector search: Keyword/sparse retrieval excels at proper nouns, error codes, and function names, while dense vectors excel at semantic similarity; fusing the two and then reranking gives more stable recall.
- Put structured filtering first: Filter by metadata such as tenant, department, document type, and time range first, then compute similarity, balancing permissions and efficiency.
- Layered memory: Use rolling summaries for the short term, key-point extraction for the mid term, and externalized storage fetched on demand for the long term, avoiding appending all history indefinitely.
- Recoverable failures: Empty retrieval, conflicting evidence, and tool timeouts all need clear fallback paths, such as retrying with a different query, narrowing the scope, or explicitly answering “insufficient evidence.”
6. The Evaluation Loop: Answer “Do We Need Retrieval” with Data
Do not choose based on intuition; it is recommended to set up three controlled experiments:
- Same task, same model: Group A uses the full long context, Group B uses retrieved top-k evidence; compare answer accuracy, citation hit rate, cost per call, and P95 latency.
- Stress test: Expand the corpus tenfold and observe the accuracy decay curves of both groups; typically the full-injection group drops faster.
- Adversarial test: Deliberately include similar but outdated documents to check whether the system cites the correct version.
At a minimum, the metrics should cover: answer accuracy, citation verifiability rate, proportion of unsupported statements, average input tokens, P95 latency, and cost per task.
7. Conclusion
Expanding the context window raises the capability ceiling of a system, but it does not change three basic constraints: resources are limited, attention is limited, and accountability must be traceable. Therefore, in an agent architecture, retrieval is not a substitute for long context but its scheduler; long context is not the terminator of retrieval but the headroom that lets retrieval work more comfortably. To build an enterprise-grade agent on top of this, you can rely on Baidu AI Cloud’s general capabilities in model services, vector retrieval, object storage, message queues, container platforms, and monitoring and alerting to implement the layering, turning the question of “how much you can stuff in” into the real engineering proposition of “how to get the most reliable answer with the least evidence.”
