Large language models are fluent, but they do not know your price list, your HR policy or last week's product update. Ask them anyway and they may produce a confident, plausible and wrong answer. Retrieval-augmented generation, usually shortened to RAG, is the most common way to fix that: before the model answers, the system looks up relevant passages in your own content and asks the model to answer from those passages only.
RAG sits behind most internal knowledge assistants, customer support bots and document question-answering tools our generative AI development team builds. This guide explains how it works in plain terms, when it is the right choice, and what goes wrong in practice.
Why language models need retrieval
A language model's knowledge is fixed at training time and covers public data, not your private documents. You could paste every document into each prompt, but that quickly becomes slow and expensive, and models handle very long inputs less reliably than short, relevant ones. RAG solves this by selecting only the few passages that matter for each question. It brings three business benefits:
- Current answers: update a document and the assistant uses the new version, without retraining anything.
- Traceability: each answer can cite the passages it used, so users and reviewers can check it.
- Control: you decide which sources are searchable and who may see which documents.
How RAG works, step by step
- 01Ingest
Collect documents from sources such as file shares, wikis, helpdesks and databases, and extract clean text.
- 02Chunk
Split each document into passages small enough to be specific but large enough to keep their meaning.
- 03Embed
Convert each chunk into a vector that captures its meaning, and store it with metadata in a vector index.
- 04Retrieve
Turn the user's question into a vector, find the closest chunks, filter by permissions and re-rank.
- 05Generate
Send the question plus retrieved chunks to the model with instructions to answer only from them and cite sources.
Steps 1 to 3 run when content changes; steps 4 and 5 run on every question.
DivTech SystemIngest is where messy reality appears: scanned PDFs, tables, slides and duplicate versions of the same policy. Chunking choices matter more than most teams expect; splitting a procedure halfway through leaves both halves meaningless. Embedding turns text into numbers so that 'refund window' and 'how long do I have to return an item' end up close together even though they share no words. The vectors live in a vector index, which can be a dedicated vector database or a vector extension in a database you already run; our guide to SQL versus NoSQL covers where vector stores fit.
At question time, retrieval often combines vector search with keyword search, because exact terms such as product codes and error messages are better matched literally. A re-ranking step then orders the candidates by relevance. Finally, generation asks the model to answer using only the supplied passages, to cite them, and to say so when the answer is not there.
RAG or fine-tuning?
Fine-tuning means further training a model on your examples so it behaves differently. Leaders often ask which one they need. They solve different problems, and many mature systems use both.
- Answers from your current documents
- Content updates take effect without retraining
- Can cite sources for every answer
- Permissions can be enforced per user
- Quality depends on retrieval and content quality
- Teaches style, format, tone or a narrow task
- Needs curated training examples
- Must be retrained when requirements change
- Does not reliably memorise facts
- Cannot show where an answer came from
verdictStart with RAG for knowledge questions; consider fine-tuning later if output format or tone still falls short.
Common failure modes and how to fix them
When a RAG assistant gives a bad answer, the model is often not the culprit. Trace the failure back through the pipeline first.
| Failure | What users see | Typical fix |
|---|---|---|
| Poor extraction | Answers miss content from tables, scans or slides | Better parsing, OCR, table-aware extraction |
| Bad chunking | Half-answers, steps missing from procedures | Chunk by headings or sections; add overlap and titles to chunks |
| Retrieval misses | 'I don't know' when the answer exists | Hybrid keyword and vector search, re-ranking, query rewriting |
| Outdated or duplicate sources | Contradictory or old answers | Source ownership, versioning, removing superseded documents |
| Ungrounded generation | Answers that go beyond the sources | Stricter instructions, mandatory citations, answer checks |
| Permission leaks | Users see content they should not | Filter by the user's access rights at retrieval time |
What a production RAG system also needs
A demo can be built in days. A system people trust needs more:
- An evaluation set of real questions with expected answers and sources, run after every change. Our guide to testing AI and LLM applications covers how to build one.
- Content ownership: someone responsible for each source, and a process to retire outdated documents.
- Incremental sync so changed documents are re-indexed automatically.
- Feedback capture in the interface, so wrong answers are reported and reviewed.
- Logging and monitoring of questions, retrieved sources and answers, with privacy rules for what is stored.
- A sensible model choice for quality, cost and data residency, covered in how to choose an LLM.
The foundation underneath all of this is well-organised data. If your documents are scattered across drives with no owners, start with our guide to an AI-ready data foundation, and consider a data and database modernisation step before indexing everything.
How to measure a RAG system
Measure retrieval and generation separately, because they fail for different reasons and are fixed by different people. Useful measures include:
- Retrieval hit rate: for each test question, was the passage containing the answer among the top results?
- Groundedness: is every statement in the answer supported by the retrieved passages?
- Correctness and completeness: does the answer match the expected answer, including conditions and exceptions?
- Honest refusals: when the answer is not in the content, does the assistant say so instead of guessing?
- Response time and cost per answer, which grow with the number and size of retrieved chunks.
If retrieval hit rate is low, work on extraction, chunking and search before touching prompts or changing models. If retrieval is good but answers are wrong, the generation step, the instructions or the model is the place to look.
When RAG is not the answer
RAG answers questions from text. It is not the right tool when the answer requires calculation over live structured data, such as 'what were sales in Pune last month?'. That calls for the model to query a database or API through a controlled tool, which moves you towards agents; see AI agents versus chatbots. RAG also cannot fix content that is wrong, contradictory or missing; it will faithfully retrieve the mistake.
Getting started
Pick one well-bounded knowledge domain, such as product documentation, internal policies or course material in an e-learning platform, collect fifty or so real questions, and build a pilot measured against them. Most pipelines are built in Python, which has mature tooling for parsing, embedding and evaluation. You can see a working assistant in our live AI agent demo. When you are ready to scope your own, request a quote and DivTech will review your content sources and recommend an architecture.
Frequently asked questions
What does RAG stand for?
Retrieval-augmented generation. The system retrieves relevant passages from your own content and gives them to a language model, which generates an answer based on those passages.
Does RAG stop hallucinations completely?
No, but it reduces them substantially when retrieval works well and the model is instructed to answer only from the supplied sources and to admit when the answer is missing. Citations and regular evaluation help catch the remaining errors.
Do we need a vector database for RAG?
You need a vector index, but it does not have to be a separate product. Many databases now offer vector search extensions, which can be simpler to operate if you already run them.
Is our data used to train the model in a RAG system?
Not by RAG itself: your documents are passed as context at question time, not used for training. Whether a hosted model provider may retain or use that data depends on its terms, so check data-use and retention settings when choosing a provider.