Frontier Foundry

RAG vs Context engineering

46 sourced facts · updated

RAG 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

RAGContext engineering
What it isA 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 inA 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 worksHybrid. 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 wrongThe 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 itThe 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 measuredMeasure 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 goesParsing 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]

Each one on its own

from their concept pages

What is RAG?

Retrieval-augmented generation looks up relevant documents when a question arrives and places them in the prompt. The model then answers from that text and not from memory alone. It gives a model current and private facts without retraining, and the answer is only as good as what was fetched.

Retrieval-augmented generation fetches relevant pieces of a document set at question time and puts them in front of the model. The sources describe a pipeline: documents are cut into chunks and filed by meaning and by exact words; a question fetches a short list, merged and reranked; the model answers from it and a check can refuse figures it cannot trace. Its limits are a short desk, a chunk size no one gets right for every query, and answers that can come from the wrong page.

about 2,000 characters
Size a chunk is packed to before it is cut, in one rulebook assistant (reported by the builders) Nina Žižakić
top 50 + top 50 to 30 to 10
Candidates per list, kept after fusion, and given to the agent (reported by the builders) Eleonora Drykina
2 to 4 calls
Search calls most questions need; the prompt asks the agent to reconsider before the sixth (reported by the builders) Eleonora Drykina

RAG, explained in full: how it works as a machine, every part and its sources.

What is Context engineering?

Context engineering is deciding what goes into a model's limited window on each turn: which instructions, files, tool results and memories, and in what form. With too little the model lacks what it needs; with too much it loses the thread and costs more. Long tasks depend on what is kept, fetched and trimmed.

Context engineering is deciding what goes into the model's window each turn (instructions, tools, retrieved facts, history) and what stays outside. These talks describe the same pressures: windows rot as they fill, tool definitions and tool results are the fastest way to fill them, and long runs force compaction or external logs. The answers are on-demand loading, sub-agent isolation, small durable memory, a stable cacheable prefix, and evals to prove the changes work.

~350K tokens
Where Bergum puts the usable context for current models before quality degrades (his opinion), compared to a 1.4 MB floppy disk Jo Kristian Bergum
7 and 12 hours
Codex runs OpenAI's team cites as spanning many compactions in one thread Gabriel Chua
43% fewer tokens, 31% lower cost
Arize reports after moving its agent to code mode, with latency about constant Mikyo King

Context engineering, explained in full: how it works as a machine, every part and its sources.

In AI coverage over the last four weeks, RAG took 0.81% and Context engineering 1.00%. RAG, week by week

The facts behind this page

46 facts from the two knowledge packs
  1. In a managed RAG 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 either returned or passed to a generation model. Cloudflare blog · 2026-10-01 · RAG
  2. DeLucia says context engineering is choosing strategically what the model sees, not just staying under the token limit or shoving in as much as fits. Sally-Ann DeLucia, AI Engineer · 2026-04-08 · Context engineering
  3. Monigatti's hot take is that context engineering is about 80% agentic search. Leonie Monigatti, AI Engineer · 2026-04-08 · Context engineering
  4. top 50 + top 50 to 30 to 10: Candidates per list, kept after fusion, and given to the agent (reported by the builders) Eleonora Drykina, AI Engineer · 2026-10-12 · RAG
  5. How many results to fetch depends on the use case: more for products, fewer for medical answers, since too many answers confuse the user and scatter the information. Abed Matini, AI Engineer · 2026-06-29 · RAG
  6. 45,000 -> ~5,000 tokens: Context sent per coding query vs. tokens that actually mattered in Sakthivel's measurement (reported) Rajkumar Sakthivel, AI Engineer · 2026-06-29 · Context engineering
  7. Werry says you cannot slam all architecture docs into the window, even at a million tokens, because the agent gets distracted and wastes tokens. Peter Werry, AI Engineer · 2026-07-01 · Context engineering
  8. Dense search is good for meaning, but rulebook codes, message names and exact identifiers look like noise to an embedding; BM25 is the mirror image: exact tokens work, paraphrases do not. Eleonora Drykina, AI Engineer · 2026-10-12 · RAG
  9. 92% to 97%: Hit rate of hybrid search over dense only on 63 retrieval questions (reported by the builders) Eleonora Drykina, AI Engineer · 2026-10-12 · RAG
  10. Bergum says BM25 suits agent users: they write long precise queries, exact matching on names and SKUs matters, it is cheap, and the model can see why a query matched. Jo Kristian Bergum, AI Engineer · 2026-06-30 · Context engineering
  11. Vaid found dense retrieval found buried facts about 80% of the time from 50K to 200K tokens, but 0% at 400K, whereas BM25 still found them every time; the tutor uses hybrid search. Samridhi Vaid, AI Engineer · 2026-06-29 · Context engineering
  12. The wrong source, the wrong number. Attaching sources after the fact does not help when retrieval pulled the wrong source (a blog with a wild price), or the right source and the wrong number: a 17 in a filing may be millions, billions or yen, or an earlier year. Vinoo Ganesh, AI Engineer · 2026-10-25 · RAG
  13. The limit of one-shot chunk retrieval: an index may find the right document but cannot open it, go to the table, read the surrounding context or verify the answer, so the model must answer from whatever the first retrieval selected. Mistral AI · 2026-08-20 · RAG
  14. Satisfaction of search. Agents using MCP or a wiki stop at the first plausible source, such as an architecture record, and never see last night's Slack thread that says to do the opposite. Brandon Waselnuk, AI Engineer · 2026-09-09 · Context engineering
  15. A retrieval index holding both an old and a new version of a document tends to return the old one, since older documents are longer and more detailed; LangChain advises returning the date in the text and having the subagent flag outdated results. LangChain blog · 2026-10-23 · Context engineering
  16. Agents change the load on the search desk: the old pattern was one retrieval call up front, the new one is an agent firing many parallel queries at once, so search becomes a highly concurrent tool call and query pricing falls. Latent Space · 2026-03-12 · RAG
  17. 2 to 4 calls: Search calls most questions need; the prompt asks the agent to reconsider before the sixth (reported by the builders) Eleonora Drykina, AI Engineer · 2026-10-12 · RAG
  18. 38 seconds: Median time to answer, the cost of letting the agent search more than once (reported by the builders) Eleonora Drykina, AI Engineer · 2026-10-12 · RAG
  19. Bergum argues an agentic-search workspace organized as a filesystem gives progressive disclosure: show title and snippet, then let the model read more with grep, sed and similar tools. Jo Kristian Bergum, AI Engineer · 2026-06-30 · Context engineering
  20. Monigatti shows an agent with a grep shell tool chaining synonyms (compliance, constraints, GDPR, governance) to approximate semantic search. Leonie Monigatti, AI Engineer · 2026-04-08 · Context engineering
  21. To tell a retrieval problem from a generation problem, measure the retriever on its own: most teams tweak prompts, chunking and models without knowing whether the retriever surfaced the right context in the first place. Mistral AI · 2026-05-28 · RAG
  22. Bergum says single-query ranked-list metrics matter less for agents, which reformulate queries, so evaluate whether the agent completes the task. Jo Kristian Bergum, AI Engineer · 2026-06-30 · Context engineering
  23. Voss says the old hard part was fitting instructions in; now it is verifying the model followed them, and the answer is checking the output with an eval each time. Laurie Voss, AI Engineer · 2026-09-09 · Context engineering
  24. An embedding is cached compute: parsing and embedding a codebase is a one-time cost, and at run time the agent queries it and saves tokens, time and money. AI Engineer · 2026-04-10 · RAG
  25. In NVIDIA's RAG Blueprint the LLM is the largest contributor to latency, followed by the reranker; the team scales the LLM service on time to first token (p90 above 2 seconds) and the reranker when its GPU use passes 75%. NVIDIA · 2025-12-12 · RAG
  26. Sakthivel says about 90% of AI coding cost is input tokens and 10% output, so cutting output by 75% saves only about 8% while cutting input by 94% saves about 61%. Rajkumar Sakthivel, AI Engineer · 2026-06-29 · Context engineering
  27. 90% input / 10% output: Sakthivel's split of AI coding cost, which is why he cuts input first (reported) Rajkumar Sakthivel, AI Engineer · 2026-06-29 · Context engineering
  28. Under each answer the assistant lists the sources it used, naming rulebook and section, so that the user can open the rulebook. Nina Žižakić, AI Engineer · 2026-10-12 · RAG
  29. A post-processing filter refuses citations that cannot be verified, so a number that is not cited cannot appear in the output. Vinoo Ganesh, AI Engineer · 2026-10-25 · RAG
  30. The table that lost its rows. The first indexer took plain text from the PDF, which did not keep tables whole: a field spanning several rows came out misaligned, so the agent could fetch the wrong row or column, and fees are in tables. Nina Žižakić, AI Engineer · 2026-10-12 · RAG
  31. The indexing job packs paragraphs into chunks of about 2,000 characters and never splits a table across two chunks; section headers are found with regular expressions. Nina Žižakić, AI Engineer · 2026-10-12 · RAG
  32. Numbers are stored with value, unit, scale and period, in a registry, and the model must cite those facts rather than write numbers. Vinoo Ganesh, AI Engineer · 2026-10-25 · RAG
  33. Curn says naive MCP clients register every tool up front, so ten servers meant about a hundred tools and roughly a third of context gone before the first question; he calls it a harness problem, not a protocol problem. Jan Curn, AI Engineer · 2026-10-02 · Context engineering
  34. 43% fewer tokens, 31% lower cost: Arize reports after moving its agent to code mode, with latency about constant Mikyo King, AI Engineer · 2026-10-27 · Context engineering
  35. Prabaker's takeaways: compaction does not equal coherence, since lossy summaries drift, and structured handoffs with clean context work better. Ash Prabaker, AI Engineer · 2026-04-08 · Context engineering
  36. DeLucia built long-session evals: load ten turns, then test the eleventh, turning late-session forgetting into a repeatable bug. Sally-Ann DeLucia, AI Engineer · 2026-04-08 · Context engineering
  37. Liberty says a knowledge layer must stay current: when the CEO changes, that fact must override thousands of older documents that any RAG search would still return. Edo Liberty, AI Engineer · 2026-06-30 · Context engineering
  38. Liberty says agents start most tasks from scratch like a new hire on day one, so they need a persistent, specialized knowledge layer rather than smarter models or more tools. Edo Liberty, AI Engineer · 2026-06-30 · Context engineering
  39. Does an agent that greps files replace the ranked index? Agentic search does not replace the index but sits on it: Mistral's agent builds on an existing search index and adds tools to open, navigate, read and grep the documents the index finds. Mistral AI · 2026-08-20 · RAG
  40. 26.7% to 86% (FinanceBench); 6.3% to 51.9% (OfficeQA Pro): Correctness of one-shot retrieval versus Mistral's multi-step agentic search on financial filings and on table-heavy multi-document questions; p90 latency down by up to 39.6% and tokens by up to a third; reported by the vendor Mistral AI · 2026-08-20 · RAG
  41. Monigatti recommends a balance: specialized tools for common lookups (low floor) plus a general query or shell tool for unexpected questions (high ceiling), then log what breaks and add purpose-built tools. Leonie Monigatti, AI Engineer · 2026-04-08 · Context engineering
  42. Does an agent that greps files replace the ranked index? 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. Jess Wang, AI Engineer · 2026-10-05 · RAG
  43. Does an agent that greps files replace the ranked index? At scale ranking wins: BM25 overtakes a file-system agent around 10 million tokens, and agentic reasoning works best after ranked discovery, not in place of it. Hugging Face · 2026-07-31 · RAG
  44. Does an agent that greps files replace the ranked index? RAG is not dead: coding companies still rely heavily on search, and hybrid retrieval (semantic, text, regex, SQL-style patterns) is becoming more important, not less. Latent Space · 2026-03-12 · RAG
  45. Where should company knowledge live: queried live or in a persistent separate layer? Prefer live API calls for simple lookups (cheaper); sync a cache only for deep, cross-record questions Gil Feig, AI Engineer · 2026-07-01 · Context engineering
  46. Where should company knowledge live: queried live or in a persistent separate layer? Keep a separate persistent, specialized layer that is kept current and overrides stale documents Edo Liberty, AI Engineer · 2026-06-30 · Context engineering

Cite this page

the version of 2026-12-02
APA
Han, R. (2026, December 2). RAG vs Context engineering: what is the difference?. Frontier Foundry. https://www.ryanhan.ai/compare/rag-vs-context-engineering
BibTeX
@misc{han2026-compare-rag-vs-context-engineering,
  author       = {Han, Ryan},
  title        = {{RAG vs Context engineering: what is the difference?}},
  howpublished = {Frontier Foundry},
  year         = {2026},
  month        = dec,
  url          = {https://www.ryanhan.ai/compare/rag-vs-context-engineering}
}

More comparisons

all of them