What Is RAG

Updated · 5 min read
mediumPython 3.13airagretrievalembeddingsllm

Retrieval-augmented generation (RAG) is a way of answering questions in which the system first retrieves relevant passages from your own documents and then has a model generate an answer from those passages. It is used when answers must come from information the model never saw in training: internal policies, product manuals, school rules or yesterday's update.

A model doesn't know your organization's documents. RAG doesn't teach it them; it hands the model the right page at the moment of the question, like an open-book exam.

The Problem RAG Solves

Srihitha, a teacher, is taking students to a science fair in October and asks: "Can I claim my hotel for the trip?" The answer is in the school district's staff travel reimbursement policy, a document no public model has ever read.

Hand the model the right page, then cite it
Without RAGWith RAG
What the model knowsIts training data onlyTraining data plus the retrieved passages
Answer about your policyA general guess, sometimes wrongBased on your document
Can show a sourceNoYes, the document it used
When the policy changesStill the old or general answerUpdate the document; answers follow

The RAG Pipeline

  1. Question: a person asks in their own words.
  2. Search: the system searches your documents, usually with embeddings (see the previous chapter).
  3. Retrieve: it takes the few most relevant passages.
  4. Augment: it sends those passages to the model with the question and rules such as "answer only from these".
  5. Generate: the model writes the answer.
  6. Cite: the answer shows which documents it came from.

Where RAG Is Used

UseDescription
Policy and HR assistantsIt is used to answer staff questions from internal handbooks
Customer supportIt is used to answer from product manuals and help articles
School and government servicesIt is used to answer fee, admission and form questions from official documents
Research and legal workIt is used to find and quote relevant passages from large collections

Common Mistakes

Expecting RAG to fix bad documents. Outdated or conflicting documents produce outdated or conflicting answers.

Skipping the "answer only from these" rule. Without it, the model may mix in general knowledge.

Hiding the sources. People need to see where an answer came from to trust it and check it.

Interview Corner

What is retrieval-augmented generation?

A pattern where relevant passages are retrieved from your documents and given to a model, which answers from them and cites them. It grounds answers in information the model wasn't trained on.

Does RAG make answers correct?

No. It makes them grounded in retrieved text, which helps a lot, but wrong retrieval or wrong documents still produce wrong answers. Test retrieval and keep sources visible.

Practice

Exercise: map a RAG idea. Pick a document set you know, such as a club's rules or a product manual. Write five questions a person might ask, find each answer in the documents by hand, and note any question the documents can't answer.

Check your understanding:

  1. What does the "retrieval" step do?
  2. Why can't a model answer from a private policy without RAG?
  3. What happens when the retrieved passage is wrong?

Quick check: what is RAG

4 questions
1What does RAG stand for?
2Why couldn't a public model answer Srihitha's hotel question correctly on its own?
3What does RAG guarantee?
4Which step shows people where the answer came from?

Key Takeaways

Quick reference

StepWhat happens
RetrieveFind the closest passages
AugmentAdd them to the prompt
GenerateThe model answers from them
CiteShow the source documents

Was this tutorial helpful?

Lesson 95 of 186