# What is RAG (retrieval-augmented generation)? A simple explanation · AI in Bed

https://www.aiinbed.com/blog/what-is-rag · Published 2026-11-25

**Short answer:** RAG, short for retrieval-augmented generation, is a way to make an AI answer from specific documents instead of only from memory. When you ask a question, the system first searches a collection of text, such as your company's help pages, picks the most relevant passages and pastes them into the prompt. The language model then writes its answer from those passages, often with citations, so answers are more current, more accurate and easier to check.

### RAG in one sentence

A large language model on its own answers from what it absorbed during training, like a student taking a test from memory. [RAG](https://www.aiinbed.com/glossary/rag) turns that into an open-book test: before answering, the AI looks up the right pages and reads them.

The idea and the name come from a 2020 research paper by Patrick Lewis and colleagues at Facebook AI Research. Today it's the most common way companies connect chatbots to their own documents.

### How RAG works, step by step

There are two phases. First you prepare your documents once, then every question runs a quick search.

1. **Split** your documents into short chunks, say a few paragraphs each.
2. **Embed** each chunk: turn it into a list of numbers that captures its meaning. These are [embeddings](https://www.aiinbed.com/glossary/embedding), and similar meanings get similar numbers. They're stored in a search index, often called a vector database.
3. **Retrieve.** When a question comes in, embed it the same way and find the chunks whose numbers are closest. Many systems also mix in ordinary keyword search.
4. **Augment.** Put the best few chunks into the [prompt](https://www.aiinbed.com/glossary/prompt), with an instruction like "answer using only these sources and cite them".
5. **Generate.** The [LLM](https://www.aiinbed.com/glossary/llm) writes the answer from the passages in front of it.

Want the details of step 2? Read [what embeddings are](https://www.aiinbed.com/blog/what-are-embeddings). You can also try a small retriever yourself in the [RAG and agents lesson](https://www.aiinbed.com/learn/advanced/rag-and-agents).

### Why RAG is so popular

- **Fresh information.** Models stop learning at their training cutoff. RAG can search documents updated this morning.
- **Private knowledge.** Your internal wiki, contracts or support tickets were never in the training data. RAG lets the model use them without retraining.
- **Fewer made-up answers.** A model that reads the source is less likely to invent one. See [why AI hallucinates](https://www.aiinbed.com/blog/why-does-ai-hallucinate).
- **Citations.** Because the system knows which passages it used, it can show them, so people can check.
- **Cheap to update.** Add a document to the index and it's searchable straight away. No training run needed.

### Examples of RAG

- A **customer support bot** that answers from the help centre and links the article it used.
- An **internal assistant** that searches HR policies, engineering docs or past tickets.
- **AI search engines** that search the web, read the top pages and write a summary with links.
- A **legal or medical research tool** that only answers from an approved library of documents.

### Where RAG goes wrong

RAG is only as good as its search. If the right passage isn't retrieved, the model can still guess. Common problems:

- **Bad chunks.** Split a table or a list in half and neither half makes sense on its own.
- **Wrong passages.** The question uses different words from the document, or many documents look similar.
- **Too much context.** Stuffing in dozens of passages can bury the useful one. More isn't always better, even with a big [context window](https://www.aiinbed.com/glossary/context-window).
- **Hidden instructions.** A retrieved document can contain text that tries to hijack the model, a form of [prompt injection](https://www.aiinbed.com/glossary/prompt-injection).

> Test a RAG system on real questions with known answers. Check two things separately: did it retrieve the right passage, and did it answer correctly from it?

### RAG vs fine-tuning

RAG gives a model **knowledge** at the moment it answers. [Fine-tuning](https://www.aiinbed.com/glossary/fine-tuning) changes the model itself, which is better for teaching a **style, format or skill**. For facts that change, RAG is usually the better first choice. We compare all the options in [fine-tuning vs RAG vs prompt engineering](https://www.aiinbed.com/blog/fine-tuning-vs-rag-vs-prompt-engineering).

When RAG is put in a loop, where the model decides what to search for next, it becomes an [AI agent](https://www.aiinbed.com/blog/what-is-an-ai-agent).

### Key takeaways

- RAG = search first, then generate: retrieve relevant text, add it to the prompt, answer from it.
- It lets an AI use private or recent information it was never trained on.
- It cuts down on hallucinations and makes answers checkable with sources.
- Most RAG systems find passages by meaning using embeddings, not just keywords.

### Questions

**What does RAG stand for in AI?**

RAG stands for retrieval-augmented generation. The AI retrieves relevant text from a collection of documents, adds it to the prompt, and generates an answer based on it.

**Is RAG better than fine-tuning?**

For giving a model up-to-date or private facts, RAG is usually better: it's cheaper, easy to update and can cite sources. Fine-tuning is better for changing how a model behaves, such as its style, format or a narrow skill. Many systems use both.

**Does ChatGPT use RAG?**

When ChatGPT or similar assistants search the web or read files you upload before answering, they are using a form of retrieval-augmented generation.

**What is a vector database in RAG?**

A vector database stores the embeddings of your document chunks and quickly finds the ones closest in meaning to a question. It's the search engine part of a RAG system.

### Sources

- [Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks](https://arxiv.org/abs/2005.11401) by Lewis et al., 2020
- [Hugging Face LLM Course](https://huggingface.co/learn/llm-course) by Hugging Face
- [The Illustrated Word2vec](https://jalammar.github.io/illustrated-word2vec/) by Jay Alammar
