Context Engineering vs RAG: When to Use Which Approach
RAG retrieves similar documents. Context engineering decides what an agent should know before it acts. Here is when each approach fits, when they overlap, and how to choose.

In brief:
• Context engineering decides what reaches the model: which sources, in what order, under which permissions, and which version wins. RAG fetches documents by similarity and is one step inside it.
• Unblocked does context engineering for engineering teams. It reasons across code, PRs, issues, docs and chat, and hands agents one cited answer over MCP.
• RAG alone is enough for one clean, read-only corpus that everyone may see.
• Once agents write code from several systems that disagree, you need the layers above retrieval: conflict resolution, permissions, freshness and synthesis.
Context engineering is the practice of deciding what an AI agent sees before it acts: which sources, in what order, under whose permissions, and which version wins when two of them disagree. Unblocked is a worked example of context engineering for engineering teams. It reasons across code, pull requests, issues, docs, Slack or Teams threads and incidents. Its MCP server then returns one synthesized answer with citations to Claude Code, Cursor, GitHub Copilot, Codex or Windsurf. Retrieval-augmented generation (RAG) is a narrower technique inside that practice: fetch the documents that look most similar to the question and put them in the prompt. RAG is a tool, and context engineering is the job the tool serves. Treating them as the same thing costs teams months of pipeline work on the wrong problem.
For background on context engineering as a discipline, see the context engineering guide.
What problem does RAG actually solve?#
RAG solves the knowledge cutoff problem. Anthropic's Claude documentation describes the context window as the model's working memory, separate from the data it was trained on (Claude docs). When a model needs facts it wasn't trained on, RAG provides them by fetching similar documents at query time.
The mechanism is straightforward. Chunk your documents, embed them as vectors, store them in a database, and at query time embed the question and pull the top-k most similar chunks. The model then generates with those chunks in its context window. OpenAI's Retrieval API documents a default version of this: files are split into 800-token chunks with 400-token overlap, then embedded and indexed in a vector store (OpenAI). For single-source question answering, like a support bot over product docs, this works well. In Stack Overflow's 2026 Developer Survey, 73% of respondents who use AI coding assistants or agents use them daily (Stack Overflow, 2026). Many of those tools use some form of retrieval under the hood.
RAG retrieves documents by vector similarity to ground LLM outputs in external data. It ranks by apparent relevance and has no notion of what is current, what is authoritative, or who may see it.
"When to use RAG" has a clean answer: use it when you have one authoritative corpus, questions shaped like "find the relevant passage," and no permission complexity. A product manual. A contained knowledge base. A FAQ chatbot. RAG is excellent in that lane.
The trouble starts when teams try to stretch RAG beyond that lane. Most engineering teams hit that wall fast.
For more detail on where RAG fits in a broader architecture, see our post on context engines vs RAG.
What problem does context engineering solve that RAG doesn't?#
Context engineering solves the "right information, right shape, right time" problem that RAG leaves open. Stanford HAI's 2026 AI Index reports that AI agents climbed from 12% to about 66% task success on the OSWorld computer-use benchmark. The same report says agents still fail roughly one in three attempts on structured benchmarks (Stanford HAI AI Index, 2026). Multi-step work is where agents still slip, and multi-step work is what coding agents do.
RAG asks: "Which documents look similar to this query?" Context engineering asks a harder set of questions. Which sources are authoritative? Which document wins when two disagree? Who is allowed to see this information? Is this still current, or was it superseded last month? And what does the combination of these sources mean for the specific task the agent is performing?
The common failure pattern looks like this. The agent retrieves the right chunks. It just picks the wrong one because nothing told it which source was authoritative, which was stale, or which the team had already rejected. Retrieval did its job. Nothing above it reasoned about which chunk to trust.
Context engineering closes the gap between document retrieval and actionable knowledge: it takes the candidates that retrieval finds and decides which of them the agent should act on.
Context engineering covers five operations that RAG doesn't touch: source curation (deciding what counts), conflict resolution (deciding what wins), permission enforcement (deciding who sees what), freshness management (deciding what's current), and synthesis (deciding what the combination means). Skip any one of those and you get an agent that retrieves fluently and acts incorrectly.
| Question | RAG | Context engineering |
|---|---|---|
| What does it decide? | Which chunks look most similar to the query | What the agent should see before it acts |
| What happens when sources disagree? | Returns both, ranked by similarity | Picks the authoritative source and says why |
| Who may see the result? | Whoever queries the index | Filtered by the asker's permissions before the prompt |
| Is the material current? | No built-in notion of freshness | Stale or superseded material is ranked down |
| What reaches the model? | A list of chunks | One task-shaped input built from what survived |
What does this look like concretely? Consider, for example, a coding agent asked to implement a retry mechanism. RAG retrieves three documents: a Notion spec from 2023, a Slack thread from last quarter where the team rejected that approach, and the current implementation in the repo. RAG returns all three ranked by similarity. A context engineering approach would resolve the conflict, surface the rejection rationale, and deliver only the current implementation plus the reason the old approach was killed.
For definitions and deeper detail, see our post on what context engineering is.
When is RAG enough for your team?#
RAG is enough when the model's only problem is that it doesn't know about your docs. Once it knows plenty and keeps picking the wrong source, you need more. GitHub's 2026 Octoverse report found that by September 2026 more than 40% of pull requests on GitHub started with an agent's first draft, up from 17% in March (GitHub Octoverse, 2026). Not every one of those agents needs more than basic retrieval. The test below tells you whether yours does.
Here's a practical test. If your team can answer "yes" to all four of these questions, RAG is likely sufficient:
Single authoritative source#
You have one corpus that doesn't contradict itself. Product documentation, a style guide, a well-maintained wiki. No conflicting versions. No outdated drafts floating alongside current specs.
Read-only outputs#
The agent answers questions. It doesn't write code, open PRs, or take actions. The worst case for a wrong answer is a confused user.
No permission complexity#
Everyone who queries the system is allowed to see everything the system retrieves. No contractor boundaries, no team-level access controls, no compliance constraints.
Low conflict frequency#
Sources rarely disagree. When they do, the disagreement is obvious and the user can resolve it manually. The agent doesn't need to arbitrate.
Most teams overestimate how long they'll stay in this lane. A single-source FAQ bot is RAG-shaped. But the moment you connect a second system, like Slack alongside your docs, you've introduced conflict potential. And the moment the agent writes code instead of answering questions, the cost of a wrong retrieval jumps by an order of magnitude.
When should you invest in context engineering instead?#
Teams should invest in the context engineering approach when agents act on retrieved information, not just display it. Once an agent turns retrieved text into a diff, a wrong source becomes a wrong change. DORA's 2026 report on the ROI of AI-assisted software development puts it plainly: "AI agents are only as effective as the data they can access" (DORA, 2026). The report adds that when internal knowledge is fragmented or outdated, AI generates duplicated or irrelevant code.
Four signals tell you RAG alone won't cut it.
Your agents write code#
When the output is a diff, the stakes change. A hallucinated function reference compiles, passes lint, and breaks at runtime or in review. Coding agents do best on well-defined tasks, and most real tasks aren't well-defined until someone supplies the institutional context.
Your knowledge lives in more than one system#
Code is in GitHub. Decisions are in Slack. Specs are in Notion. Incidents are in PagerDuty. RAG can index all of those, but it can't reconcile them. When the Notion spec says "use library X" and the Slack thread says "we killed library X last sprint," RAG returns both. An agent needs to know which one wins.
You have permission boundaries#
Contractors shouldn't see executive strategy docs. Junior engineers shouldn't see compensation data in HR tickets. RAG retrieves by similarity and knows nothing about authorization. A context engineering approach enforces permissions before context hits the prompt, so the agent never sees what the asker can't.
Your agents keep failing review#
This is the clearest signal. If AI-generated PRs keep getting bounced for "you should have known about X," the problem usually sits in what the model was allowed to see. The context engineering approach treats review feedback as a signal that improves future retrieval.
When review keeps catching the same missing knowledge, the fix sits upstream, in what the agent was shown. Context engineering is the quality process for that input.
For more on this concept, see decision-grade context.
Can you use RAG inside a context engineering strategy?#
Yes, and most mature implementations do. Anthropic's Claude documentation warns that more context isn't automatically better. As token count grows, accuracy and recall degrade. Context rot is the docs' name for that decline, and it makes curating what's in context as important as window size (Claude docs). RAG is usually the first step.
Think of it as layers. RAG handles the initial fetch: embed the query, pull similar chunks, return candidates. Context engineering handles everything after that. Conflict resolution filters contradictory sources. Permission enforcement strips unauthorized content. Freshness ranking deprioritizes stale material. Synthesis combines surviving context into a task-shaped input.
Gustavo Alvarez, a software engineer at Sixfold, described the layered approach in practice.
My biggest use of Unblocked MCP has been AI governance — searching across Slack, fourteen Notion docs, S3, trying to understand where data lives and where the gaps are. There is no other way to humanly accomplish this task. It's an absolute godsend for getting context out of sources that don't talk to each other.
Gustavo Alvarez — Software Engineer, Sixfold
That's retrieval from multiple systems, governed by a context layer that decides what reaches the agent and in what shape. The retrieval step uses similarity search. Everything after it is context engineering. MCP, an open-source standard for connecting AI applications to external systems, is how that layer reaches the agent. GitHub Copilot Chat is one host that connects to MCP servers to share context from other applications.
In practice, RAG usually serves as the internal retrieval step, with selection, conflict resolution, and synthesis happening above the retrieval layer.
A practical layering model#
The simplest way to think about context engineering vs RAG is as concentric circles, from the inside out:
- RAG is the inner circle: fetch candidates by similarity.
- Conflict resolution sits around it: when two sources disagree, pick the authoritative one.
- Permission enforcement comes next: filter by who's asking.
- Synthesis is the outer ring: combine what survived into a coherent input the agent can act on.
RAG stays in place, and the other layers sit on top of it.
Developers ask for the same thing. Stack Overflow's 2026 survey write-up says that trusting what AI gives you requires source attribution, at 93% (Stack Overflow, 2026). Retrieval hands back sources, and the context layer decides which of them the answer should rest on and cite.
Is it worth building all those layers yourself? That depends on your team's maturity and the complexity of your knowledge landscape. The layers exist whether you build them or not. The question is whether you handle them deliberately or let the agent guess.
For a deeper look at how these layers work inside a context engine, read our explainer on what a context engine is.
Frequently asked questions#
Is context engineering just RAG with extra steps?#
No. RAG is one retrieval technique. Context engineering is a discipline that includes source curation, conflict resolution, permission enforcement, freshness management, and synthesis. The "extra steps" are where the accuracy comes from.
Can a small team benefit from context engineering?#
Yes. Small teams often have less documentation and more tribal knowledge, which makes the gap between "what the code says" and "why the code is that way" even wider. You don't need a platform to start. Curating which sources your agent can see and adding a freshness signal to retrieval results are context engineering moves any team can make today.
Does context engineering replace prompt engineering?#
No. Prompt engineering shapes the instruction. Context engineering shapes the evidence the model sees alongside that instruction. Anthropic's Claude documentation says curating what's in context is just as important as how much space is available (Claude docs). You need both, but context work is the higher-impact investment for coding agents.
What are the biggest RAG limitations for coding agents?#
Four limitations show up repeatedly: stale source confusion (old docs rank higher than current code), permission leakage (unauthorized content retrieved by similarity), conflict blindness (contradictory sources returned without resolution), and reasoning gaps (chunks retrieved but not connected). Stanford HAI's 2026 AI Index found agents still fail roughly one in three attempts on structured benchmarks, and coding tasks are multi-step work (Stanford HAI AI Index, 2026).
For why adding more connectors does not fix these limits, see MCP connectors are not a context engine.
Where to start: the question your agent must answer#
The context engineering vs RAG debate resolves quickly once you flip the framing. Skip the question of whether to use RAG. Ask what your agent needs to know to get this right, and who decides what it sees.
If the answer is "it needs one set of docs and anyone can see them," RAG is the right tool. Ship it, move on. If the answer involves multiple conflicting sources, permission boundaries, stale-vs-current arbitration, or agents that act rather than answer, you need context engineering, and RAG will likely be one component inside it.
With agents now starting more than 40% of GitHub pull requests, the gap between retrieval and decision-grade context will widen. Teams that invest in context engineering now will ship agents that survive review. Teams that stop at RAG will keep bouncing PRs.
Start with the question your agent needs to answer. Work backward to the context it needs. The tool choice follows from there.
For the instruction side of the same question, see context engineering vs prompt engineering.


