RAG End to End, No Gaps
You know retrieval; the commonly missing piece is the G. RAG stands for Retrieval-Augmented Generation: retrieval collects evidence, and then a language model writes the answer from that evidence. Retrieval alone is a search engine. The generation step is what turns search results into a direct, grounded answer β and it's also a second place where things can go wrong. This lesson is the complete pipeline, walkable from memory.
The two phases
Phase 1 β Ingestion (before any user shows up):
- Collect the authoritative documents (and only authoritative ones β corpus scoping is a governance decision).
- Chunk them β split into passages, respecting structure.
- Embed each chunk with the embedding model.
- Store (vector, chunk text, source metadata β document, section, version, date) in the index. The metadata is what makes citations possible later.
Phase 2 β Query time (every question):
- Embed the user's question with the same embedding model.
- Vector search: top-k nearest chunks. Optionally rerank β a second, more careful pass that reorders candidates by true relevance (this is the "retrieve candidates, then verify them" instinct, productized).
- Assemble the prompt β this is the load-bearing step people forget. The prompt contains: the retrieved chunks (with their source labels), the user's question, and instructions like: "Answer using only the provided context. Cite the source for each claim. If the context doesn't contain the answer, say you don't know."
- The LLM generates the answer from that prompt β grounded, citing chunks.
- Return the answer with its citations, so a human can check the claim against the source. In high-stakes systems, log the whole assembly (question, chunks used, answer) β that log is your audit trail.
One-sentence summary for the room: "Retrieval finds the evidence; the LLM writes the answer from the evidence; citations make it checkable."
Every way it produces a wrong answer with a real citation
This question separates people who've operated RAG from people who've read about it. There are failure modes on both sides:
Retrieval side:
- Over-matching β the answer isn't in the corpus, so search returns the nearest related chunk, and the answer gets built on the wrong source. Defense: relevance thresholds + "I don't know" as a first-class outcome.
- Stale corpus β the citation is real, the document is outdated. Defense: corpus versioning and re-indexing discipline.
- Bad chunking β the retrieved fragment lacks the qualifier that changes the meaning ("waived for renewals only"). Defense: chunking that respects document structure.
Generation side (possible even with perfect retrieval):
- The model misreads or blends chunks β merging two requirements into one that doesn't exist, decorated with both citations.
- The model answers from its own weights β ignoring the context and generating from training memory, then attaching a citation cosmetically. Defense: strict "context-only" instructions, low temperature, and evaluation questions designed to catch exactly this.
- The question outruns the context β the user asks for a synthesis the chunks don't support, and the model obliges anyway.
Because failures live on both sides, so does verification: retrieval metrics (are the right chunks found?) and generation metrics (is the answer faithful to the chunks?) are measured separately. That sentence alone signals real practice.
Interview drill
Whiteboard the nine steps from memory β ingestion (collect, chunk, embed, store) and query (embed, search/rerank, assemble prompt, generate, return with citations). Then recite four wrong-with-citation causes: over-match, stale corpus, chunk fragmentation, unfaithful generation β and one defense for each. When you can do both cold, this topic is closed.