Is RAG Still Necessary with Million-Token Context Windows?
As context windows grow to one million tokens and beyond, many developers wonder whether retrieval-augmented generation (RAG) is obsolete. This article explains why longer windows change the feasible upper limit rather than the optimal engineering solution. It treats context as a budget to allocate across system prompts, tool definitions, history, retrieved passages, and output reserves, and breaks down four overlooked costs of stuffing everything into the window: expense, latency, signal-to-noise ratio, and auditability. It also clarifies how RAG and AI Agents work as layers rather than replacements, outlines a practical layered architecture, and shares engineering tips on hybrid retrieval, chunking, caching, and observability.
1. The Trend: Context Windows Are Being Maxed Out
The industry has recently entered a race over context length. One general-purpose large model has pushed its window to the one-million-token level, a coding and conversational AI platform has combined a million-token window with trillions of parameters to set a new record, and another vendor is reportedly testing two-million-token context. The most common question in developer communities is immediate: if you can fit an entire book or a whole code repository into a single request, should retrieval-augmented generation (RAG) retire?
The answer is no, but the conclusion needs to be stated precisely. A longer window changes the feasible upper limit, not the optimal engineering solution. Context is a scarce resource, and allocating a scarce resource always requires a strategy. RAG remains one of the most mature and measurable allocation strategies available today.
2. Treat Context as a Budget, Not a Container
A more practical mental model is to treat context as a budget rather than a container. The budget for a single request must be divided among the system prompt, tool definitions, conversation history, retrieved passages, the current input, and a reserve for output. Expanding the window from 200K to one million tokens only raises the total; it does not eliminate per-item accounting.
A schematic budget allocation looks like this:
def build_context(req, limit):budget = {"system": 2000,"tools": 3000,"history": int(limit * 0.15),"retrieved": int(limit * 0.35),"current": len(req.input_tokens),"output_reserve": 4000,}budget["retrieved"] = min(budget["retrieved"],limit - sum(budget[k] for k in budget if k != "retrieved"))return budget
The point of this code is not the specific numbers but the constraint: retrieved passages can only take the remaining budget and must never crowd out the output reserve. Without this constraint, a long window actually makes truncation—and the hidden errors that come with it—more likely.
3. Four Overlooked Costs
Cost. Attention computation and GPU memory usage grow quickly with sequence length. Mainstream services generally bill by token, so repeatedly feeding an entire document corpus costs far more than a single retrieval.
Latency. Time to first token is strongly tied to the pre-processing stage. Extremely long inputs push response times for interactive applications into an unacceptable range, and Agents often need multiple loop iterations, which multiplies the latency several times over.
Signal-to-noise ratio. A bigger window does not mean more useful information. Irrelevant passages dilute key evidence and produce the “lost in the middle” phenomenon, where information located in the middle of a long context is more easily ignored, showing up as off-topic answers or misplaced citations.
Auditability. Compliance scenarios require explaining which passages a conclusion came from. A retrieval pipeline naturally produces passages, sources, and scores, whereas reading an entire corpus directly can hardly provide an evidence chain at the same granularity.
4. The Real Relationship Between RAG and Agents: Layering, Not Replacement
A more accurate framing is this: RAG is responsible for “putting the right small amount of information into the budget,” while the Agent is responsible for “deciding what information to fetch next and whether to call a tool.” They sit in an upstream-downstream relationship.
A practical layered structure looks like this:
- Perception layer: query rewriting, intent recognition, and multi-path recall (keyword + vector + structured filtering).
- Decision layer: the Agent decides whether to answer directly, retrieve, or call a computation or query tool.
- Evidence layer: reranking, deduplication, passage compression, and conflict resolution, producing an evidence set with citations.
- Generation layer: organize the answer within the budget and explicitly declare uncertainty when information is insufficient.
The Agent’s loop termination conditions also need engineering constraints, such as a maximum iteration count, an evidence-sufficiency threshold, and a timeout circuit breaker. Otherwise, you get a “spinning” behavior where the Agent repeatedly retrieves without converging.
5. Engineering Best Practices
Hybrid retrieval beats single-path vector retrieval. Keyword recall excels at proper nouns and identifiers, vector recall excels at semantic similarity, and a reranking model then scores everything uniformly. This is usually more stable than any single path.
Chunking must match document structure. Split by heading hierarchy, clauses, or function boundaries, and keep a small amount of overlap to avoid cutting complete semantics in half.
Caching and incremental updates are not optional. When documents change, rebuild only the affected indexes. Keep index and vector data in object storage, metadata in a database, and drive asynchronous rebuilds through a message queue.
Observability must cover retrieval quality. Track recall hit rate, position changes before and after reranking, the token share of passages, citation accuracy, and end-to-end latency to form a loop for continuous optimization.
6. Conclusion
Million-token context is a capability upgrade, not the end of architecture. It makes a hybrid form of “a small amount of precise ranking plus long-document supplementation” more natural: first use retrieval to compress candidates to a manageable scale, then spend the remaining budget on long-document details and multi-round tool calls. On platforms such as Baidu AI Cloud, the combination of general capabilities—object storage, message queues, container platforms, logging services, and monitoring and alerting—is enough to support this layered architecture in practice. What really needs to change is not whether to use RAG, but to treat context as a budget, retrieval as a strategy, and the Agent as the scheduler.
