Last updated

How RAG Works: The Pipeline

Definition: RAG has two phases. First you index your documents (done once, in advance). Then, for each question, you retrieve, augment, and generate.

Phase 1 — Indexing (prepare your knowledge)

  1. Load your documents (PDFs, web pages, notes).
  2. Chunk them into small passages.
  3. Embed each chunk into a vector (a list of numbers capturing its meaning).
  4. Store the vectors in a vector database.

Phase 2 — Answering (for every question)

  1. Retrieve — embed the question and find the most similar chunks.
  2. Augment — paste those chunks into the prompt alongside the question.
  3. Generate — the language model answers using the provided context.

The whole flow in one line

Question → find relevant chunks → "here is the context, now answer the question" → grounded answer.

💡 Coming up: the next lessons build each piece — embeddings, similarity, chunking, and retrieval — with code you can actually run.

Ad · responsive