RAG end to end: what each stage fixes, and what breaks when it fails A developer-authored lesson on Deployed Lab walks through a four-stage RAG pipeline — hybrid search, permission filtering, re-ranking, and prompt writing — showing how each stage fixes a distinct failure mode. Using a composite refund-policy example, it demonstrates that meaning-only search surfaces a marketing FAQ over the current policy and leaks a Legal-only contract page into the prompt, while mixing keyword and semantic scores or re-ranking recovers the correct 30-day answer, and only the permission filter removes the restricted page. The lesson advises debugging in pipeline order — chunking, search, permissions, re-rank, writing — and inspecting the pages that reached the prompt before blaming the model. A support assistant tells a customer, "You have 14 days to request a refund." The real policy says 30 days. In the same demo it quotes a contract line that only Legal may read. The English was fluent. The assistant was simply handed the wrong pages. This is the problem RAG retrieval-augmented generation exists to solve, and each stage of it fixes a different failure. The example below is a composite with made-up scores. It shows a pattern, not a benchmark. An AI that has never seen your files will guess, and the guess sounds confident. RAG lets it look up the right pages just before it answers. Looking things up is cheap and always current. Retraining goes stale the day a policy changes. Your documents are filed once, in advance, as chunks, each stamped with who may read it. Then every question passes through these stages. 1. Search. Hybrid search matches by meaning and by exact words, then mixes the scores. 2. Permission check. Pages the asker may not read are dropped, using the access list stored with each chunk. 3. Re-rank. A slower, more careful reader re-sorts the pages that search found. 4. Writing. The rules, top pages and question go into one prompt, and the AI answers. The question: "How long do Enterprise customers have to request a refund?" Four pages, made-up scores from 0 to 1: | Page | Meaning | Keyword | Careful reader | |---|---|---|---| | Refund policy v3 current | 0.74 | 0.95 | 0.97 | | Refund policy v1 old | 0.82 | 0.55 | 0.30 | | Marketing FAQ | 0.88 | 0.35 | 0.20 | | Legal-only contract page | 0.79 | 0.60 | 0.55 | Only the top 3 reach the AI. With meaning alone, the FAQ wins and the current policy is cut. The answer is vague, and the Legal-only page is in the prompt. Now mix half meaning and half keyword: The current policy rises to first place and the answer becomes 30 days. The re-ranker reaches the same result from a different stage: it scores the current policy 0.97 against 0.30 for the old one. Only the permission filter removes the Legal-only page. Check in order: shelving chunk size , search, permission check, re-rank, writing. An early fault hides later ones. Read the pages that went into the prompt first, because a wrong number could be a stale page or the AI inventing it. The chapter has an interactive lab where you switch hybrid search, the re-ranker and the permission filter on and off, and watch the answer change. It takes about 12 minutes and is free: RAG end to end https://deployedlab.dev/lessons/09-rag-end-to-end . It is one of the free chapters of Deployed Lab https://deployedlab.dev , a course on AI engineering and the forward deployed engineer role.