
Retrieval-augmented generation, or RAG, is a method where an AI system first searches your own documents for relevant passages, then writes an answer using only that material. It reduces made-up answers, lets you cite sources and keeps your content up to date without retraining a model. It does not remove errors entirely, so testing and access control still matter.
Key takeaways
- RAG means search first, then generate: the model answers from retrieved passages rather than from memory.
- Use it when answers must come from your changing, private content; fine-tuning is usually the wrong first step.
- Quality depends on clean documents, sensible chunking and good retrieval more than on the model.
- Access control is essential: a user must only retrieve documents they are allowed to see.
- Build a set of test questions and review failures before and after every change.
RAG in plain English
A language model knows what it learned in training. It does not know your internal policies, price lists or product manuals, and it may guess when asked. With RAG, the system behaves more like an open-book exam. When someone asks a question, it looks up the most relevant pieces of your documents, adds them to the prompt and asks the model to answer from those pieces, ideally with references.
This pattern is the basis of many support assistants and internal knowledge tools. It is also why our guide on AI chatbots for customer support recommends grounding replies in approved content.
RAG vs fine-tuning vs plain prompting
These three approaches solve different problems.
Plain prompting
You paste the needed text into the prompt yourself. This is fine for a one-off task or a short document, and it needs no engineering. It does not scale when you have many documents.
Fine-tuning
You train a model further on examples so it changes its style or behaviour. This is good for teaching a format, tone or specialised task. It is a poor way to add facts that change often, because updating knowledge means retraining, and the model may still misquote.
RAG
You keep documents outside the model and retrieve them as needed. This suits knowledge that is large, private and changing, and it lets you show where an answer came from. Many real systems use RAG first, and consider fine-tuning only for stubborn behaviour problems.
The parts of a RAG pipeline
1. Collect and clean documents
Gather the sources: help articles, PDFs, wikis, policy documents and spreadsheets. Remove duplicates, outdated versions and navigation clutter. Scanned documents may need text recognition. Garbage in, garbage out applies strongly here.
2. Chunking
Documents are split into smaller pieces, called chunks, so the system can retrieve just the relevant part. Chunks that are too small lose context; chunks that are too large dilute the match and waste space in the prompt. Splitting along headings and keeping titles with each chunk usually works better than cutting at a fixed length.
3. Embeddings and vector search
An embedding is a list of numbers that represents the meaning of a piece of text. Similar meanings produce similar numbers. The system stores embeddings in a vector database or a database with vector support. When a question arrives, it is converted the same way, and the closest chunks are retrieved. Many systems combine this with ordinary keyword search, because exact names, codes and numbers are matched better by keywords.
4. Reranking
The first search returns a rough list of candidates. A reranker reads the question with each candidate and orders them by relevance, so the best passages reach the prompt. It adds a little time but often improves quality.
5. Prompting with sources
The prompt includes the question, the retrieved passages and clear instructions: answer only from the sources, say so if the answer is not there, and quote or cite the source. This is where you also set tone and format.
6. Citations and review
Show users which documents supported the answer, with links. This builds trust and lets people check. It also helps your team spot bad sources.
Access control: the part people forget
If your assistant can search every document, it can reveal confidential material to the wrong person. Finance files, HR records and client contracts must not appear in answers for everyone.
- Store permission information with each chunk, such as the team, role or document owner.
- Filter retrieval by the signed-in user's permissions before anything reaches the model.
- Do not rely on the prompt to hide information; instructions are not security.
- Test with accounts that have different rights, and try to extract restricted content on purpose.
Connecting AI to business systems carries similar risks, which we cover in connecting AI models to your CRM safely.
Keeping content fresh
Answers are only as current as the index. Decide how updates flow in:
- Re-index changed documents on a schedule or when they are edited.
- Remove deleted or superseded documents promptly.
- Record document dates and, where useful, show them in citations.
- Assign an owner to each content area, so someone is responsible when a policy changes.
Evaluating a RAG system
Do not judge a RAG system by a few impressive demos. Build a test question set.
- Collect real questions from staff or customers, and add awkward ones.
- For each, write down the correct answer and the document that contains it.
- Check two things separately: did retrieval find the right passage, and did the answer use it correctly?
- Include questions that have no answer in your documents; the system should decline.
- Re-run the set after every change to chunking, models, prompts or content.
Separating retrieval from generation tells you where to fix things. If the right passage was never retrieved, improve chunking or search. If it was retrieved but misused, improve the prompt or the model.
Common failure modes
- Wrong chunk retrieved. The question matches similar but irrelevant text.
- Answer split across chunks. Needed context is lost at chunk boundaries.
- Outdated sources. Old and new versions of a policy both exist, and the system quotes the wrong one.
- Confident misreading. The model summarises a passage inaccurately.
- Table and PDF problems. Poorly extracted tables produce nonsense.
- Over-trust. Staff treat the answer as authoritative without checking the source.
Privacy and vendor choices
Your documents may be sensitive, so check where they go. Ask each vendor where data is stored and processed, whether it is used for training, how long it is retained and what security controls apply. Options range from hosted services to models running in your own cloud account. The right choice depends on your data, budget and legal obligations, which vary by country and sector, so involve a qualified adviser for regulated data. Our AI and machine learning team and API developers can help with architecture, and the broader build or buy question applies here too.
A worked example
Imagine a mid-sized company that wants an internal policy assistant so staff can ask, "How many days of notice do I need for leave?" The team collects its leave, travel and expense policies, removes old versions and splits each by heading. Each chunk keeps its policy title and effective date. The assistant retrieves the best passages, answers from them and links to the source document. Managers can see more documents than other staff, so retrieval filters by role. Before launch, HR writes fifty test questions, including some the documents cannot answer, and reviews every failure. The result is a helpful tool that says "I could not find that" rather than guessing.
FAQ
What does RAG stand for in AI?
It stands for retrieval-augmented generation. The system retrieves relevant information from a knowledge source and then uses a language model to generate an answer based on it.
Does RAG stop AI hallucinations?
It reduces them by giving the model real source text, but it does not eliminate them. The model can still misread a passage or answer from the wrong one, so citations and testing remain necessary.
Do I need a vector database for RAG?
Not always. Small collections can work with simple search or a database that supports vectors. A dedicated vector store becomes worth considering as the collection or traffic grows.
Is RAG better than fine-tuning?
They answer different needs. RAG suits changing, private knowledge, while fine-tuning suits teaching a behaviour or style. Many teams start with RAG and add fine-tuning only if needed.
Related reading
- AI Chatbots for Customer Support: What Works, What Backfires
- Connecting AI Models Like Gemini and Claude to Your CRM Safely
- AI Usage Policy for Small Businesses: A Simple Starting Point
Next steps
Pick one document set that is small, clean and valuable, write thirty real questions and try a simple prototype before committing to a larger build. If you want help scoping or building an assistant that answers from your own content, contact us.



