Learn/Generative AI, RAG & Agents/MODULE 2: RETRIEVAL AUGMENTED GENERATION (RAG)
Lesson 16 of 37 · 3 min read

2.5 The Full RAG Pipeline

Now let's put it all together.

A complete RAG system has two distinct workflows: an indexing pipeline that runs ahead of time to prepare your documents, and a query pipeline that runs each time a user asks a question.

Indexing Pipeline (Done Once, Updated Periodically)

This is the setup phase.

You do this whenever you have new or updated documents.

[Your Documents]
       ↓
   Load & Parse
       ↓
   Chunk into smaller pieces
       ↓
   Generate embeddings (using an embedding model)
       ↓
   Store in vector database
  1. Load & Parse: Read the documents from wherever they live — files on disk, web pages, databases, Google Drive, Notion, etc. Extract the text from each (PDFs, Word docs, HTML pages all need different handling).
  2. Chunk: Split each document into smaller pieces (we'll discuss why and how in section 2.6).
  3. Embed: Run each chunk through an embedding model to get a vector.
  4. Store: Save each chunk's text, embedding, and metadata into the vector database.

This pipeline might process thousands or millions of documents.

You'll typically re-run it on a schedule (nightly, weekly) to incorporate new content, or trigger it whenever a document is added or updated.

Query Pipeline (Runs for Every User Question)

This is what happens each time a user interacts with your RAG-powered app.

[User Question]
       ↓
   Generate embedding of the question
       ↓
   Query vector database for top-K similar chunks
       ↓
   Build a prompt: question + retrieved chunks + instructions
       ↓
   Send to LLM
       ↓
   Return LLM's answer (with citations)
  1. Embed the question using the same embedding model used for indexing. (Using the same model is critical — different models produce incompatible embedding spaces.)

  2. Query the vector database for the top K most similar chunks. K is typically 3–10, depending on how much context you want to provide.

  3. Build the prompt. This is just a string with a structure like:

    "Answer the following question based on the provided context. If the answer is not in the context, say you don't know.

    Context:
    [Retrieved chunk 1]
    [Retrieved chunk 2]
    [Retrieved chunk 3]

    Question: [user's question]

    Answer:"

  4. Send to the LLM like any other prompt.

  5. Return the answer, optionally with citations pointing back to the source documents.

A Worked Example

Let's walk through a real scenario: a RAG-powered help-desk bot for a fictional company, "Acme Software."

Indexing (done once): The team takes all of their help articles (let's say 5,000 articles in Confluence), runs them through the indexing pipeline.

Each article is chunked into roughly 1,000-character pieces.

Each chunk is embedded and stored in Pinecone.

Metadata includes article ID, title, and last-updated date.

A user asks: "Why am I getting Error 503 when I try to log in?"

Query pipeline:

  1. The user's question is embedded into a vector.

  2. Pinecone returns the top 5 most similar chunks. Three of them happen to be from an article titled "Common Login Errors and Solutions." One is from "What to Do When Acme Software Is Down." One is barely relevant.

  3. The system constructs a prompt:

    "You are Acme Software's help-desk assistant. Use the following context to answer the user's question. Always cite the article you got information from.

    Context:
    [Chunk about Error 503 specifically]
    [Chunk about authentication errors generally]
    [Chunk about checking service status]
    ...

    User question: Why am I getting Error 503 when I try to log in?"

  4. The LLM (any current model, such as Claude, GPT or Gemini) reads the context and produces:

    "Error 503 typically indicates that the Acme authentication service is temporarily unavailable. You can check our status page at status.acme.com to confirm. If the service is operational, try clearing your browser cache and signing in again. [Source: Common Login Errors and Solutions]"

The user gets an accurate answer, grounded in real Acme documentation, with a citation they can verify.

None of this required retraining the LLM.

If the help articles are updated, the next indexing run picks up the changes.

Keep going with a free account

A free account saves your progress across lessons and lets you pick up where you left off.