A general AI model knows a lot about the world but nothing about your return policy, your product catalog, your internal procedures, or last month's meeting notes. Retrieval-augmented generation, usually called RAG, is the most common way to fix that. Instead of hoping the model remembers the right facts, a RAG system looks up the relevant information from your own content and hands it to the model along with the question. This article explains how RAG works and what it takes to do it well.
The core idea
RAG combines two steps:
- Retrieval: find the passages from your documents that are most relevant to the question.
- Generation: give those passages to the model with instructions to answer using them.
It is the automated version of something you can do by hand: paste the relevant policy into a chat and ask the AI to answer from it. RAG does the finding and pasting automatically, across collections far too large to paste, for every question.
Why RAG is so widely used
- Accuracy: answers are grounded in your actual content, which greatly reduces invented answers.
- Current information: update a document, and the next answer reflects it. No retraining needed.
- Citations: the system can show which documents an answer came from, so people can check.
- Access control: retrieval can respect permissions, so people only get answers from documents they are allowed to see.
- Cost-effective: it works with standard models and avoids the expense of training.
- Works with any capable model: you can switch models without rebuilding your knowledge base.
How a RAG system works
Preparation, done ahead of time
- Collect content: documents, web pages, help articles, PDFs, manuals, FAQs, policies, and similar material.
- Clean and convert it into text the system can process. See Preparing your documents for AI.
- Split it into chunks: smaller passages, often a few paragraphs each, so the system can retrieve just the relevant parts rather than whole documents.
- Create embeddings: each chunk is converted into a list of numbers that represents its meaning. See Embeddings explained.
- Store them in a searchable index, often a vector database, along with the original text and details like the source document, date, and permissions.
At question time
- A user asks a question, such as "Can I return a sale item after 30 days?"
- The question is embedded using the same embedding model.
- The system searches for chunks whose meaning is closest to the question. Many systems combine this meaning-based search with traditional keyword search, called hybrid search, to catch exact terms like product codes.
- Results may be reranked by a second model that scores which passages best answer the question.
- The top passages are added to the prompt with instructions like "Answer using only the information below. If the answer is not there, say so. Cite the source."
- The model generates the answer, ideally with citations to the source documents.
Where RAG works well
- Customer support assistants that answer from your help center, policies, and product information.
- Internal knowledge assistants for procedures, HR policies, and technical documentation.
- Website search and Q&A that answers questions from your own pages.
- Document research across contracts, reports, or case files.
- Sales and service support that pulls product specs and pricing rules quickly.
Common pitfalls and how to avoid them
Poor source content
RAG can only be as good as the documents it searches. Outdated, contradictory, or poorly written content produces poor answers. Clean up and maintain the knowledge base first.
Bad chunking
Chunks that are too small lose context; chunks that are too large dilute relevance and add cost. Splitting in the middle of a table or a list of steps can break meaning. Split along natural boundaries such as headings and sections, and test.
Retrieval misses
If the right passage is not retrieved, the model cannot use it. Causes include vocabulary mismatches, such as customers saying "money back" while documents say "refund," questions that need information from several documents, and exact codes that meaning-based search handles poorly. Hybrid search, reranking, and rewriting the user's question before searching all help.
The model ignores or goes beyond the sources
Even with good passages, a model may add information from its general knowledge or misread the text. Clear instructions to use only the provided content, requiring citations, and testing reduce this.
Missing access controls
If every document is searchable by everyone, a RAG assistant may reveal confidential information to the wrong person. Apply permissions at retrieval time, enforced by the system rather than by instructions to the model.
Prompt injection through documents
If the knowledge base includes content from outside sources, such as customer emails or web pages, it may contain hidden instructions. See Prompt injection explained.
No evaluation
Without testing, you will not know how often the system answers correctly. Build a set of real questions with known correct answers and check results regularly, especially after changes.
What you need to build RAG
- Content in a reasonably clean, current state.
- An embedding model to convert text into vectors.
- A search index such as a vector database, or a search engine with vector support.
- A language model to write answers.
- Application logic to tie it together, apply permissions, and present answers with citations.
There are several ways to get there:
- Built-in features: many AI chat products let you upload files to a project or custom assistant and will do simple RAG automatically. This is a great starting point for small, non-sensitive collections.
- Managed services: cloud platforms and model providers offer managed retrieval and knowledge base services.
- Open-source frameworks: developers can assemble RAG systems from open-source libraries and databases, including fully self-hosted setups using local models.
- Custom builds: for customer-facing assistants or systems that must respect permissions and connect to business systems, a custom application is often the right choice. Napa AI builds this kind of feature as part of its custom web applications, and many developers and agencies do similar work.
RAG versus other approaches
RAG is not the only way to give AI your knowledge. Very long context windows can sometimes hold all the relevant documents at once, and fine-tuning can teach a model a style or specialized behavior. Each has a place. See Choosing between RAG, fine-tuning, and long context and Fine-tuning explained.
Key takeaways
- RAG finds relevant passages from your content and gives them to the model to answer from.
- It improves accuracy, keeps answers current, supports citations, and works with any capable model.
- Quality depends on clean content, good chunking, effective retrieval, and clear instructions.
- Enforce access controls at retrieval time and test with real questions.
- Start with built-in file features for small collections, and move to managed or custom systems as needs grow.