Module 1 · Beyond naive RAG

Anatomy of a modern RAG pipeline

6 min read

A "naive" RAG fits in five steps: split the documents, embed them, find the passages closest to the question, paste them into a prompt, generate. It works surprisingly well in a demo… and disappoints as soon as the data gets real: badly phrased questions, product references, documents that look alike, questions that span several sources. This course takes the pipeline apart step by step and shows, with numbers, what each advanced technique brings.

The naive pipeline

INDEXING   documents ─► chunking ─► embeddings ─► vector database
QUERY      question ─► embedding ─► k nearest neighbors ─► prompt ─► LLM ─► answer

Every arrow hides a choice, and every default choice is a potential source of failure. A modern pipeline adds steps at almost every level:

StepNaive RAGModern RAGModule
ChunkingFixed sizeStructure, added context, parent/child3
RepresentationOne dense vectorDense + lexical (hybrid), possibly a graph3, 4
StorageDefault indexTuned ANN index, quantization, filters, multi-tenancy2
QueryThe question as isRewriting, HyDE, decomposition3
Retrievalk nearest neighborsBroad retrieval + re-ranking3
OrchestrationOne retrieval, one answerAgent that searches several times, self-correction4
ControlNoneContinuous evaluation, cache, observability5

The core message of the course is simple: none of these techniques is free, and none always helps. Each adds latency, cost or complexity. The only way to know whether it is worth it on your data is to measure it.

Prism: a lab for measuring

The companion project, Prism, is not an application: it is a test bench. Every technique is implemented in readable Python (often in a few dozen lines, to understand its principle) and measured on the same dataset:

  • a corpus: the help center of Nimbus, a fictional online store — 36 articles in French (returns, warranty, delivery, products, error codes…), split into 67 passages;
  • a set of 45 annotated questions, with the articles that answer them, divided into types that each stress one weakness:
TypeExampleWhat it tests
Factual"How much does express delivery cost?"The easy case
Rephrased"I changed my mind, can I send my order back?"Vocabulary different from the documents'
Lexical"What does code E02 mean?"Exact references, which embeddings handle poorly
English"How long do I have to return an item?"A language different from the corpus's
Multi-source"Supplier of the Lift desk and warranty of its motors?"Several articles needed
Out of scope"Do you sell 3D printers?"Knowing how to say "I don't know"

(The questions are in French in the dataset, except the English ones, which are deliberately in a different language from the corpus.)

Embeddings and the re-ranker run locally (FastEmbed): you reproduce every number in the course with no API key and no cost. The techniques that need an LLM (rewriting, contextual retrieval, GraphRAG, agent, judge) use Claude; an offline mode (PRISM_FAKE=1) runs everything without a key, to check the mechanics.

A first look at the results

Here are the results of a few configurations measured on this dataset — detailed in the following lessons:

ConfigurationRecall@5MRREnglish questionsRephrased
BM25 (lexical)0.740.700.000.55
Dense (embeddings)0.900.820.920.90
Hybrid (RRF fusion)0.990.820.921.00
Hybrid + re-ranking1.000.971.001.00

In one line: lexical search fails completely on English questions, dense search misses multi-source questions, fusing the two finds almost everything, and re-ranking puts the right answer first almost every time. These gaps are not universal — they depend on the corpus, the questions and the models — but they show why we measure.

What a demo corpus does not show

Prism is small on purpose: it runs in seconds and every failure can be read by eye. Three effects do not show up in it, and the course covers them separately:

  • scale: with millions of vectors, exact search becomes too slow; approximate indexes (lesson 2.1) and quantization (lesson 2.4) are required;
  • real diversity: real questions are more varied, more ambiguous and more error-ridden than 45 carefully written questions;
  • the ceiling: on a small corpus, several configurations reach 100%; on a real corpus, the gaps between techniques persist much longer.

Prism's numbers are therefore a method, not a general truth: reproduce the test bench on your own data before choosing.

cd prism-rag
pip install -e ".[dev,ann]"
python examples/01_benchmark.py      # modèles réels, téléchargés au premier lancement
PRISM_FAKE=1 pytest                  # 25 tests hors ligne

(The first command uses the real models, downloaded on first run; the second runs the 25 offline tests.)

Key takeaways

  • A naive RAG chains chunking, embeddings, k nearest neighbors and generation; every default choice can fail.
  • A modern RAG improves every step: chunking, hybrid representation, tuned indexes, transformed queries, re-ranking, orchestration, evaluation.
  • No technique is free or universal: keep it if it wins on your data.
  • Prism measures every technique on the same set of 45 questions annotated by difficulty type.
  • A small corpus shows the method; real scale and diversity are handled separately.

Practice

  1. Install Prism and run examples/01_benchmark.py: do you get the numbers in the table?
  2. Read the failures listed by the test bench for BM25: what do these questions have in common?
  3. Add three questions of your own to data/questions.jsonl (with their expected articles) and rerun the test bench.

Resources