LyraLearn AI Learning Platform
Exams
← Module 12 Β· Gap Drills: The Mechanical Layer
🎧 Listen

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):

  1. Collect the authoritative documents (and only authoritative ones β€” corpus scoping is a governance decision).
  2. Chunk them β€” split into passages, respecting structure.
  3. Embed each chunk with the embedding model.
  4. 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):

  1. Embed the user's question with the same embedding model.
  2. 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).
  3. 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."
  4. The LLM generates the answer from that prompt β€” grounded, citing chunks.
  5. 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:

Generation side (possible even with perfect retrieval):

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.

🧠 Quiz yourself on this lesson →

Ask the AI Tutor

Grounded in the course lessons β€” it cites its sources and says when it doesn't know.