RAG vs Context engineering
46 sourced facts · updatedRAG vs context engineering: what is the difference?
RAG fetches relevant pieces of a document set at question time and puts them in front of the model. DeLucia says context engineering is choosing strategically what the model sees. Monigatti's hot take is that context engineering is about 80% agentic search, so retrieval sits inside context work. [1][2][3]
In the knowledge graph: The card catalog is retrieval run as an agent loop: search, read, search again.
The difference between RAG and Context engineering
| RAG | Context engineering | |
|---|---|---|
| What it is | A pipeline: the query is optionally rewritten and embedded, vector and keyword search run in parallel, the lists are fused and optionally reranked, and the top chunks are returned or passed to a generation model. [1] | Choosing strategically what the model sees, not just staying under the token limit or shoving in as much as fits. [2] |
| How much goes in | A short list. One rulebook assistant fetched the top 50 from each search, kept 30 after fusion and gave 10 to the agent. In another team's view, too many results confuse the user and scatter the information. [4][5] | Less than it first seems. Sakthivel reports a coding query sending 45,000 tokens of context when only about 5,000 mattered. Werry says you cannot slam all architecture docs into the window even at a million tokens, because the agent gets distracted and wastes tokens. [6][7] |
| How the search works | Hybrid. Dense search is good for meaning but exact identifiers look like noise to an embedding, while BM25 is the mirror image. Hybrid search lifted the hit rate from 92% to 97% over dense only on 63 retrieval questions, as the builders report. [8][9] | Contested. Bergum says BM25 plus grep is a strong agent primitive. Vaid found dense retrieval found buried facts about 80% of the time from 50K to 200K tokens but 0% at 400K, while BM25 still found them every time, and the tutor uses hybrid search. [10][11] |
| How it goes wrong | The wrong source or the wrong number. Attaching sources after the fact does not help when retrieval pulled the wrong source, or the right source and the wrong number, such as a 17 that may be millions, billions or yen. An index may also find the right document but cannot open it. [12][13] | Finding is not understanding. Waselnuk warns that agents using MCP or a wiki stop at the first plausible source and never see a newer Slack thread that says the opposite. An index holding old and new versions of a document tends to return the old one. [14][15] |
| How agents change it | The old pattern was one retrieval call up front; the new one is an agent firing many parallel queries, so search becomes a highly concurrent tool call. In one builder's system most questions needed 2 to 4 search calls, and the median answer took 38 seconds. [16][17][18] | Bergum argues for an agentic-search workspace organized as a filesystem, which gives progressive disclosure: show title and snippet, then let the model read more with grep, sed and similar tools. Monigatti shows an agent with a grep shell tool chaining synonyms to approximate semantic search. [19][20] |
| How it is measured | Measure the retriever on its own, so a retrieval problem is not mistaken for a generation problem. Mistral says most teams tweak prompts, chunking and models without knowing whether the retriever surfaced the right context in the first place. [21] | Bergum says single-query ranked-list metrics matter less for agents, which reformulate queries, so evaluate whether the agent completes the task. Voss says the hard part is now verifying the model followed its instructions, and the answer is an eval on the output each time. [22][23] |
| Where the cost goes | Parsing and embedding a codebase is a one-time cost, as an embedding is cached compute. In NVIDIA's RAG Blueprint the LLM is the largest contributor to latency, followed by the reranker. [24][25] | For coding agents, mostly input tokens. Sakthivel says about 90% of AI coding cost is input tokens, so cutting output by 75% saves only about 8% while cutting input by 94% saves about 61%. [26][27] |
When to use RAG
- Work on RAG when answers have to be checkable: under each answer the assistant can list the rulebook and section it used so the user can open it, and a post-processing filter refuses citations that cannot be verified. [28][29]
- Work on RAG when the right chunks are not being found: a first indexer took plain text from PDFs, tables came out misaligned and the agent could fetch the wrong row, so the team turned each table into CSV with repeated fields and never split a table across chunks. [30][31]
- Work on RAG when exact figures matter: numbers are stored with value, unit, scale and period in a registry, and the model must cite those facts rather than write numbers. [32][12]
When to use Context engineering
- Work on context when tools fill the window: a naive MCP client with about a hundred tools lost roughly a third of context before the first question, and Arize reports 43% fewer tokens and 31% lower cost after moving to code mode. [33][34]
- Work on context when long sessions have to carry on: Prabaker says compaction does not equal coherence because lossy summaries drift, and DeLucia built long-session evals that load ten turns and test the eleventh. [35][36]
- Work on context when facts change: Liberty says that when the CEO changes, that fact must override thousands of older documents that any RAG search would still return, so a knowledge layer must stay current. [37][38]
Using RAG and Context engineering together
The sources describe agents that sit on an index instead of replacing it. Mistral's agent builds on an existing search index and adds tools to open, navigate, read and grep the documents the index finds, which targets the limit Mistral names: an index may find the right document but cannot open it. Mistral, the vendor, reports correctness rising from 26.7% to 86% on FinanceBench and from 6.3% to 51.9% on OfficeQA Pro against one-shot retrieval. Monigatti recommends specialized tools for common lookups plus a general query or shell tool for unexpected questions. [39][13][40][41]
Does an agent that greps files replace the ranked index?
The sources disagree. On about 20 bug tasks agentic search matched vector search in accuracy at a quarter of the cost, because lone chunks lacked the surrounding logic. But BM25 overtakes a file-system agent around 10 million tokens, and Mistral's agent builds on an existing search index rather than replacing it. Latent Space says RAG is not dead: coding companies still rely heavily on search. [42][43][39][44]
Where should company knowledge live: queried live or in a persistent separate layer?
The sources split. Feig prefers live API calls for simple lookups because they are cheaper, and syncing a cache only for deep, cross-record questions. Liberty wants a separate persistent, specialized layer that is kept current and overrides stale documents. [45][46]