Skip to content
Artificial Intelligence

What Is Retrieval-Augmented Generation (RAG)? A Plain-English Guide

Retrieval-augmented generation lets AI models answer using your own documents instead of memory alone. Here is how RAG works, when to use it and where it fails.

  • Published
  • Updated
  • 5 min read
Library bookshelves connected by glowing fiber-optic strands to a server rack, illustrating how RAG links documents to an AI model
Library bookshelves connected by glowing fiber-optic strands to a server rack, illustrating how RAG links documents to an AI model. AI-generated illustration.

Key takeaways

  • RAG retrieves relevant documents first, then has the language model answer using them.
  • It keeps answers current and grounded in your own data without retraining the model.
  • Most RAG quality problems come from retrieval and source data, not from the language model.
On this page
  1. The short definition
  2. Why RAG matters
  3. How a RAG pipeline works, step by step
  4. 1. Prepare the documents
  5. 2. Create embeddings
  6. 3. Store and index
  7. 4. Retrieve at question time
  8. 5. Re-rank (optional but valuable)
  9. 6. Generate the answer
  10. RAG vs fine-tuning vs long context
  11. Real-world uses
  12. Common reasons RAG projects underperform
  13. Getting started
  14. Conclusion

Large language models (LLMs) are impressive writers, but they have two well-known weaknesses: their knowledge stops at a training cut-off, and they sometimes state things that are not true with complete confidence. Retrieval-augmented generation (RAG) is the most widely used technique for addressing both problems. Instead of relying only on what the model memorised during training, a RAG system looks up relevant information first and hands it to the model along with the question.

This guide explains how RAG works, what it is good for, and the practical mistakes that cause RAG projects to disappoint.

The short definition

Retrieval-augmented generation is a pattern with two steps:

  1. Retrieve: search a collection of documents for passages relevant to the user's question.
  2. Generate: give those passages to a language model and ask it to answer using them.

The term comes from a 2020 research paper by Patrick Lewis and colleagues, which combined a neural retriever with a text generator and showed better results on knowledge-heavy tasks than a generator alone. Today "RAG" is used more loosely for any system that puts retrieved content into an LLM's prompt.

What is Retrieval-Augmented Generation (RAG)? · IBM Technology
A short whiteboard explanation from an IBM Research scientist showing why LLMs need retrieval and how RAG adds sources to answers.

Why RAG matters

An LLM on its own answers from patterns learned during training. That causes three practical problems:

  • Stale knowledge. The model does not know about anything that happened after its training data was collected.
  • No private knowledge. It has never seen your company handbook, your product documentation or your support tickets.
  • Unverifiable answers. Without a source, you cannot easily check whether an answer is correct.

RAG addresses all three. You can update the document collection whenever you like without retraining anything, you can include private material, and you can show users which passages an answer came from.

How a RAG pipeline works, step by step

1. Prepare the documents

Source material such as PDFs, web pages, wiki articles or database records is converted to plain text and split into chunks, typically a few hundred words each. Chunking matters: chunks that are too large dilute the relevant part, and chunks that are too small lose context.

2. Create embeddings

Each chunk is passed through an embedding model, which turns text into a list of numbers (a vector) that captures its meaning. Passages about similar topics end up with vectors that are close together, even if they use different words.

3. Store and index

The vectors are stored in an index that supports fast similarity search. This is the job of vector databases and of vector extensions for ordinary databases. Many systems also keep a traditional keyword index.

4. Retrieve at question time

When a user asks a question, the question is embedded with the same model, and the system finds the chunks whose vectors are most similar. Combining this with keyword search (often called hybrid search) helps with exact terms such as product codes, names and error messages, which pure semantic search can miss.

5. Re-rank (optional but valuable)

A second, more precise model can re-score the top results so that the best few passages go to the LLM. This step often improves answer quality more than switching to a bigger language model.

6. Generate the answer

The retrieved passages are inserted into the prompt with instructions such as "answer using only the sources below and cite them; if the answer is not in the sources, say so." The LLM writes the final response.

RAG vs fine-tuning vs long context

ApproachWhat it changesBest forMain drawback
RAGWhat the model sees at question timeLarge or frequently changing knowledge, citationsAnswer quality depends on retrieval quality
Fine-tuningThe model's weightsConsistent style, format or specialised behaviourCostly to update, does not reliably add facts
Long contextPuts whole documents in the promptSmall document sets, one-off analysisCost and latency grow with document size

These approaches are not mutually exclusive. Many production systems use a fine-tuned or well-prompted model together with retrieval.

Real-world uses

  • Customer support assistants that answer from help-centre articles and link to them.
  • Internal knowledge search over policies, wikis and meeting notes.
  • Developer tools that answer questions about a specific codebase or API documentation.
  • Research assistants that summarise and compare documents while quoting their sources.

Common reasons RAG projects underperform

Most RAG failures are retrieval failures, not model failures. Watch for these:

  • Poor source data. Outdated, duplicated or contradictory documents produce outdated, contradictory answers.
  • Bad chunking. Splitting a table or a step-by-step procedure across chunks breaks its meaning.
  • Semantic search only. Exact identifiers and rare terms are often better matched by keyword search, so consider hybrid retrieval.
  • No evaluation. Build a small test set of real questions with known correct answers and measure whether the right passages are retrieved before tuning the prompt.
  • Missing permissions. If documents have access controls, retrieval must respect them, or the assistant may reveal information to users who should not see it.

Getting started

For a first prototype, keep it simple: pick a small, high-quality document set, use an off-the-shelf embedding model, retrieve the top five or so chunks, and instruct the model to cite sources and admit when the answer is not present. Then collect real user questions and improve retrieval based on what fails. If you are new to working with AI assistants, our guide on writing better prompts covers the instruction-writing side.

Conclusion

Retrieval-augmented generation connects a language model to the information it needs at the moment it needs it. It is cheaper to keep current than fine-tuning, it works with private data, and it makes answers checkable through citations. Its quality, though, is capped by the quality of retrieval, so the most valuable work in any RAG project is cleaning the source data and measuring whether the right passages are being found.

Frequently asked questions

Is RAG the same as fine-tuning?

No. Fine-tuning changes a model's weights by training it on examples. RAG leaves the model unchanged and instead supplies relevant documents in the prompt at question time. RAG is usually the better fit for knowledge that changes often; fine-tuning is better for teaching a consistent style or format.

Does RAG stop AI hallucinations?

It reduces them but does not eliminate them. A model can still misread a retrieved passage, combine sources incorrectly or answer from memory when retrieval misses. Showing citations and testing retrieval quality are the main safeguards.

Do I need a vector database to build RAG?

Not necessarily. Vector databases are common because they make semantic search fast at scale, but small projects can use keyword search, a search engine you already run, or embeddings stored in a regular database.

Sources and further reading

  1. Lewis et al. (2020), Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (arXiv)
  2. Karpukhin et al. (2020), Dense Passage Retrieval for Open-Domain Question Answering (arXiv)