Do You Still Need RAG or Agents in the Era of Million-Token Contexts?

    As context windows expand to a million tokens and beyond, it is tempting to assume that retrieval-augmented generation (RAG) is no longer necessary. This article explains why "fitting everything in" is not the same as "using it well," breaking the argument down across four dimensions: cost, latency, output quality, and governance. It also clarifies how long context and RAG solve different problems, why agents actually depend more on retrieval, and how to build a practical hybrid architecture. A selection checklist is included to help you decide when to rely on long context, when to prioritize retrieval, and how to combine both.

    1. The Symptom: Context Windows Are Being Maxed Out

    Over the past year, the industry has seen a clear race to expand context windows. One cloud vendor’s flagship model pushed its window to 1 million tokens, a model behind an AI coding tool set a record with a million-token window combined with trillions of parameters, and another vendor is reportedly testing a 2-million-token context. Looking at the numbers alone, it is easy to reach a tempting conclusion: if you can fit an entire novel, a whole code repository, or a year of logs into a single prompt, shouldn’t retrieval-augmented generation (RAG) be retired?

    The problem with this reasoning is that it mistakes “being able to fit” for “being able to use well.” The context window is a capacity metric, while RAG addresses relevance, cost, freshness, and governability. The two do not compete on the same dimension. The following sections re-examine the question across four layers—mechanism, cost, effectiveness, and engineering governance—and offer a practical framework for making the choice.

    2. First, Clarify the Concepts: What Long Context and RAG Actually Solve

    Long context refers to the maximum number of tokens a model can process in a single inference call. It expands the “input bandwidth.” RAG (retrieval-augmented generation) refers to the paradigm of first retrieving relevant external knowledge snippets, then assembling them into a prompt for the model to generate an answer. It optimizes the “input signal-to-noise ratio.”

    An analogy: long context is like moving an entire library into your office, while RAG is like having a librarian pick out three books based on your question. No matter how large the library is, you still need to turn to the right page at the right moment; and having a librarian means you don’t have to move the whole library for every question.

    It is worth emphasizing that the two are complementary rather than mutually exclusive. The widely accepted view in the industry is that long context lowers the “recall threshold” for RAG (you no longer have to worry about snippets being truncated), but it does not eliminate the need for “precise filtering.”

    3. Four Dimensions: Why “Fitting It In” Does Not Mean “Stuffing It All In”

    3.1 Cost: Token Consumption Is Linear or Even Superlinear

    Inference cost is roughly proportional to the number of input tokens, and attention computation grows superlinearly with sequence length in most implementations. Sending an entire 800,000-token repository into the model versus retrieving 8,000 tokens of relevant snippets can differ in cost by two orders of magnitude. For online services that require high-frequency calls and pay-as-you-go billing, this is a hard bill to balance.

    An illustrative comparison of calling strategies:

    1. # Anti-pattern: stuffing everything in
    2. prompt = repo_all_files + question # input can reach hundreds of thousands of tokens
    3. # Recommended: retrieve first, then generate
    4. hits = retriever.search(question, top_k=8) # keep only highly relevant snippets
    5. prompt = build_prompt(hits) + question # input typically stays within a few thousand tokens

    3.2 Latency: Pressure on Both Time-to-First-Token and Throughput

    Long inputs significantly lengthen the prefill stage, directly driving up time-to-first-token; at the same time, a single request occupies more GPU memory and compute, reducing overall throughput. For interactive applications, the difference between waiting 3 seconds and waiting 30 seconds is decisive for user experience. By shrinking the input size, RAG keeps latency within a predictable range.

    3.3 Effectiveness: “Lost in the Middle” and Noise Interference

    Numerous experiments and public studies point to the same phenomenon: when key information sits in the middle of a very long input, the model’s utilization of it drops noticeably; meanwhile, irrelevant content dilutes attention and increases the probability of hallucinations and off-topic answers. In other words, the longer the window, the more you need to “put the right content in the right position”—and that is precisely the job of retrieval and reranking.

    3.4 Governance: Permissions, Freshness, and Auditability

    The core demands of an enterprise knowledge base are “who can see what” and “changes must take effect immediately.” Full injection means exposing the entire knowledge base to the model and logs at once, making permission boundaries hard to contain; and knowledge updates require re-injecting the full dataset, which is poor in freshness. RAG naturally supports filtering the retrieval scope by user permissions, incrementally updating the index, and preserving an auditable trail of “which snippets an answer cited.”

    4. What About Agents? Agents Need Retrieval Even More

    An agent’s reasoning loop is typically “plan—call tools—observe results—replan,” and the context is quickly inflated by tool return values. Without retrieval and summary compression, the window gets filled with logs and intermediate artifacts after just a few rounds, causing goal drift. Here retrieval plays three roles:

    • Knowledge supply: pulling domain documents and historical tickets as external memory on demand;
    • Context compression: summarizing and chunking lengthy observations, keeping only the information needed for decisions;
    • Memory management: storing long-term memory externally and re-injecting it by relevance, rather than keeping it resident in the window.

    The conclusion, therefore, is that long context lets an agent perform a few fewer retrievals, but it does not make the retrieval mechanism disappear.

    5. A Practical Hybrid Architecture

    A layered design of “retrieval first, long context as fallback” is recommended:

    1. Indexing layer: chunk and vectorize documents, while retaining a keyword index to support exact matching;
    2. Retrieval layer: run vector recall and keyword recall in parallel, then fuse the results and score them with a reranker;
    3. Assembly layer: fill in order of relevance, placing high-confidence snippets first and leaving the remaining budget for long-context fallback;
    4. Generation layer: the model produces an answer based on the assembled prompt and attaches citation sources;
    5. Evaluation layer: continuously regress on four metrics—recall rate, answer faithfulness, time-to-first-token, and cost per call.
    1. User question
    2. │
    3. ├─ Keyword recall ─┐
    4. ├─ Vector recall ─┼─ Fusion → Rerank → Budget trimming → Prompt assembly → Generation → Citation audit
    5. └─ Long-context fallback (enabled only when retrieval confidence is low)

    6. Selection Decision Checklist

    • Does the knowledge update frequently, requiring permission isolation and citation auditing? If so, retrieval is a must;
    • Are calls high-frequency and cost-sensitive? If so, prioritize compressing the input;
    • Is the application highly interactive and sensitive to time-to-first-token? If so, avoid full injection;
    • Does the task only require locating a few facts within a single very long document? Long context can be primary with retrieval as support;
    • Is it a multi-round agent loop? External memory plus retrieval compression is a must.

    From an engineering standpoint, a more robust approach is to combine general-purpose capabilities on demand on platforms such as Baidu AI Cloud—object storage, vector retrieval, message queues, container platforms, and monitoring and alerting—to build an observable, elastically scalable retrieval pipeline, rather than betting everything on the window number.

    7. Conclusion

    Million-token context is important infrastructure: it turns “can it fit” into “is it worth fitting.” For large models and agents, RAG is not a legacy burden but a regulator between cost and effectiveness. A truly mature solution lets long context and retrieval each do their own job: the window handles capacity, retrieval handles relevance, and evaluation provides the safety net.