Large language models answer from memory. They were trained on text frozen months ago, so they know nothing about your internal docs, your codebase, or a policy that changed last week. When they lack facts, they fill the gap with fluent guesses. This article answers what is retrieval-augmented generation in plain terms: what it is, how the pipeline works, and where it breaks in real projects.
What is retrieval-augmented generation, in plain terms
Retrieval-augmented generation, usually shortened to RAG, is a pattern for grounding a language model in outside knowledge. Before the model writes an answer, the system searches your own sources for passages relevant to the question, then hands those passages to the model together with the question. The model still writes the answer, but it works from retrieved text instead of memory alone. Give the model the facts first, then let it write. That one change cuts down on invented details, lets answers point at real sources, and lets you update knowledge by updating documents instead of retraining a model. It also keeps private data out of model weights: the documents stay in your own store, and only the retrieved passages reach the model.
How a rag pipeline works, step by step
A typical rag pipeline has five steps. Each one is small on its own, and most failures come from the seams between them.
- Ingest. Load your documents and split them into chunks, usually a few hundred words each, with some overlap so a fact that straddles a boundary still survives.
- Embed. Turn every chunk into a vector with an embedding model, so passages with similar meaning sit close together.
- Store. Put the chunks and their vectors in a vector store, alongside metadata such as source, date, and document title.
- Retrieve. Turn the user question into a vector, find the closest chunks, and pass the top few to the model.
- Generate. Send the question plus the retrieved passages to the model, with an instruction to answer only from that material.
If you want a hands-on version, this walkthrough shows how to build a RAG pipeline in Python from scratch, including chunking and retrieval. The seams matter more than any single step. A chunk that splits a table in half, a query that pulls last year’s version of a doc, or a prompt that lets the model ignore the retrieved text will all produce confident, wrong answers.
Retrieval: vector embeddings, chunking, and search
Retrieval starts with how vector embeddings work. An embedding is a list of numbers that captures what a passage means. Two passages about the same topic end up near each other even when they share no words, which is why a question phrased one way can still find a document written another way.
Chunking decides what the model actually sees. Short chunks retrieve precisely but can lose the sentence that gives a fact its meaning. Long chunks keep context but dilute the match and eat context window space. A common starting point is 500 to 800 characters with overlap, then adjust against real questions. The tradeoffs are covered in detail in this guide to chunking strategies.
The chunks and their vectors live in a vector database, which returns the nearest matches for a query vector. Most teams also mix in keyword search, since exact terms such as product names and error codes are easy for vectors to miss, and some add a reranking step that scores the top candidates a second time before generation.
RAG vs fine-tuning: which one fits your problem
| Aspect | RAG | Fine-tuning |
|---|---|---|
| Updating facts | Update the documents and re-index | Retrain or add new training data |
| Private data | Stays in your own store | Baked into model weights |
| Citations | Can point at source passages | No source to point at |
| Behavior and tone | Same base model behavior | Can teach consistent style and format |
| Effort to start | Pipeline plus a vector store | Training data plus a training run |
Pick RAG when your facts change often or when answers must cite sources. Pick fine-tuning when you need a consistent tone, format, or behavior across answers, or when the task depends on patterns the base model never learned. Many teams use both: RAG for facts, fine-tuning for behavior. Fine-tuning a model does not teach it your private docs; it teaches it how to respond.
Where RAG breaks in practice
- Stale index. The docs changed, the index did not, and the model quotes the old version with full confidence.
- Retrieval misses. The right passage exists but the query never finds it, often because the question uses different words than the doc.
- Context ignored. The model gets good passages and still answers from memory, usually because the prompt never told it to stick to the material.
- No citation check. Nobody verifies that the cited passage actually supports the claim, so a real-looking citation hides a wrong answer.
- One bad chunk poisons the answer. A single outdated or incorrect passage in the top results can steer the whole response.
The fix for most of these is boring: keep the index fresh, log which passages were retrieved for each answer, and read a sample of answers every week. If you cannot see what the model saw, you cannot debug what it wrote.
How to tell if your RAG system works
A RAG system needs a fixed test set: 20 to 50 real questions from your users, with the correct answer or the source passage for each. Run the same set after every change to chunking, retrieval, or prompts, and score each answer on two questions: does the retrieved material contain the answer, and does the written answer stay faithful to it? That split tells you whether retrieval or generation is at fault. Human review still matters: read a sample of real answers each week, especially the ones users rated poorly. A practical guide to rag evaluation walks through faithfulness, relevance, and the checks teams actually use.
A minimal RAG setup you can build this week
Start small. Pick 20 to 50 documents you actually get asked about. Chunk them at 500 to 800 characters with overlap, embed them with an off-the-shelf embedding model, and store them in a small vector store. Retrieve the top five chunks per question, send them to the model with an instruction to answer only from that material, and cite the source of each claim. Hosted embedding and model APIs vary in price, so check official pricing before you pick one. Then test with 20 real questions and read every answer. Fix retrieval first: if the right passage never reaches the model, no prompt will save the answer.
That is what is retrieval-augmented generation, end to end: search your docs, hand the best passages to the model, and check the answer against them. RAG is plumbing, not magic, with seams you can inspect. Start small, measure answers against a fixed question set, and fix retrieval before you blame the model. Most RAG projects that fail do so at retrieval, not generation.