RAG in Production: Why Your AI Search Returns Wrong Answers
Retrieval-augmented generation looks simple in a demo: embed your documents, find the closest chunks to the question, give them to the model, get an answer. Production adds thousands of documents, several versions of each, users with different access, and questions nobody predicted.
First, find out which half is failing
Take 30 real questions that got bad answers. For each, look at what retrieval returned before the model saw it.
- The right passage was not retrieved: retrieval problem. Causes 1-5 below.
- The right passage was retrieved but the answer is still wrong: generation problem. Causes 6-7.
This split takes an afternoon and saves weeks of prompt tweaking aimed at the wrong half.
Retrieval causes
1. Chunks cut through the answer
Fixed-size chunking (every 500 tokens) splits tables, lists and procedures down the middle. The question matches the first half; the answer sits in the second. Split on document structure (headings, sections, table rows) and keep a small overlap. Store the section title with each chunk so a chunk saying "it takes 14 days" still knows what "it" refers to.
2. Vector search alone misses exact terms
Embeddings are good at meaning and weak at exact identifiers: product codes, error numbers, clause references, names. A question about "error E-4012" may retrieve chunks about errors in general. Hybrid search (vector plus keyword, such as BM25, with the results merged) fixes most of these cases. Adding a re-ranking step on the merged top 30-50 results improves ordering further.
3. The index is stale
Someone updated the policy document last week. The index still holds the old version, or both versions. Track a content hash per document, re-index on change, and delete chunks from removed or replaced documents. Answers built from an outdated document are worse than no answer.
4. No filters for version, product or permission
Users ask about their own plan, their own product version, documents they are allowed to read. If retrieval searches the whole corpus, it returns the best text match from the wrong context. Store metadata (product, version, region, access group) on each chunk and filter before ranking. Permission filtering here is a security requirement, not a quality tweak: without it, the system can quote a document to a user who should never see it.
5. The question and the documents use different words
Users write "how do I get my money back"; the documents say "refund policy". Query rewriting (ask the model to restate the question in the documents' vocabulary before searching) or a short synonym list for your domain closes much of this gap.
Generation causes
6. The prompt allows guessing
If the instructions do not say "answer only from the provided context, and say you don't know when the context does not contain the answer", the model will fill gaps from its general knowledge. Require citations to the retrieved chunks and drop answers whose citations don't support the claim.
7. Too much context
Stuffing 40 chunks into the prompt to be safe makes the relevant passage harder to use. Fewer, better-ranked chunks usually beat more of them.
Measure before and after
You need a test set before you change anything:
- 50-100 real questions from logs or support tickets,
- the document (or passage) that contains each answer,
- the expected answer in one or two sentences.
Track two numbers on every change:
- Retrieval hit rate: how often the right passage is in the top results.
- Answer correctness: judged by a person on a sample, or by a model grading against the expected answer, spot-checked by a person.
A change that improves one number and drops the other gets reverted. Without this, every fix is an opinion.
When to change the model
After retrieval is fixed and measured. A stronger model helps with reasoning across several passages and with following the "don't guess" instruction. It does not help when the right passage never reached it.
If your AI search or support assistant gives answers your team doesn't trust, our starts with exactly this diagnosis: split retrieval from generation, build the test set, and fix the causes in order.
FAQ
What services do we provide?
We specialize in creating innovative digital solutions including web development, mobile applications, CRM systems, and enterprise software. Our services are tailored to meet your specific business needs and drive growth.

Oleksii Stupak
CEO @ AleannLab
"Want to explore how we can help your business grow? Let's connect and discuss your project on LinkedIn."
Ready to discuss your project with us?




