Tech Terms Explained Open in the app →

Retrieval-Augmented Generation

AI & Machine Learning · Intermediate · 5 min read

What is it?

RAG is a technique that gives a language model relevant documents to read at question time, so its answers are grounded in real, up-to-date information.

Explain like I'm 5

RAG is like letting a student take an open-book exam: instead of answering from memory alone, the model first looks up the right pages and then answers using them.

Why was it created?

LLMs can be out of date and may invent facts. RAG was created to ground answers in your own or current data without retraining the model.

Where is it used?

  • Chatbots over company docs
  • Customer support assistants
  • Search with natural-language answers
  • Question-answering over private data

Why should developers care?

RAG is the most common way teams build accurate AI assistants over their own documents, so it's a key pattern for AI features.

How does it work?

Your documents are split into chunks and stored as embeddings in a vector database. At question time, the system retrieves the most relevant chunks and includes them in the prompt so the model answers using that context.

Real-world example

A support bot answers a policy question by first retrieving the exact relevant section from the company handbook, then summarizing it for the user.

Common use cases

  • Answering questions over private documents
  • Keeping answers current without retraining
  • Reducing hallucinations
  • Citing sources in responses

Advantages

  • Grounds answers in real data
  • No model retraining needed
  • Easy to update by changing documents
  • Can cite sources

Disadvantages

  • Quality depends on retrieval
  • Adds infrastructure (vector store, pipeline)
  • Irrelevant retrieval can mislead the model
  • Latency from the extra lookup

When should you use it?

When you need an LLM to answer accurately over specific or changing information.

When should you avoid it?

For general tasks where the model's built-in knowledge already suffices.

Alternatives

Fine-tuning the model on your dataPutting all context directly in the promptTraditional search

Related terms

Large Language ModelEmbeddingsVector DatabaseHallucinationContext Window

Interview questions

Beginner

  • What does RAG stand for?
  • Why give a model documents at question time?

Intermediate

  • What role does a vector database play in RAG?
  • How does RAG reduce hallucinations?

Senior

  • How would you improve retrieval quality?
  • When would you choose RAG over fine-tuning?

Common misconceptions

  • "RAG retrains the model" — it doesn't; it just supplies relevant context at query time.
  • "RAG eliminates hallucinations" — it reduces them, but poor retrieval can still mislead the model.

Fun facts

  • RAG stands for Retrieval-Augmented Generation.
  • It relies on embeddings to find text by meaning rather than exact keywords.

Timeline

  • 2020 — Retrieval-augmented generation introduced in research

Learning resources

Quick summary

RAG retrieves relevant documents and feeds them to an LLM at question time, grounding answers in real, current data without retraining.

Cheat sheet

  • Retrieve relevant docs, then generate
  • Grounds answers in your data
  • Uses embeddings + a vector database
  • Reduces but doesn't erase hallucinations

If you remember only one thing

RAG gives an LLM the right documents to read before answering, grounding it in real data.