Why RAG: what a model doesn't know, and answering from your documents
RAG & Vector Search · 10 questions
Short notes
Key idea
A model only knows its training data. Retrieval-augmented generation (RAG) finds the relevant passages in your own documents and puts them in the prompt, so the model answers from them and can cite where the answer came from.
Syntax
- Index (once): split documents into chunks → embed each chunk → store vectors with the text.
- Retrieve (per question): embed the question → find the most similar chunks.
- Generate: prompt = instructions + retrieved chunks + question → answer with sources.
Example
"What's the return window for electronics?" The shop's policy PDF isn't in any model's training data. RAG retrieves the chunk "Electronics can be returned within 7 days of delivery…", and the model answers "7 days from delivery (Returns policy, section 3)".
Traps
- RAG fails silently when retrieval fails: the wrong chunks lead to a confident wrong answer.
- Tell the model to say "I don't know" when the context doesn't contain the answer.
- Pasting whole documents into the prompt is costly and dilutes attention; retrieve only what's relevant.
- RAG is for knowledge; for style or format, use prompting or fine-tuning.
- Stale index: when documents change, re-index.
Want the full lesson with step-by-step examples, a project and a certificate? RAG & Vector Search course, ₹180 →
- Question 1easy
What does RAG stand for?
- Question 2easy
In what order does a RAG system work for each question?
- Question 3medium
What does this print?
import re answer = "Returns are allowed within 10 days [6]. Refunds start within 2 days [7]. Gift cards can't be returned [6]." print(sorted({int(x) for x in re.findall(r"\[(\d+)\]", answer)})) - Question 4medium
A company has 40,000 policy documents that change every week. How should a chatbot answer from them?
- Question 5medium
Retrieval always returns the top 3 articles, even for "Do you offer EMI?", which no article answers. What stops a made-up answer?
Why RAG: what a model doesn't know, and answering from your documents
Why RAG: what a model doesn't know, and answering from your documents
Why RAG: what a model doesn't know, and answering from your documents
Why RAG: what a model doesn't know, and answering from your documents
Why RAG: what a model doesn't know, and answering from your documents
5 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.