Most RAG demos I've seen (a couple of them my own) work beautifully for about a week. Someone drops a folder of PDFs into a vector database, asks a handful of questions, and everyone's happy. Then real users turn up, and the assistant starts making things up with total confidence.
At Perimattic I spent most of my time on the far side of that first week, building RAG pipelines on OpenAI models, embeddings and vector databases for platforms that had to keep working after the demo. This is roughly how I build them now, and a fair bit of it I learned the slow way.
Write the questions before the code
The first thing I ask a client for isn't their documents. It's a list of questions their users actually ask, along with the correct answers and where each answer lives. A few dozen is enough to start with.
Clients usually find this a bit odd ("don't you just need the files?"). But that list becomes the evaluation set, and without one every change you make is a guess dressed up as progress. If nobody can say where an answer lives, no retrieval system will find it either.
Parsing decides most of your accuracy
When a RAG answer is wrong, my first suspect is almost never the model. It's the text that went into the index: tables flattened into a soup of numbers, headers repeated on every chunk, scanned PDFs that came back empty without anyone noticing.
So each source type gets its own handling. Native PDFs are extracted with layout, and tables stay tables. Scans go through OCR and a cleanup pass. Word files and HTML become clean Markdown with the headings intact, because those headings matter in the next step.
My B.Com in Computer Application helps here more than you'd think. When a balance sheet table comes out of the parser mangled, I can often spot it by eye before any metric does. (I've written more about the extraction side in turning documents into structured JSON.)
Chunk by structure, then by size
Fixed-size chunks, say every 1,000 characters, are the default in most tutorials. They also cut sentences, tables and lists clean in half. I split on structure first: headings, sections, list items. Only after that do I cap the size.
Every chunk also carries its section title with it. A chunk that says "the limit is 30 days" still needs to know whether it sits under "Refund policy" or "Leave policy". It's a cheap trick, and it fixes a surprising number of wrong answers on its own.
Use hybrid retrieval
Embeddings are good at meaning and bad at exact strings: invoice numbers, product codes, names, clause numbers. Ask a pure vector search about one specific invoice and it'll happily hand back a different invoice that looks "semantically similar".
So I run vector and keyword search side by side, merge the results and re-rank them before anything reaches the model. This one change often does more for answer quality than a bigger model, at a fraction of the cost.
Make the model show its sources
The prompt is strict. Answer only from the retrieved context, cite the chunk every claim came from, and say so plainly when the context doesn't cover the question. Something like this:
Answer using only the context below.
After each claim, cite the chunk id in square brackets, like [c3].
If the context does not contain the answer, reply:
"I couldn't find that in the documents I have access to."
That last line matters more than people expect. Clients sometimes push back on an assistant that admits it doesn't know. I tell them a confident wrong answer about a contract or a payslip does far more damage, and it kills trust in the whole tool. Citations help from the other side: business users only rely on what they can check.
Change one thing, then measure
Every change gets run against the evaluation set: chunk size, retrieval depth, prompt wording, the model itself. One at a time. That sounds slow, but it's quicker than changing four things, watching the score move, and not knowing why.
The numbers I watch:
- retrieval hit rate, meaning whether the right chunk came back at all
- answer correctness against the reference answers
- how often it correctly refuses questions the documents don't cover
If the hit rate is low, no amount of prompt tweaking will save you. Fix retrieval first.
The unglamorous production work
This is the part demos skip. Changed files get re-indexed automatically, not whenever someone remembers. Retrieval is filtered by the user's permissions before anything reaches the model (filtering the answer afterwards is too late, the model has already read the restricted text). Embeddings and frequent answers get cached, because re-embedding unchanged files is paying twice for nothing.
I also log every question with the chunks it retrieved and the answer it gave, so when someone reports a bad answer I can see whether parsing, retrieval or the prompt was at fault. The production systems I look after run at 99.99% uptime, and honestly most of that comes from boring habits like this.
Where I'd spend the first week
Good RAG is mostly data engineering with a language model at the end. On a new project I'd spend the first week on parsing and the evaluation set, and almost none of it on picking a model. The model is the easiest part to swap later.
If you're planning an AI assistant over your company's documents, I'm happy to look at what you have. See my AI & RAG development service or book a free consultation.