What is RAG? It stands for retrieval augmented generation, a technique that improves the answers of a large language model by first retrieving relevant information from a trusted source, such as company documents, and then giving that information to the model to use when it writes its response. Instead of relying only on what the model learned during training, RAG grounds answers in current, private and checkable data. This guide explains what RAG is, how the pipeline works, the role of embeddings and vector databases, how it compares with fine tuning, and how to build a RAG system that is accurate and secure.
Short answer: RAG searches your knowledge base for passages related to a question, adds them to the prompt and asks the language model to answer from them. This reduces hallucination, keeps answers up to date without retraining and lets you show sources.
What is RAG?
The technique was introduced in a 2020 research paper from Meta and collaborators and is described in the retrieval augmented generation article on Wikipedia. It addresses a core limitation of a large language model: its knowledge is frozen at training time and does not include your private data. RAG gives the model an open book to consult, which makes it one of the most practical ways to build business applications of generative AI.
How a RAG pipeline works

| Stage | What happens | Key choices |
|---|---|---|
| Ingest | Collect documents from sources such as wikis, PDFs, tickets and databases | Which sources, how often to refresh, permissions |
| Chunk | Split documents into passages of manageable size | Chunk size and overlap, respect headings |
| Embed | Convert each chunk to a vector that represents its meaning | Embedding model and language coverage |
| Index | Store vectors and metadata in a vector database. See what is a vector database | Index type, metadata filters |
| Retrieve | Find the chunks most similar to the question | Top results, hybrid keyword and vector search, reranking |
| Generate | Give the question and chunks to the LLM and ask it to answer using them | Prompt, citation format, refusal rules |
| Evaluate and monitor | Test accuracy and track real use | Test sets, feedback, drift |
RAG compared with fine tuning and plain prompting
| Aspect | Plain prompting | RAG | Fine tuning |
|---|---|---|---|
| Uses private data | Only what you paste in | Yes, retrieved on demand | Baked into the model |
| Freshness | Manual | Update the index, no retraining | Requires retraining |
| Source citations | No | Yes | Difficult |
| Cost to maintain | Low | Medium | Higher |
| Best for | Simple tasks | Question answering over documents | Style, format and specialised behaviour |
The approaches combine well. Many production systems use RAG for knowledge and a small amount of fine tuning or careful prompting for tone and structure.
Benefits of RAG
- Fewer hallucinations, because the model answers from supplied evidence.
- Answers reflect current information without retraining the model.
- Citations let users verify claims, which builds trust.
- Private data stays in your control and can be permissioned per user.
- Cheaper and faster to build than training a custom model.
How to build a RAG system step by step
- Define the use case and users. For example, support agents searching product documentation or staff asking HR questions.
- Prepare the knowledge. Clean documents, remove duplicates and outdated versions, and add metadata such as owner, date and access level. See data quality.
- Choose chunking and embeddings. Start with passages of a few hundred words that follow document structure, and test alternatives.
- Select a vector store and search method. Combine vector similarity with keyword search and filters, and consider reranking the top results.
- Design the prompt. Instruct the model to use only provided passages, cite them and say it does not know when the answer is missing.
- Evaluate. Build a test set of real questions and check retrieval quality and answer correctness separately.
- Secure and monitor. Respect permissions at retrieval time, log usage and review failures regularly. See what is MLOps.
Common RAG problems and fixes
| Problem | Likely cause | Fix |
|---|---|---|
| Irrelevant answers | Poor retrieval or chunking | Tune chunks, add hybrid search and reranking |
| Missing information | Content not indexed or too fragmented | Expand sources, add overlap, improve metadata |
| Outdated answers | Stale index | Automate refresh and remove old versions |
| Made up details | Prompt allows guessing | Require citations and permit I do not know |
| Data exposure | Retrieval ignores permissions | Filter by user access before retrieval |
| Slow or costly responses | Too many or large chunks | Limit context, cache frequent questions |
Common RAG mistakes
- Indexing messy, duplicated or contradictory documents and expecting good answers.
- Measuring only the final answer, so retrieval faults stay hidden.
- Ignoring access control, which can reveal confidential documents to the wrong person.
- Overstuffing the prompt with irrelevant text.
- No process for keeping content current.
- Launching with no feedback loop from users.
Our AI and machine learning service builds secure RAG assistants, and our data governance service prepares and protects the knowledge they use. Teams that want actions as well as answers should read what is agentic AI.
A worked example: a support knowledge assistant
A software vendor has 3,000 help articles and release notes, and agents often give inconsistent answers. The company builds a RAG assistant. Articles are chunked by heading, embedded and stored with metadata for product, version and language. When an agent asks a question, the system retrieves the top passages, reranks them and asks the model to answer from them with links to the source articles.
The team measures retrieval and answers separately on 300 real questions. Early testing shows that questions about older versions return advice for the latest release, so version metadata is added as a filter. Agent handling time falls and answer consistency rises, and customers receive links to articles instead of long unsourced replies. The knowledge team also gains a dashboard of questions with no good source, which becomes a prioritised list of articles to write.
Advanced RAG techniques
- Query rewriting: rephrase vague questions or break them into sub-questions before searching.
- Hybrid search: combine keyword and vector search to catch exact terms and meaning.
- Reranking: use a second model to order retrieved passages by relevance.
- Parent and child chunks: search small chunks but return larger surrounding context.
- Graph or structured retrieval: use relationships and database queries for facts that are poorly suited to text search.
- Self checks: ask the model to verify that its answer is supported by the passages.
Measuring RAG quality
Good RAG evaluation separates two questions. First, did retrieval bring back the passages that contain the answer? Second, given those passages, did the model answer correctly and cite them? Measuring only the final answer hides which half is failing, and the fixes are very different. Retrieval problems are solved with better chunking, metadata, hybrid search and reranking. Generation problems are solved with clearer prompts, stricter citation rules and sometimes a stronger model.
Build a test set from real questions asked by your users, and write down the expected answer and the source document for each. Re-run the set after every change to content, chunking, embeddings or prompts, and track the score over time. Add a small set of questions that should have no answer in the knowledge base, and check that the system declines politely rather than inventing one. Review a sample of live conversations each week, because real users ask things test sets miss.
Finally, plan the operating model. Someone must own content freshness, someone must review feedback and someone must approve changes to prompts and models. Without owners, a RAG system slowly decays as documents age and products change, and trust is lost quickly once users meet a few wrong answers.
Key takeaways
- RAG retrieves relevant information and gives it to a language model to ground its answer.
- It reduces hallucination, keeps answers current and enables citations.
- Quality depends on clean content, good chunking, strong retrieval and clear prompts.
- Respect permissions at retrieval time and monitor real usage.
- Evaluate retrieval and generation separately and improve both.
Quick glossary
| Term | Meaning |
|---|---|
| Embedding | A vector that represents the meaning of text |
| Chunk | A passage of a document stored and retrieved as a unit |
| Vector database | A store optimised for similarity search |
| Reranking | Re-ordering retrieved results by relevance |
| Grounding | Basing answers on supplied evidence |
Read next: What Is Fine-Tuning? Methods, Data and Costs · What Is Feature Engineering? Techniques and Workflow · What Is Explainable AI? Methods, SHAP and LIME
Frequently asked questions
What is RAG in simple terms?
RAG lets an AI model look things up in your documents before answering, so its response is based on real, current information rather than only its training.
What does RAG stand for?
RAG stands for retrieval augmented generation: retrieve relevant information, then generate an answer using it.
What is the difference between RAG and fine tuning?
RAG supplies knowledge at question time from an updatable source. Fine tuning changes the model itself, which suits style or specialised behaviour more than fresh facts.
Does RAG eliminate hallucinations?
No, but it reduces them. Models can still misread sources, so use citations, clear instructions to refuse when unsure and regular evaluation.
Do I need a vector database for RAG?
Most systems use one for semantic search, though smaller or hybrid setups can use search engines or databases with vector features.
How big should chunks be?
A few hundred words that follow the document structure is a common start. The right size depends on your content and should be tested.
Is RAG secure for confidential data?
It can be, if retrieval respects each user permissions, data stays in approved systems and access and usage are logged and monitored.
How do I evaluate a RAG system?
Create test questions with expected answers, measure whether the right passages are retrieved and whether the final answer is correct and cited, and re-run after changes.
