Five stages.
One map of RAG techniques.
A RAG pipeline has five stages. Each technique changes one stage. For each one, ask: what does it fix, what does it cost, and when should I skip it?
- Indexingprepare the pages
- Pre-retrievalimprove the question
- Retrievalsearch
- Post-retrievalpick the best pages
- Generationanswer from the pages
- AdvancedRAG that checks and improves itself
Two moments. Indexing happens once, before anyone asks. The other four stages run for every question: improve the question → search → pick the best pages → answer from the pages. Source column: “nb 05” = notebook 05 in the all-rag-techniques collection (MIT); “outside the repo” = a paper or product page.
1 · Indexing (prepare the pages)
How do we cut, label and store the files so each page can be found?
Pedala example The 2026 price sheet has a section “Student plan” with the line “Price: €25 per month”. A cut every N characters can split the heading from the price. A cut at the heading keeps them together. A label says which price sheet is current.
| Technique | What it does | Good | Bad | Source |
|---|---|---|---|---|
| Cut every N characters (fixed-size chunking) | Cut the text into equal pieces. The simplest pipeline. | Simple, cheap, fast. | Cuts ideas in half. A line can lose its heading. | nb 01in the lab |
| Cut at the headings (section chunking) | Each page is one section, with its heading. | Cheap and predictable. Keeps a line with its heading. | Needs files with clear headings. Some sections are long. | outside the repoin the lab |
| Cut where the topic changes (semantic chunking) | Measure how similar each sentence is to the next. Cut where the topic shifts. | Works when files have no headings. | One model call per sentence. Page sizes vary. Needs tuning. | nb 02 |
| Test the page size (chunk-size test) | Try small, medium and large pages. Keep the size that gives the best answers. | Turns a guess into a test. | Needs test questions. Re-indexing costs time. | nb 03 |
| One fact per card (proposition chunking) | A model rewrites the text as short facts. Each fact is indexed alone. | Precise for fact questions. | Many model calls. A rewrite can drop a condition. Keep a link to the original line. | nb 14 |
| Describe the charts (multimodal captions) | A vision model writes a caption for each chart or image, so search can find it. | Charts in a pitch deck become searchable. | One call per image. A caption can miss or invent a detail. | nb 15 |
| Stamp each page with its source (contextual chunk headers) | Add the file name, date and section to the top of each page. | Cheap. Works with any cut. | A wrong header misleads search. Adds tokens. | nb 05in the lab |
| Explain each page before you store it (Contextual Retrieval, by Anthropic) | A model writes a short context for each page from the whole file. The context goes into both search indexes. | Anthropic reported 49% fewer top-20 search failures, 67% with reranking, on its own test sets. | One model call per page. Your files can differ. | outside the repo |
| Write the questions each page answers (question generation, or document augmentation) | Store likely questions next to each page. Match questions to questions. | Bridges different words at index time. | Many model calls. The index grows. Real users ask other questions. | nb 06 |
| Labels on every page (metadata: status, date, owner) | Store tags such as “current” or “superseded” with each page. | Exact, cheap, easy to explain. | Needs clean labels. A wrong label hides the right file. | outside the repoin the lab |
| Table of contents first (hierarchical index) | Summarise each section. Search the summaries first, then the detail. | Focused search in a big data room. | A wrong first pick cannot be fixed later. Summaries go out of date. | nb 18 |
| A tree of summaries (RAPTOR) | Group and summarise pages again and again into a tree. Search at several levels. | Reported +20% absolute accuracy on one benchmark with GPT-4. | Many summary calls. Rebuild when files change. | outside the repo |
2 · Pre-retrieval (improve the question)
How do we turn the question into a better search?
Pedala example The partner asks: “Can Pedala cancel the battery contract?” The agreement never says “cancel”. It says “end the agreement with 90 days’ written notice”. Rewrite the question in the file’s words.
| Technique | What it does | Good | Bad | Source |
|---|---|---|---|---|
| Say it in the file’s words (query rewrite) | A model rewrites the question before the search. | No change to the index. Easy to add. | One extra model call. A rewrite can drift from what you meant. | nb 07in the lab |
| Ask the bigger question too (step-back question) | Also search a broader question to fetch the background. | Brings the rule behind a detail. | More searches. Can fetch text that is too general. | nb 07 |
| Split it into small questions (sub-questions, or decomposition) | Break a complex question into simple ones. Search each one. | Helps comparisons: “Pedala vs BiciYa churn”. | More searches, more waiting. | nb 07 |
| Sketch the answer, then search with it (HyDE) | A model writes a fake answer. Search with the fake answer, because answers look like answers. | Strong for short, vague questions. | The fake answer can hold false details. Never show it as the answer. | nb 19in the lab |
| Send it to the right place (routing) | Decide what kind of question it is. Send it to the right search or source. | A price lookup and a market analysis get different treatment. | A wrong route sends the question the wrong way. Harder to test. | nb 12 |
3 · Retrieval (search)
How do we find the candidate pages?
Pedala example Keyword search finds “VoltCell” exactly. Meaning search finds “end the agreement” for “cancel”. Use both and merge the lists.
| Technique | What it does | Good | Bad | Source |
|---|---|---|---|---|
| Search by exact words (keyword search, BM25) | Match the words of the question. | Cheap. No model. Good for names, numbers and codes. | Misses other words for the same idea. | nb 16in the lab |
| Search by meaning (dense search, embeddings) | Each page gets a place on a meaning map. The question lands on the map. The nearest pages win. | Finds other words for the same idea. | Weak on exact terms. Old and new versions both match. | nb 01in the lab |
| Use both and merge the lists (hybrid search with reciprocal rank fusion, RRF) | Run both searches. Merge by rank: 1 / (60 + rank). The lab uses RRF. | Strong across question types. No score tuning. | Two indexes to keep in step. | nb 16 (weighted) · RRF outsidein the lab |
| Drop pages with the wrong label (metadata filter) | Remove pages tagged “superseded” before you rank. | Exact and easy to explain. | Only as good as the labels. | outside the repoin the lab: Indexing panel (“Hide old versions”), because the label is set at indexing |
| How many pages to bring (top-k) | Keep the best k pages. | One simple setting. | Always returns k pages, even bad ones. | nb 01in the lab |
| Find the card, bring the whole page (small-to-big, or parent-child) | Search small pieces for a precise match. Bring the larger section around it. | Precise match and enough context. | More tokens per hit. Needs links between pieces. | outside the repo |
| Match word by word (late interaction, ColBERT) | Keep one vector per word for a finer match. For engineers. | Finer match than one vector per page. | A much larger index. | outside the repo |
4 · Post-retrieval (pick the best pages)
Which pages go on the desk, in what order and size?
Pedala example The investor FAQ repeats “customers” and “complaint” many times but holds no facts. It fills the top results. A careful second judge moves the customer survey to the top.
| Technique | What it does | Good | Bad | Source |
|---|---|---|---|---|
| A careful second judge (reranking) | Take a wide list. A slower model scores each page. Keep the best few. | Large gain for little code. The first search can stay fast and wide. | One model call per candidate. Cannot help if the right page was never found. | nb 08in the lab |
| Keep only the useful lines (contextual compression) | Cut each page down to the sentences that answer the question. | Fewer tokens, less noise. “Extraction” mode keeps exact quotes. | An extra model call. Can drop a needed condition. | nb 10in the lab |
| Bring the whole passage (relevant segment extraction) | Join neighbouring good pieces into one passage, in reading order. | No model call. | Needs page positions. Can return long passages. | nb 09 |
| Add the page before and after (neighbour chunks) | Add the pieces next to the best hit. | Very cheap. No model call. | Adds tokens even when they do not help. | nb 04 |
| Best pages first (ordering) | Bring fewer, better pages. Put the strongest first. | Free. A 2023 study found models use the start and end of a long context best. | The study used 2023 models. Today’s effect is not known. | outside the repo |
5 · Generation (answer from the pages)
How does the model answer from the desk?
Pedala example The partner asks: “Does Pedala own any patents?” No file mentions patents. The correct answer is “Not in the data room.”
| Technique | What it does | Good | Bad | Source |
|---|---|---|---|---|
| Put the pages on the desk (context injection) | Add the chosen pages to the prompt, each with its file name. Long files go first, the question last. | The model can name the file and the line. | Retrieved text is untrusted data, the same as tool output (Thursday 03). | all |
| Point to the page (cite and quote) | Ask the model to quote the lines it used, then answer. | You can check every claim. | Longer answers. | outside the repo |
| Say “not in the data room” (abstain threshold) | If no page scores high enough, do not answer. | Stops confident guesses. “Missing content” is the first of seven known RAG failure points. | Set it too high and real answers disappear. | outside the repoin the lab |
| Check the answer against the pages (support check (faithfulness)) | Check that each claim in the answer is backed by a page on the desk. | Catches made-up details. | Another model call. The checker can be wrong too. | outside the repo |
+ · Advanced (RAG that checks and improves itself)
When do we search, how do we check, and how does the system get better?
Pedala example Before the committee, the agent searches the data room, sees the evidence is weak, searches again with new words, answers, then checks its own answer.
| Technique | What it does | Good | Bad | Source |
|---|---|---|---|---|
| Decide if you need to search (Self-Route) | Choose per question: search (RAG) or put the whole file on the desk (long context). | Costs much less than long context for every question, with similar results. | A wrong choice skips a needed search. | outside the repo (Self-Route, Li et al. 2024) |
| Check the pages, then the answer (Self-RAG) | Search only when needed. Grade each page. Check that the answer is backed. | Visible checks. | Many calls per question. The paper trains a model; the notebook only uses prompts. | nb 13 (copies the paper with prompts) |
| If the pages are weak, search again (Corrective RAG, CRAG) | Grade the pages. If they are weak, rewrite and search elsewhere. | A clear quality gate. | Web search brings untrusted text. For a private data room, “not in the data room” is often better. | nb 20 |
| Search as a tool the agent calls (agentic RAG) | The agent decides when, what and whether to search again. | Handles multi-step questions. Mixes sources. | More calls, more waiting, harder to test. | outside the repo |
| Follow the links between facts (Graph RAG) | Link related pages. Follow the links to join facts. | Answers questions that chain facts. | Costly to build. Rebuild when files change. | nb 17 |
| Who-did-what card file (knowledge graph from text) | Pull people, companies and links out of the text into a graph you can query exactly. | Exact, checkable queries. | A heavy pipeline. Extraction errors become “facts”. | nb 22 (builds the graph, gives no answers) |
| Themes across everything (Microsoft GraphRAG) | A graph plus summaries of related groups, for whole-collection questions. | Answers “what are the themes?” questions that plain RAG misses. | Microsoft warns that indexing “can be an expensive operation”. | outside the repo |
| Learn from ratings (feedback loop) | Use people’s ratings to adjust later results. | Uses real signal. No training. | Bad or false feedback can poison results. | nb 11 |
| Learn which steps help (RAG with reinforcement learning) | Try pipeline actions and keep the ones that score well. | Shows a learned search policy. | Needs reference answers. Slow. A research idea, not a first project. | nb 21 |
| Put it all on the desk instead (long context vs RAG) | If the files are small, put all of them on the desk. Anthropic’s advice: under 200,000 tokens, you can skip RAG. | Simpler for a small, stable data room. A 2024 study found long context wins on average with enough budget. | RAG costs much less. Big, changing or private data still needs search. | outside the repo |
| Measure it (evaluation: RAGAS, best_rag_finder) | Use a test set to measure search and answers. Then choose settings. | Turns RAG into an experiment. | Notebook scores use one file and a small judge. They are not benchmarks. | best_rag_finder |
Beyond basic RAG: four steps
- RAGFind the right passages.Find Pedala’s standard price.
- Graph RAGFind connected facts.“Which of Pedala’s investors also back BiciYa?”
- Agentic GraphsAgents plan the work as a graph of tasks and fetch what each task needs.Agents split the investment memo: market, team, numbers.
- Agentic Learning GraphsAgents also write back. The graph grows and becomes memory.The fund’s graph grows after every deal.
From Jose F. Sosa (2025), “Comparative Analysis of RAG, Graph RAG, Agentic Graphs, and Agentic Learning Graphs”. This is the author’s comparison, in our words. The fourth step is memory: a wrong fact, once added, shapes later answers, so it needs checks and a way to forget. Agentic graphs come back in Thursday 05 and 06.
Stage names: Gao et al., “Retrieval-Augmented Generation for Large Language Models: A Survey” (2024). We show Indexing as its own stage because it runs before anyone asks. “nb” = notebook number in all-rag-techniques by Fareed Khan (MIT), via github.com/Shubhamsaboo/all-rag-techniques. We adapt ideas; we copy no code. Notebook scores are teaching results, not benchmarks. Notebook 16 uses weighted score fusion; the lab uses reciprocal rank fusion (Cormack et al. 2009). Other sources: Anthropic Contextual Retrieval (2024), Liu et al. 2023, Asai et al. 2023, Yan et al. 2024, Edge et al. 2024, Sarthi et al. 2024, Li et al. 2024, Barnett et al. 2024, Es et al. 2023, Sosa 2025. Pedala, BiciYa, VoltCell, Fondo Norte and every person in the data room are fictional. Checked 29 October 2026.