SevyDevy

Module 4 · Making AI know your stuff · Lesson 19 of 32

RAG: the open-book exam

12 minFree GenAI course · BeginnerLesson 4.2By Saket Bhatnagar

Researched and drafted with AI, reviewed and edited by Saket Bhatnagar.

In short

  • RAG means: search your documents first, then let the model answer using what it found.
  • It is an open-book exam. The model does not memorise your facts; it looks them up for every question.
  • Good RAG depends on good search. If it fetches the wrong page, you get a confident wrong answer.
Soon

Video lesson · coming soon

What is RAG? The open-book exam, explained

Lala, your AI mentor, will walk you through this lesson in a short animated video. Until then, everything is here to read and try.

  1. 01 A café handbook nobody reads
  2. 02 RAG is an open-book exam
  3. 03 Follow one question
  4. 04 Prepare once, answer every time
  5. 05 Wrong page, confident answer
  6. 06 Next: how the search works

Asha runs Chai & Chapters, a café-bookshop in Bengaluru. Every day the same messages arrive. “Are you open on Monday?” “Can I return a book I got as a gift?” “Is there parking?” Every answer is in her staff handbook.

Nobody reads that handbook except Rohan, the new weekend helper. He keeps it open behind the counter, and when a customer asks something, he flips to the right page, reads it, and answers. Asha wants a chat helper on her website that works like Rohan. That is exactly what RAG is.

RAG is an open-book exam

In the last lesson, you saw that a model cannot know Asha’s handbook by itself. It was never in its training data. Ask a plain chat app about the café’s return rule, and it will guess something that sounds like a typical shop.

A closed-book exam is answered from memory. That is a plain chat model, working from training data only. An open-book exam is answered from the book in front of you. That is RAG.

What the three words mean

The name sounds heavy, but each word is plain.

  • Retrieval: find the parts of your documents that relate to the question. Priya checking the index.
  • Augmented: add those parts to the prompt, so the context window now holds the facts.
  • Generation: the model writes the answer, one token at a time as you learned in module 2, but now while reading your facts.

Here is the key point. The model itself does not change. There is no new training. Asha’s handbook lives outside the model, in a searchable store. If she changes a rule today, tomorrow’s answers use the new rule.

The name comes from a 2020 research paper by a team at Facebook AI Research and university partners. Today it is one of the most common patterns behind company help desks, policy chatbots and “chat with your PDF” tools.

One question, step by step

Let’s follow a single message through Asha’s helper. Kabir, a regular, types: “Can I return a book I got as a gift?” Watch how much happens before the model writes a single word.

Try it yourselfFollow one question through RAGStep through Kabir’s question and see each job the app does: search, pick, build the prompt, then answer.

Zoom out and you will see that RAG is really two jobs. One happens once, before anyone asks anything. The other happens for every single question.

RAG has two jobs: prepare once, answer every time

Before any question, the handbook is cut into chunks and stored in a searchable index. For each question, search picks the best chunks, the prompt carries them, and the model answers from them.

Diagram connections:

  • Café handbook to Search index (chunk, store)
  • Customer question to Retrieve top chunks (search)
  • Search index to Retrieve top chunks (best matches)
  • Retrieve top chunks to Prompt with notes (paste in)
  • Prompt with notes to Model (read)
  • Model to Grounded answer (writes)
  • Café handbook: Opening hours, pets, returns, Wi-Fi, parking and more.
  • Search index: The handbook, cut into chunks and stored so they can be fou…
  • Customer question: Can I return a book I got as a gift?
  • Retrieve top chunks: Scores every chunk against the question and keeps the best…
  • Prompt with notes: Instructions, the chosen chunks and the question, together.
  • Model: The same model as before; it now reads the notes while it w…
  • Grounded answer: An answer built from the handbook, with its source named.

The first job runs once, and again whenever the handbook changes. The second job runs for every message. How the handbook gets cut up, and how search scores meaning, is the whole of the next lesson.

What can go wrong?

RAG is not magic. It moves the problem. Now your answer is only as good as your search. A great model reading the wrong page gives a confident, well-written, wrong answer.

Imagine search had fetched the gift-cards chunk but missed the book-returns chunk. The model reads “Gift cards cannot be refunded” and tells Kabir no. Every sentence sounds right. It is still wrong, and the model followed the rules perfectly.

Common RAG problems and their fixes
ProblemWhat you seeFix
Wrong chunk fetchedA fluent answer about a nearby topicBetter chunking and search; show citations so people can check
Answer not in the documentsThe model fills the gap from memoryTell it to say “not sure”; add the missing document
Outdated documentLast year’s price or ruleKeep the store up to date; remove old versions
Too many chunksA slow, costly prompt with the answer buriedKeep only the top few chunks

Check yourself

Check yourself

In an open-book exam, the index helps you find the right pages. In RAG, which part plays the index?

Pick an answer to see why it is right or wrong.

Check yourself

A customer asks about returning a gift book, and Asha’s helper replies “Gift cards cannot be refunded.” What most likely went wrong?

Pick an answer to see why it is right or wrong.

Remember these three

  1. RAG = search your documents, paste the best parts into the prompt, then generate.
  2. The model is not retrained: update the documents, and the answers update too.
  3. Search quality decides answer quality, so show sources and allow “I’m not sure”.

Questions people ask

What is RAG in simple words?
RAG, or retrieval-augmented generation, is an open-book exam for AI. Before answering, the app searches your documents, pastes the most relevant parts into the prompt, and the model writes its answer from them.
Does RAG stop AI hallucinations?
It reduces them a lot when search finds the right text, but it does not remove them. The model can still misread a chunk, or fill gaps from memory. Clear instructions, citations and testing help further.
Is RAG the same as training a model on my data?
No. RAG leaves the model unchanged and looks up your documents for each question. Training, or fine-tuning, changes the model itself. RAG is usually cheaper, and much quicker to keep up to date.
Do apps that “chat with your PDF” use RAG?
Often, yes. For a short file, an app may paste the whole text into the context window. For long files or many files, it usually searches for the relevant parts first, which is RAG.