Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 6 min read

How I Build Production RAG Pipelines That People Trust

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

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.

Frequently asked questions

What is a production RAG pipeline?

It's a retrieval-augmented generation system built to be used by real people every day, not just shown in a demo. Documents are parsed, chunked and indexed, the relevant pieces are retrieved for each question, and a language model answers from those pieces with citations. The production part is everything around that: evaluation, access control, re-indexing, caching and logging.

Why does my RAG chatbot give wrong answers?

In my experience the model is rarely the main cause. Most wrong answers trace back to bad parsing, such as flattened tables or empty scanned pages, or to retrieval that never returned the right chunk. Check what text actually went into the index and whether the correct chunk comes back for the question before you touch the prompt or the model.

Is hybrid search better than vector search for RAG?

For business documents it usually is. Embeddings handle meaning well but struggle with exact strings like invoice numbers, product codes and names. Combining vector search with keyword search and then re-ranking the merged results tends to fix those misses without changing the model.

How do you evaluate a RAG system?

I start with a set of real user questions, each with a correct answer and the place that answer lives in the documents. Every change is tested against that set, one change at a time. I track whether the right chunk was retrieved, whether the answer matches the reference, and whether the system correctly says it doesn't know when the documents don't cover the question.

Originally published on anupojha.in. I'm Anup Ojha, a full-stack and AI engineer from Nagpur, India. More at anupojha.in.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.