A retrieval-augmented generation (RAG) system holds up in production when seven things are right: the documents go in clean, the chunks carry enough context to be understood on their own, retrieval combines meaning and keywords, answers cite their sources, access rights are enforced at retrieval time, the index stays current, and all of it is tested on real questions. When a RAG system gives a wrong answer, the cause is very often that the right passage never reached the model. So most of this guide is about retrieval. We rewrote it in November 2026.
What RAG is, and when to skip it
The term comes from a 2020 paper that combined a language model's built-in knowledge with a searchable external memory, and found the combination produced more specific and factual text than the model alone (Lewis et al., 2020). In a business system it works like this: your documents are split into passages and indexed; a question comes in; the system finds the most relevant passages; the model answers from them.
Before building any of that, check whether you need it. Anthropic points out that a knowledge base smaller than about 200,000 tokens, roughly 500 pages, can be placed in the prompt in full, with no retrieval step to get wrong (Anthropic, September 2024). With prompt caching, described in our guide to cutting LLM costs, that is often affordable. RAG is the right tool when the content is larger, changes often, or has to be filtered by who may see it. If the question is whether to retrain a model instead, see fine-tuning versus RAG.
1. Clean the documents before you index them
Retrieval can only find what ingestion preserved. The unglamorous work here decides the ceiling for everything after it.
- Parse structure, not just text. Keep headings, lists and tables as they are. A table flattened into a stream of numbers can't be retrieved or read.
- Handle scans. A scanned PDF is a picture until it has been through text recognition. Our piece on multimodal AI covers documents and images.
- Remove noise. Page headers, footers, navigation and legal boilerplate repeat on every page and pollute the results.
- Remove duplicates and old versions. If three versions of a policy are indexed, the system will quote all three.
- Keep metadata. Source, section title, date, owner, language and who may read it. You will need each of these later.
- Give every passage a stable ID, so one changed document can be updated without rebuilding the whole index.
2. Make chunks that can stand on their own
Documents are split into chunks because a model can't be handed the whole archive. How you split matters more than most teams expect.
Split along the document's own structure: sections, paragraphs, list items, whole tables. Fixed-length cuts break sentences and separate a rule from its exception. A few hundred tokens per chunk with a small overlap is a common starting point, and the right size is the one that scores best on your own test questions.
The larger problem is lost context. A chunk that reads "the notice period is three months" is useless if nothing in it says which contract type it belongs to. Anthropic's contextual retrieval method addresses this by adding a short, generated description of where each chunk sits in its document before indexing it. In their tests, contextual embeddings reduced the rate of failed retrievals by 35%, adding contextual keyword search brought the reduction to 49%, and adding a reranking step brought it to 67%. You don't have to adopt that exact method. The principle is what matters: carry the document title, section heading and any defining terms into every chunk.
3. Retrieve with meaning and with keywords
There are two ways to find a passage, and they fail in opposite ways.
| Method | Finds | Misses |
|---|---|---|
| Embedding search | Passages with the same meaning in different words | Exact codes, names and rare terms |
| Keyword search (BM25) | Exact terms such as part numbers, error codes and article numbers | Paraphrases and synonyms |
| Both, then reranking | The best of each list, re-ordered by a model that reads question and passage together | Little, at the price of an extra step |
The same Anthropic study describes keyword search as particularly effective for queries that include unique identifiers or technical terms, and concludes that embeddings combined with BM25 work better than embeddings alone. Business questions are full of identifiers: order numbers, product codes, clause numbers, medication names. A system with embeddings only will keep missing them.
A few further practices carry over to almost every project:
- Rewrite the question. "And for part-timers?" means nothing to a search index. Have the system turn it into a full question using the conversation so far.
- Filter by metadata. Language, product, department and date narrow the search before ranking starts.
- Check your languages. If your documents are in Dutch and your users ask in English, test that case explicitly.
- Decide how many passages to send. In Anthropic's tests, passing the top 20 chunks worked better than 10 or 5. More is not always better, though: research on long contexts found that models use information at the start and end of the input best and do worse when the relevant passage sits in the middle (Liu et al., "Lost in the Middle"). Put the strongest passages first, and measure.
4. Make the answer show its sources
Once the right passages arrive, the instruction to the model is simple and should be strict:
- Answer only from the passages provided.
- Cite the passage for each claim.
- If the answer isn't in the passages, say so and offer the next step, such as a contact person.
Then show the citations to the user as links to the source document and section. Citations do two jobs. They let people check an answer in seconds, which is what builds trust in the first weeks. And they make failures visible, so they get reported instead of quietly believed. A knowledge assistant that says "I couldn't find this in the handbook" is behaving correctly.
5. Enforce access rights at retrieval time
A RAG system makes everything in its index easy to find, including the things that were only protected by being hard to find. The OWASP Top 10 for LLM applications lists this as its own risk: weak access controls on a vector store can let users reach content they shouldn't see, and in stores shared between groups, one group's content can surface in another group's answers (LLM08:2025). The same entry recommends permission-aware stores, validated data sources and logs of what was retrieved.
- Filter before ranking. Each chunk carries the access group of its source document, and the search only considers chunks the user is allowed to open. Never retrieve first and ask the model to withhold.
- Mirror the source system's permissions, and update them when they change there.
- Keep personal data out unless it's needed. Exclude or redact it at ingestion. For patient or client files, this is a design decision to take with whoever is responsible for privacy.
- Treat documents as untrusted input. A document can contain instructions aimed at the model. Our guide to secure AI systems explains indirect prompt injection and how to contain it.
- Log retrievals, so you can answer "why did it say that?" months later.
6. Keep the index fresh
An assistant that confidently quotes last year's price list does more damage than one that doesn't answer. Freshness needs an owner and a mechanism:
- Re-index a document when it changes, triggered by the source system where possible.
- Remove chunks when their document is deleted or withdrawn.
- Show the document date next to each citation.
- Alert when parsing fails, so a broken import doesn't silently empty part of the index.
- Name a person responsible for each source.
7. Test retrieval and answers separately
Build a set of real questions, and for each one record which passage contains the answer. That allows two separate measurements: did retrieval return that passage, and was the answer faithful to the passages it was given? The Ragas framework formalises the same split between retrieval quality, faithfulness and answer quality (Es et al., 2023). Without it you'll tune the prompt for weeks to fix what is really a chunking problem. Rerun the set whenever you change the chunking, the embedding model, the number of passages or the prompt. The full method is in our guide to evaluating LLM quality.
When it goes wrong: a quick diagnosis
| Symptom | Likely cause | First fix |
|---|---|---|
| Can't find an exact code or name | Embedding search only | Add keyword search and merge the results |
| Answers mix up products or contract types | Chunks without context | Add title and section to each chunk |
| Quotes outdated rules | Old versions still indexed | Remove duplicates, re-index on change |
| Right passage found, wrong answer | Too many or badly ordered passages, loose instructions | Rerank, send fewer, require citations |
| Answers reveal restricted content | No permission filter at retrieval | Filter by the user's access rights before ranking |
The checklist
- Confirm the content is too large or too changeable to simply put in the prompt.
- Parse structure, remove noise and duplicates, keep metadata.
- Chunk along document structure and carry context into each chunk.
- Combine embedding and keyword search, then rerank.
- Require cited answers and an honest "not found".
- Filter by access rights before ranking, and log retrievals.
- Re-index on change and show document dates.
- Test retrieval and grounding separately on real questions, on every change.
Done this way, RAG is ordinary engineering: mostly data preparation, search and testing, with a model at the end. Neurova AI builds knowledge assistants on a company's own documents, with access rights and citations designed in. If you have an assistant that people have stopped trusting, the cause is usually in one of the seven steps above, and we can help you find which.
Frequently asked questions
What is retrieval-augmented generation (RAG)? RAG is a way of letting a language model answer from your own documents. When a question comes in, the system first searches a prepared index of your content for the most relevant passages, then gives those passages to the model together with the question and asks it to answer from them. The model's general knowledge is combined with a searchable store you control and can update.
When do I not need RAG? When the material is small enough to fit in the prompt. Anthropic notes that a knowledge base under about 200,000 tokens, roughly 500 pages, can simply be included in full, which removes retrieval as a source of error. RAG earns its place when the content is larger than that, changes often, or must be filtered by who is allowed to see what.
What is hybrid search in RAG? Hybrid search combines two ways of finding passages. Embedding search finds text with a similar meaning, even when the wording differs. Keyword search, usually BM25, finds exact terms such as product codes, names and error numbers. Running both and merging the results, often followed by a reranking step, finds the right passage more reliably than either method alone.
How do I stop a RAG system from making things up? Fix retrieval first, because most wrong answers start with the wrong passages. Then instruct the model to answer only from the supplied passages, to cite the passage for each claim and to say so when the answer is not there. Show the sources to the user, and test grounding on a set of real questions every time you change the system.
