Measuring LLM quality: evals and RAG, part 4 of 4
Agentic RAG vs RAG: When Letting the Model Search Pays Off
Plain RAG searches once; agentic RAG lets the model search again. When the loop earns its tokens, what it costs, and how to cap and measure it.
After this video
You can decide, per question type, whether one retrieval step is enough or a search loop is worth its cost, and cap and measure the loop.
The short version
Plain RAG searches your docs once and the model answers from what it got: cheap and predictable, but blind to questions whose answer spans pages that depend on each other. Agentic RAG turns search into a tool the model calls, reads and calls again. Every lap is another full model call that resends the conversation, so tokens and latency climb fast. Route easy questions to plain RAG, cap the loop, and measure both designs on real questions before you choose.
Plain RAG
Docs are cut into chunks and embedded. At question time your code finds the chunks closest in meaning and pastes the top few into the prompt. One search, one model call; the model never decides to search.
Return window. "How long is your return window?" lives on one page, so one search is enough.
Multi-hop questions
Some answers need several documents, and the next search depends on what the first one found. One round of retrieve-and-read can't write that second query in advance.
Refund approver. The policy says refunds over $500 need the store manager; only then can you search for which manager.
The agentic loop
Search becomes a tool. The model writes a query, the API hands your code the call, your code runs the search and sends results back, and the model decides again: answer or search.
Sale blender. Search one finds the 30-day policy and a line about sale items; search two, written by the model, finds 'final sale'.
What the loop costs
The API is stateless, so every lap resends the whole conversation including earlier results. Input tokens grow each call, and each call adds latency.
Token math. Plain RAG: one call, 3,000 input tokens with its chunks. An agent whose first call is 1,500 tokens, each search adding 1,500: 1,500 + 3,000 + 4,500 + 6,000 = 15,000 over four calls, 5x.
Routing and stop rules
Send easy questions down the cheap path and hard ones into the loop. Cap the steps, stop when results repeat, hand off honestly at the cap, and log every query the model writes.
Measure both
Run both designs on about 30 real questions with known answers and count correct answers, input tokens and seconds per answer, split by question type.
The code
const messages = [{ role: "user", content: question }];
for (let call = 0; call < 5; call++) {
const res = await ai.messages.create({ model, max_tokens: 1024, messages, tools: [searchTool] });
if (res.stop_reason !== "tool_use") return textOf(res);
const uses = res.content.filter((b) => b.type === "tool_use");
const results = await Promise.all(uses.map(async (u) => ({
type: "tool_result", tool_use_id: u.id, content: await search(u.input.query),
})));
messages.push({ role: "assistant", content: res.content }, { role: "user", content: results });
}
return "I couldn't find that. Passing you to a human.";Check yourself
What is the one thing that changes between plain RAG and agentic RAG?
Who decides when to search: in plain RAG your code searches once before the model sees anything; in agentic RAG the model calls search itself, as often as it decides.
Why does a four-call agent cost far more than one plain RAG call, even though each search is cheap?
Each call is a full model call and the API is stateless, so every call resends the whole conversation, including earlier search results; input tokens grow each lap (3,000 vs 15,000 in the example).
Which question should go into the loop: 'how long is your return window?' or 'can I return the blender I bought in the sale?', and why?
The sale blender: its answer spans two pages that depend on each other (return policy, then sale terms), while the return window lives on one page.
Sources
Every claim in this video was checked against these pages. Open one to see the claims it backs and the exact words they rest on.
anthropic.com/…/contextual-retrieval
- Plain RAG splits docs into chunks, embeds them, and at question time finds the chunks closest in meaning to the question.
at runtime, when a user inputs a query to the model, the vector database is used to find the most relevant chunks based on semantic similarity to the query.
- The most relevant chunks are added to the prompt and the model answers from them.
then, the most relevant chunks are added to the prompt sent to the generative model.
- Plain RAG splits docs into chunks, embeds them, and at question time finds the chunks closest in meaning to the question.
anthropic.com/…/multi-agent-research-system
- Traditional RAG uses static retrieval: it fetches the chunks most similar to the input query once and generates from them; the model does not decide when to search.
traditional approaches using retrieval augmented generation (rag) use static retrieval. that is, they fetch some set of chunks that are most similar to an input query and use these chunks to generate a response.
- An agentic search loop does multi-step search that adapts to new findings.
our architecture uses a multi-step search that dynamically finds relevant information, adapts to new findings
- In Anthropic's data, agents typically use about 4x more tokens than chat interactions.
in our data, agents typically use about 4× more tokens than chat interactions
- Agents struggle to judge how much effort a task needs; explicit rules prevent over-investing in simple queries.
agents struggle to judge appropriate effort for different tasks, so we embedded scaling rules in the prompts.
- Early research agents spawned 50 subagents for simple queries and searched endlessly for nonexistent sources.
early agents made errors like spawning 50 subagents for simple queries, scouring the web endlessly for nonexistent sources
- Traditional RAG uses static retrieval: it fetches the chunks most similar to the input query once and generates from them; the model does not decide when to search.
arxiv.org/…/2212.10509
- One-step retrieve-and-read is insufficient for multi-step questions, because what to retrieve next depends on what was already found.
this one-step retrieve-and-read approach is insufficient for multi-step qa
- One-step retrieve-and-read is insufficient for multi-step questions, because what to retrieve next depends on what was already found.
arxiv.org/…/1809.09600
- Multi-hop questions require finding and reasoning over several supporting documents.
the questions require finding and reasoning over multiple supporting documents to answer
- Multi-hop questions require finding and reasoning over several supporting documents.
arxiv.org/…/2310.11511
- Retrieving a fixed number of passages whether or not they are relevant can lead to unhelpful answers.
indiscriminately retrieving and incorporating a fixed number of retrieved passages, regardless of whether retrieval is necessary, or passages are relevant, diminishes lm versatility or can lead to unhelpful response generation
- Retrieving a fixed number of passages whether or not they are relevant can lead to unhelpful answers.
anthropic.com/…/building-effective-agents
- With retrieval as a tool, current models generate their own search queries and decide which tools to use.
our current models can actively use these capabilities—generating their own search queries, selecting appropriate tools
- An agent is typically a model using tools based on feedback in a loop.
they are typically just llms using tools based on environmental feedback in a loop.
- Agentic systems trade latency and cost for better task performance.
agentic systems often trade latency and cost for better task performance, and you should consider when this tradeoff makes sense.
- Start with the simplest solution and only add complexity when needed.
we recommend finding the simplest solution possible, and only increasing complexity when needed.
- Agents fit open-ended problems where the number of steps can't be predicted.
agents can be used for open-ended problems where it's difficult or impossible to predict the required number of steps
- Stopping conditions such as a maximum number of iterations are a common way to keep an agent loop under control.
it's also common to include stopping conditions (such as a maximum number of iterations) to maintain control.
- With retrieval as a tool, current models generate their own search queries and decide which tools to use.
docs.claude.com/…/overview
- With a client tool, the API stops with a tool_use block; your code runs the operation and sends back a tool_result.
claude responds with stop_reason: "tool_use" and one or more tool_use blocks. your code runs the operation and sends back a tool_result
- With a client tool, the API stops with a tool_use block; your code runs the operation and sends back a tool_result.
docs.claude.com/…/working-with-messages
- The Messages API is stateless: every call sends the full conversation history.
the messages api is stateless, which means that you always send the full conversational history to the api.
- The Messages API is stateless: every call sends the full conversation history.
docs.claude.com/…/pricing
- Tool use requests are billed on the total input tokens sent on each request.
tool use requests are priced based on: the total number of input tokens sent to the model
- Prompt caching bills repeated prefix tokens at a fraction of the base input price (0.1x on most models).
cache read (hit) 0.1x base input price
- Tool use requests are billed on the total input tokens sent on each request.
arxiv.org/…/2403.14403
- Adaptive-RAG picks a retrieval strategy, from simplest to most sophisticated, per question using a small classifier that predicts query complexity.
dynamically select the most suitable strategy for (retrieval-augmented) llms from the simplest to the most sophisticated ones based on the query complexity
- One fixed strategy either spends unnecessary compute on simple questions or fails complex multi-step ones.
they either handle simple queries with unnecessary computational overhead or fail to adequately address complex multi-step queries
- Adaptive-RAG picks a retrieval strategy, from simplest to most sophisticated, per question using a small classifier that predicts query complexity.
arxiv.org/…/2210.03629
- ReAct interleaves reasoning with actions that gather information from external sources.
generate both reasoning traces and task-specific actions in an interleaved manner
- ReAct interleaves reasoning with actions that gather information from external sources.
Spotted a mistake? Say so in the video's comments. Fixes are listed on corrections.