RAG in One View
Give the model your documents, not its guesses
Retrieval-Augmented Generation grounds model answers in your documents: index the corpus, retrieve what a question needs, and hand it to the LLM as context. This section maps the whole pipeline.
What you will learn
- Describe the RAG pipeline end to end
- Explain why grounding reduces hallucination
- Identify the levers that actually move RAG quality
What is this?
RAG (Retrieval-Augmented Generation) answers questions by first retrieving relevant chunks from your own corpus, then generating an answer with those chunks in the prompt. It combines a vector/lexical index for retrieval with the model's fluency. The result: answers grounded in material the model never saw, which is fresher, more specific and far less likely to invent policy or facts.
Why do you need it?
- Models hallucinate when the answer isn't in their weights — retrieval puts the truth in context.
- Your data stays yours: no fine-tuning, no weight updates, updates are index refreshes.
- Citations become possible: you know which chunks claimed what.
- Costs are well-scoped: index size dominates, generation stays same-size queries.
Mental model
A librarian fetching before the writer writes
RAG
You ask a library question. The librarian (retriever) runs to the shelves and returns three relevant books (chunks). The writer (LLM) reads them and answers strictly from what they say. No books, no trustworthy answer — a documented bibliography on demand.
How it works
- Ingest: parse/corpus documents → chunk → embed → index.
- Retrieve: embed the question → top-k nearest chunks.
- Augment: assemble system prompt + user question + retrieved chunks.
- Generate: the LLM answers grounded in those chunks.
- Verify: citations/scores let you trust (or reject) each claim.
The RAG loop.
In production
- Support copilots answer from the help center, not from the model's vague memory.
- Policy bots cite the exact clause that justifies each statement.
- Code assistants retrieve from your private repos for project-aware answers.
Best practices
- Start simple: okay chunking, top-k=4-8, plain LLM prompt — then measure.
- Ground only what you actually need; don't stuff the whole corpus in every call.
- Add citations + not-found behavior from day one.
- Improve retrieval before touching the prompt or the model.
Common mistakes
- Tuning the prompt while retrieval returns garbage — you polish noise.
- Stuffing entire documents into context and overflowing budgets.
- Serving retrieval failures as confident answers without grounding checks.
- Dropping the question entirely and asking 'summarize these chunks'.
Common issues
Model ignores retrieved contextPrompt structure devalues chunks or retrieved noise
Restructure prompt, reduce chunk count, or gate generation behind retrieval quality.
Answers book-cold without corpusRetrieval returned nothing/confused chunks
Debug retrieval first: corpus coverage, chunk quality, top-k/threshold.
Debugging tips
- Answers contradict docs → check chunk selection (retrieved the wrong section).
- Generic answers despite massive retrieval → chunks ignored; reinforce with prompts/routing.
- Citations wrong → retrieval-scoring or citation-assembly logic, not the model.
Interview checkpoint
Quick quiz
The purpose of retrieved chunks in RAG is to…
RAG eliminates the need to update model weights for new knowledge.