RAGEngineering Hub
Chapter 12 · concept 2 of 4 · show all
  1. 1What RAG is, and why
    1. 1.1Why models need outside knowledge, and what hallucination means
    2. 1.2What RAG is: anatomy of a request
    3. 1.3RAG vs fine tuning vs long context and prompt caching
    4. 1.4Use cases and the quality, latency and cost triangle
    5. Chapter overview
  2. 2Tokens, cost and your first RAG
    1. 2.1Tokens and context windows for RAG
    2. 2.2The RAG lifecycle and your first RAG in miniature
    3. Chapter overview
  3. 3Getting documents in
    1. 3.1Content sources and file formats
    2. 3.2Parsing, layout and OCR
    3. 3.3Tables, images and mixed content
    4. 3.4Cleaning, normalization and quality gates
    5. 3.5Metadata, document identity and versioning
    6. 3.6Updates, deletes, reindexing and ingestion pipelines
    7. Chapter overview
  4. 4Chunking
    1. 4.1Why we chunk, and the main chunking strategies
    2. 4.2Structure aware chunking and tables
    3. 4.3Chunk size, overlap and token based sizing
    4. 4.4Contextual chunking and late chunking
    5. 4.5Parent child and multi representation indexing
    6. 4.6Chunk metadata, provenance and the chunking debugging playbook
    7. Chapter overview
  5. 5Embeddings
    1. 5.1Embeddings and similarity from first principles
    2. 5.2What embeddings cannot do
    3. 5.3Choosing an embedding model: size, cost, language
    4. 5.4Embedding model migration and index rebuilds
    5. Chapter overview
  6. 6Vector stores and scores
    1. 6.1Vector databases, ANN indexes and choosing a store
    2. 6.2Score calibration and thresholds
    3. 6.3Late interaction and multivector retrieval
    4. Chapter overview
  7. 7Finding the right chunks
    1. 7.1Query understanding, rewriting and expansion
    2. 7.2Dense retrieval and keyword search with BM25
    3. 7.3Hybrid retrieval and rank fusion
    4. 7.4topK, no good match, and metadata filtering
    5. 7.5Routing, diversity, deduplication and caching
    6. 7.6Reranking: two stage, cross encoder and LLM rerankers
    7. Chapter overview
  8. 8When retrieval fails
    1. 8.1Retrieval failure analysis playbook
    2. Chapter overview
  9. 9Building the answer
    1. 9.1Context selection, packing and citations
    2. 9.2Grounding prompts and abstention
    3. 9.3Lost in the middle and context management
    4. 9.4Conflicts, staleness and freshness rules
    5. 9.5Hallucination checks and answer verification
    6. 9.6Conversational RAG, answer UX and RAG APIs
    7. Chapter overview
  10. 10Measuring
    1. 10.1Why measure, and what to measure
    2. 10.2Building a golden dataset
    3. 10.3Retrieval metrics: precision, recall, MRR, nDCG
    4. 10.4Faithfulness and answer correctness
    5. 10.5LLM as judge, and judging the judge
    6. 10.6Offline and online evals, regression tests and slices
    7. Chapter overview
  11. 11Safety and operations
    1. 11.1Prompt injection and poisoned documents
    2. 11.2Access control, privacy and governance
    3. 11.3Index lifecycle operations
    4. 11.4Observability and tracing
    5. 11.5Latency, cost, caching and model routing
    6. 11.6Reliability, degraded modes and launch readiness
    7. Chapter overview
  12. 12Scale and advanced RAG
    1. 12.1Scaling, multi tenancy and enterprise architecture
    2. 12.2Choosing an architecture: naive, advanced, agentic, graph
    3. 12.3Agentic RAG and RAG as an MCP tool
    4. 12.4GraphRAG, structured data and multimodal RAG
    5. Chapter overview

Choosing an architecture: naive, advanced, agentic, graph

Four families of RAG design, from one vector search to agents and knowledge graphs. Start simple, measure, and climb only when a measured failure needs it. On our corpus, two simple steps did most of the work.

A real question

Naive RAG, advanced RAG, agentic RAG, GraphRAG. Which one should we build?

The simplest one that passes your golden set. Start naive, measure, and add one technique for each failure you can name. Most teams need hybrid search and a reranker long before they need agents or graphs.

The problem

Why this matters

The belief

Start with the most advanced design, so you never have to rebuild.

What really happens

On our corpus, plain vector search put the answer first for 30 of 47 questions. Adding keyword search and a reranker made it 40, and all 47 in the top 3. Every extra layer adds cost, latency and ways to fail.

Why not the simpler way

New RAG patterns appear every month, each with an impressive demo. Teams adopt them before measuring the basics, and end up with slow, expensive systems that are hard to debug. This course measured each step on one corpus; this page puts them together into a decision.

The idea

The idea in plain words

Naive RAG: embed, retrieve top k, generate. Advanced RAG: improvements around the same single pass (better chunking, hybrid search, reranking, filters, query rewriting, verification). Agentic RAG: a model decides what to search, possibly many times, and can call other tools. GraphRAG: build a graph of entities and relations, and retrieve over it.

Choosing a vehicle: a bicycle for the commute, a van when you move house. Owning a lorry for the commute just in case is expensive.

How it works

Step by step

  1. 1

    Measure the simple design

    Chunk, embed, top k, prompt. Run the golden set and the slices. This is your baseline.

  2. 2

    Fix named failures

    Ranked low: hybrid and reranking. Old versions: filters. Follow-ups: rewriting. Multi-step questions: an agent. Relationships: a graph.

  3. 3

    Pay only for gains

    Keep a technique only if the golden set improves and the latency and cost budgets still hold.

In detail

Decision rules.

  • Answers present but ranked low → hybrid and reranking (RAG-28, RAG-31).
  • Wrong versions or roles → metadata filters (RAG-29, RAG-46).
  • Follow-ups fail → rewriting (RAG-38).
  • Questions need several look-ups that depend on each other, or calculations, or live systems → agentic (RAG-53).
  • Questions about relationships across many documents, or themes of the whole corpus → graph or hierarchical summaries (RAG-54).
  • Small, stable corpus → long context with caching may beat any RAG (RAG-04).

Costs to compare. Latency, cost per question, build effort, debuggability, and how many new failure modes it brings.

RAG pipeline: documents are loaded, chunked, embedded and indexed offline; at question time the index is searched, the best chunks are packed into the prompt, and the model writes a cited answer.OFFLINE · BUILD THE INDEXLoadPDF, HTML, MDChunk256–512 tokensEmbedtext → vectorIndexvectors + BM25ONLINE · ANSWER A QUESTIONQuestionuser asksRetrievetop k chunksPack promptwithin budgetGeneratecited answersearch the index
Quality is decided offline more often than online: a chunk that splits the answer cannot be rescued by a better prompt.

The code

Try it in Python

LADDER = [
    ("naive",    lambda: VectorRAG()),
    ("hybrid",   lambda: HybridRAG()),
    ("rerank",   lambda: HybridRAG(reranker="bge-reranker-base")),
]

def climb(golden, budget_ms: float, min_gain: int = 2):
    best_name, best = None, None
    for name, make in LADDER:
        system = make()
        score, p95 = run_golden(system, golden), p95_latency(system, golden)
        if p95 > budget_ms:
            break
        if best is None or score - best >= min_gain:
            best_name, best = name, score
    return best_name

See it

What we measured

Measured · naive against advanced RAG on 47 golden questions

Polder corpus, 34 recursive 512 token chunks. Naive: bge-small vector search. Advanced: BM25 + vector with RRF, top 10 reranked by bge-reranker-base.

Answer in top 3naive 44advanced 47
Answer ranked firstnaive 30advanced 40
Extra retrieval timeabout 1.4 s (reranking)
Agentic and graph designsnot measured

Measured 2026-11-04 with corpus/scripts/measure-parts-4-7.mts and measure-part-8.mts.

Try it on a real example

Four families, what they add, and what we measured

Design

One vector search, top k, prompt

Simple, fast, cheap.

Measured: 44 of 47 in the top 3, 31 first.

Choosing

Use it when, avoid it when

Use it when
  • Naive RAG as a measured baseline
  • Advanced techniques per named failure
  • Agents or graphs only for question types the golden set shows failing
Avoid it when
  • Choosing a design from a demo
  • Keeping components that no longer improve the numbers

What it costs · Each rung adds latency, cost and failure modes; measure all three.

In production

Write the decision down: which failures each component fixes, with the golden-set numbers. Revisit it when the question mix changes; new user needs, such as multi-step questions, are the real reason to climb. Remove components that no longer pay for themselves.

Watch out

Common mistakes

  • Naive RAG is a toy. It found 44 of 47 here; it is the right start.
  • Agentic RAG is the next version of RAG. It is a tool for specific questions.
  • GraphRAG replaces vector search. Most graph systems still use vector search inside.

Check yourself

Remember this

Remember these

  • Start naive and measure; it is your baseline.
  • Advanced RAG (hybrid, rerank, filters) fixed most failures here.
  • Agents and graphs solve specific problems at real cost.
  • Keep a technique only if the golden set and budgets agree.

Say it in an interview

  1. 01I start naive, measure, and add one technique per named failure.
  2. 02On my corpus hybrid plus reranking took answers first from 30 to 40 of 47.
  3. 03I use agents for multi-step questions and tools, not as a default.
  4. 04I consider graphs for relationship and corpus-wide questions.
  5. 05Every component has to justify itself on the golden set and the budgets.

Quick quiz

Three questions

Question 1

Q1

On our corpus, which change moved answers at rank 1 from 30 to 40 of 47?

Question 2

Q2

When does an agentic design earn its cost?

Question 3

Q3 · from RAG-04

When is long context or caching better than RAG?

Saved on this device. No account needed.