RAG & VECTOR DATABASES / SYSTEM CONCEPT BRIEF

RAG vs Agentic RAG

Classic RAG is a fixed pipeline.

AdvancedPhase 10 / Topic 24 of 25RequirementsTrade-offsFailure modes
01

Overview

Classic RAG is a fixed pipeline. It embeds the question, retrieves top-K chunks once, and generates an answer. Agentic RAG puts an LLM agent in control of retrieval. The agent decides whether it needs to search at all, which source to query, how to rewrite the query, whether the results are good enough, and whether to search again before answering.

The benefit is better answers for complex questions, such as comparisons, multi-step lookups, or questions spanning several systems. The cost is more LLM calls, higher and less predictable latency, and harder debugging. A good design uses classic RAG for simple questions and escalates to the agentic path only when needed.

Librarian vs research assistant

Classic RAG is a librarian who hears your question once, fetches five books, and hands them over. Agentic RAG is a research assistant who reads the first results, realizes they need a different angle, checks the database and another shelf, and only then writes the summary.

02

When to use it

  • Questions that need several lookups, for example comparing two policies or joining data across systems.
  • Many heterogeneous sources such as docs, SQL databases, APIs, and web search.
  • When single-shot retrieval often returns irrelevant chunks.
03

Where it shows up in interviews

Multi-hop retrieval

Recognize it when: answering needs facts from more than one place.

  • Design an AI search engine
  • Design a RAG system
Routing across sources

Recognize it when: data lives in docs, databases, and APIs.

  • Design an AI agent
  • Design an AI customer-support system
04

Where it is used in real software

Research assistants

Deep-research style products plan searches, read results, and iterate before writing a report.

Enterprise copilots

Choose between wiki search, ticket search, and a metrics database depending on the question.

Coding agents

Search the repository, open files, and search again based on what they find.

05

Key terms

Query rewriting
Rephrasing or splitting the question to improve retrieval.
Router
A step that chooses which source or tool to query.
Self-evaluation
The agent judges whether retrieved context is sufficient before answering.
Iteration limit
A cap on retrieval rounds to bound cost and latency.
06

How it works, step by step

  1. 1
    Decide whether to retrieve

    Simple greetings or general questions may not need retrieval at all.

  2. 2
    Plan and route

    Break the question into sub-questions and choose a tool for each, such as vector search, SQL, or an API.

  3. 3
    Retrieve and grade

    Run searches and score whether results are relevant and sufficient.

  4. 4
    Refine or continue

    If results are weak, rewrite the query or try another source, up to an iteration limit.

  5. 5
    Synthesize with citations

    Combine the gathered evidence into one answer that cites each source.

Fixed pipeline vs agent loop
Step 1 / 4
Question
Plan
Retrieve
Grade results
Answer

STEP 1Question "Compare our 2024 and 2025 remote-work policies". The agent plans two lookups.

07

Classic vs agentic

Same knowledge base, three question types.

Step 1 / 3
Question typeClassic RAGAgentic RAG
Single fact lookupGood, 1 LLM callGood, but 2-3 calls
Comparison across documentsOften misses one sideRetrieves each side separately
Needs live data from an APICannotCalls the API tool

NOWQuestion type: Single fact lookup | Classic RAG: Good, 1 LLM call | Agentic RAG: Good, but 2-3 calls

Route simple questions to classic RAG and escalate complex ones to the agent.

08

Implementation

type Tool = { name: string; run: (query: string) => Promise<string[]> }; async function agenticRag(question: string, tools: Tool[], maxRounds = 3) {  const evidence: string[] = [];  let query = question;   for (let round = 0; round < maxRounds; round++) {    const decision = await llmJson<{ tool: string; query: string } | { done: true }>(      `Question: ${question}\nEvidence so far:\n${evidence.join("\n")}\n` +      `Tools: ${tools.map((t) => t.name).join(", ")}. Reply {"done":true} if evidence is sufficient, ` +      `otherwise {"tool": name, "query": text}.`,    );    if ("done" in decision) break;    const tool = tools.find((t) => t.name === decision.tool);    if (!tool) break;    query = decision.query;    evidence.push(...(await tool.run(query)));  }   return llmText(`Answer using only this evidence and cite it:\n${evidence.join("\n")}\n\nQuestion: ${question}`);}
09

Complexity and performance

LLM calls1 (classic) vs 3-10 (agentic)

Each planning and grading step is a call.

Latencyseconds to tens of seconds

Stream progress updates to keep users informed.

10

Trade-offs

Quality vs cost and latency

Iteration improves complex answers but multiplies model calls. Cap rounds and route simple questions to the fast path.

Flexibility vs predictability

A fixed pipeline is easy to test and debug. Agents can take different paths for the same question, so tracing and evaluation are essential.

11

Variants and related techniques

Corrective RAG

Grades retrieved chunks and falls back to another source when they are irrelevant.

Multi-agent RAG

Separate agents handle retrieval, verification, and writing.

12

Common mistakes

  • Unbounded loops.

    Fix: Set a maximum number of rounds, a token budget, and a timeout.

  • Using the agent for every question.

    Fix: Route by complexity so most traffic stays on the cheap, fast path.

  • No tracing.

    Fix: Log every plan, tool call, and retrieved result to debug and evaluate behavior.

13

Interview questions

When would you choose agentic RAG over classic RAG?

When questions need multiple lookups, several sources, or live data, and when single-shot retrieval quality is poor. For simple fact questions classic RAG is cheaper, faster, and easier to evaluate.

How do you keep agentic RAG costs under control?

Route simple questions away from the agent, cap iterations and tokens, use a small model for planning and grading, cache retrieval results, and monitor cost per request.

14

Practice problems

ProblemDifficultyWhat it trains
Add a relevance grader that triggers a second searchMediumCorrective retrieval.
Design an assistant that answers across docs, SQL, and a ticketing APIHardRouting and iteration limits.