Module 10 · RAG · Lesson 21 of 34

The RAG pipeline

Index your documents, retrieve the relevant pieces, and have the model answer from them with sources.

In this lesson · about 20 minutes

  • Describe the indexing and question-time halves of a RAG system
  • Explain how chunk size, overlap and top-k change answers
  • Write a grounded prompt that cites sources and admits gaps

A model does not know your company's policies, your product catalogue or yesterday's meeting notes. Retrieval-augmented generation (RAG) fixes that without retraining: before the model answers, your system looks up the relevant passages and puts them in the prompt.

Ahead of time (indexing):

  1. Load documents: web pages, PDFs, help articles, tickets.
  2. Chunk them into passages of a few hundred tokens.
  3. Embed each chunk and store it with its text and metadata in a vector database (Module 4).

At question time:

  1. Retrieve the top-k chunks most similar to the question (often embedding + keyword search together).
  2. Build the prompt: instructions, the chunks labelled as sources, and the question.
  3. Generate an answer that uses only those sources, with citations.

Try it · simulator

RAG pipeline simulator

The bakery's policy page is split into chunks. Ask a question, tune the chunking and how many chunks to retrieve, and see the prompt and the answer change.

Question→Search the chunks→Top 2 chunks→Build the prompt→Model→Answer + sources
chunk 1score 0.00Bloom Bakery bakes everything fresh each morning in our Riverside kitchen. Our kitchen handles nuts, so no product can be guaranteed nut-free.
chunk 2has the answerscore 0.60 · #1We deliver Monday to Saturday between 9am and 6pm. There is no delivery on Sundays or public holidays.
chunk 3score 0.00Delivery is free on orders over $50; otherwise delivery costs $6. You can return unused, unopened items within 14 days of delivery.
chunk 4score 0.00A damaged cake must be reported with a photo within 24 hours. Refunds are approved by our staff, usually within two working days.
chunk 5score 0.00Names and messages on cakes can be changed up to 24 hours before delivery. The chocolate celebration cake costs $32 and serves 8 to 10 people.
chunk 6score 0.00Gift cards are valid for 12 months and cannot be exchanged for cash. For allergy questions, call us on 555-0142 before ordering.

Chunks in the index

6

Needed facts retrieved

1 / 1

Prompt size

76tokens

Answer

Grounded

The prompt sent to the model

SYSTEM: Answer using only the sources below. Cite them like (source 1). If the answer is not there, say you don't know.

Source 1: We deliver Monday to Saturday between 9am and 6pm. There is no delivery on Sundays or public holidays.

QUESTION: Do you deliver on Sunday?
“No. There is no delivery on Sundays or public holidays.” Grounded in the retrieved sources, with citations.

Retrieval here scores word overlap, a simple keyword search. Real systems usually combine it with embedding search (Module 4) and may re-rank the results.

A grounded prompt

Answer the customer's question using ONLY the sources below.
Cite the source number after each fact, like (source 2).
If the sources do not contain the answer, say you don't know
and offer to connect them with a person.

Source 1: ...
Source 2: ...

Question: Is the carrot cake safe for a nut allergy?

Three parts do the work: only the sources, cite them, and permission to say "I don't know". Without the last one, the model fills gaps with plausible guesses.

Check your understanding0 of 3 correct

Question 1

1.What problem does RAG solve?

Question 2

2.An answer needs facts from two neighbouring sentences, but chunks are one sentence each and k = 1. What will likely happen?

Question 3

3.Why tell the model it may say “I don't know”?

Quiz score: 0 of 3

Tip: answer every quiz question correctly first.

Written by Noviq Academy in its own words. The simulators are small teaching models that keep the real idea and leave out the scale; their numbers (prices, speeds, scores) are illustrative. Model names, prices and features change quickly, so check your provider's current documentation before you build. Read-aloud uses your device's built-in voices.