· 4 min read
What building a RAG platform taught me about hallucinations
Most chatbot hallucinations are retrieval problems, not model problems. Lessons from building a platform that lets businesses train chatbots on their own documents.
For two years I led AI engineering at IT Together, where one of the main things we built was a platform that lets businesses create their own chatbots, trained on their private data using retrieval-augmented generation (RAG).
The pitch for RAG is clean. Instead of hoping a language model memorised the right facts, you find the relevant pieces of the customer's own documents and hand them to the model along with the question. The model answers from that context. Fewer made-up answers, and it works on data the model has never seen.
In practice, getting from "it works in the demo" to "a business trusts it with their customers" took most of our effort. Here is what I would tell anyone starting out.
Most hallucinations are retrieval failures
When the chatbot gave a confident wrong answer, my first instinct early on was to blame the model, or the prompt. Usually, that was wrong.
Nine times out of ten, when we traced a bad answer back, the model had simply not been given the right information. The relevant paragraph was never retrieved, or it was retrieved but cut in half, or it was buried under five irrelevant chunks. The model did what models do: it filled the gap with something plausible.
So the first debugging question is always: what did we actually send the model? Log the retrieved chunks for every answer. Look at them. You will learn more in an afternoon of reading those logs than in a week of prompt tweaking.
Ingestion is the unglamorous 80%
Everyone wants to talk about embeddings and vector databases. The real work is earlier: getting documents in cleanly.
Business documents are messy. PDFs with tables that come out as soup. Headers and footers repeated on every page. Scanned files with no text at all. Word documents where the important bit is in a text box. Policy documents where one paragraph only makes sense if you know which section heading it sits under.
Our ingestion pipeline ended up doing a lot of quiet work before anything was embedded: extracting text properly, stripping repeated noise, keeping section headings attached to the text under them, and keeping a link back to the source page so answers could cite where they came from.
If your retrieval is bad, check your ingestion before you change anything else.
Chunking is a product decision
How you split documents into chunks decides what the model can see at once.
Chunks that are too small lose context: "the fee is waived in this case" means nothing without knowing which case. Chunks that are too large drag in unrelated text and push out other useful pieces. There is no universal right size. Policy manuals, product catalogues and FAQs all want different treatment.
What helped most was splitting along the document's own structure, headings and sections, rather than at a fixed number of characters, and carrying the heading into each chunk so it stands on its own.
Let it say "I don't know"
A chatbot that always answers is a liability. A chatbot that says "I couldn't find that in your documents" is something a business can put in front of customers.
We made this explicit in the instructions to the model, and, more importantly, we tested it. Every evaluation set included questions whose answers were not in the documents. A correct "I don't know" counted as a pass. A confident invention counted as a serious failure, worse than a vague answer.
Test with real questions, not your own
The questions engineers write to test a chatbot are too clean. Real users type half sentences, use internal nicknames for products, and ask three things at once.
The best evaluation data we had came from the client: questions their staff or customers actually asked. Even fifty real questions with known good answers will tell you more than hundreds of synthetic ones. Run them every time you change the chunking, the embedding model, the prompt or the LLM, and you will catch regressions before your users do.
Show your sources
Finally, cite. Every answer should point to the document and section it came from.
It helps users check the answer. It helps the business trust the system. And it helps you, because when someone reports a wrong answer, you can see immediately whether the problem was the source, the retrieval, or the model.
The short version
If I had to compress two years into a few lines:
- Log and read what you retrieve.
- Fix ingestion before tuning anything else.
- Chunk along the document's structure.
- Reward "I don't know".
- Evaluate on real user questions, every change.
- Always cite the source.
None of this is glamorous. All of it matters more than which model you pick. I wrote about the model side, and why we built one API in front of many LLMs, in a separate post.