Skip to content
AI guide

Taking RAG From Prototype to Production

Why most RAG demos fail in production — and the retrieval quality, evaluation and guardrails that make grounded AI assistants reliable.

Abstract 3D AI letters representing artificial intelligence and generative AI
Radiatus at a glance
  • Since 2021Independent studio
  • 31 servicesAcross 5 practices
  • 15 productsBuilt & run in-house
  • 24/7Managed support
On this page

Retrieval-Augmented Generation (RAG) demos are seductive: point a model at your documents, ask a question, get a confident answer. Then you ship it, and reality arrives — stale answers, confident hallucinations, and the occasional leak of information a user shouldn't see. Moving RAG from prototype to production is mostly about the parts the demo skipped. This is the checklist our generative AI team works through.

First, check that RAG is the right tool

RAG answers questions from documents that change. It is not the answer to every AI feature, and choosing it for the wrong job is the most expensive mistake on this list.

ApproachUse it whenAvoid it when
RAGAnswers live in documents that change, and users need citationsThe answer is a number in a database, or the whole corpus fits comfortably in one prompt
Long-context promptingA small, stable set of documents and low query volumeCost and latency per question matter at scale
Fine-tuningYou need a consistent format, tone or classification behaviourYou want the model to know facts that change; retraining is a poor way to stay current
Tool calls over live systemsQuestions about orders, balances, appointments or stockUsers ask open questions across prose documents
Plain search with good snippetsUsers want to find a document, not get a generated answerUsers need a synthesised answer across several sources

Many production assistants combine two of these: RAG for policies and manuals, and tool calls for live data. If your assistant takes actions as well as answering, the tool layer deserves as much design as retrieval; see AI agent development and MCP server development for how we scope that part.

Retrieval quality is the whole game

If retrieval surfaces the wrong context, no amount of prompt engineering saves you. Invest here first:

  • Clean sources: remove duplicates and outdated versions, keep titles, dates and section headings as metadata.
  • Thoughtful chunking that follows document structure rather than fixed character counts, with enough overlap to keep context.
  • Hybrid search: combine keyword (BM25) and vector search — keyword search still wins on product codes, error messages and names.
  • Re-ranking of the top candidates with a cross-encoder or re-ranking model before they reach the prompt.
  • Metadata filters (product, region, date, permission) applied before similarity search.

Measure retrieval directly — is the passage that contains the answer in the top results? — before you even look at generation. That pipeline work is classic AI & data engineering.

Starting settings we tune from

These are our defaults for a first build, not rules. The evaluation set decides what stays.

  • Chunks split on headings and paragraphs, a few hundred tokens each, with a small overlap and the document title and section path prepended to every chunk.
  • Keyword and vector results merged with reciprocal rank fusion, which needs no score calibration between the two.
  • Twenty to fifty candidates retrieved, re-ranked, and the best five to eight passed to the model.
  • Follow-up questions rewritten into standalone queries before retrieval, so "and for annual plans?" carries its context.
  • A minimum re-ranker score below which the assistant says it does not know, rather than answering from weak context.

Worked example: the wrong version wins (illustrative)

A support assistant is asked about the refund window for annual plans. Version 3 of the policy says 30 days; version 2, still in the index, says 14. The two passages are nearly identical, so vector similarity cannot tell them apart and the older one ranks first. Prompt changes will not fix this. The fixes are upstream: mark superseded documents at ingestion, filter on status = current before similarity search, and show the policy date in the citation so a reader can spot a stale answer.

Ground, then generate

Instruct the model to answer only from the retrieved context and to say it doesn't know when the context doesn't contain the answer. Return citations so users — and you — can verify each claim. A grounded "I'm not sure, here's who to ask" beats a fluent fabrication every time, especially in support, legal, finance or healthcare settings.

Citations need checking too. Ask the model for structured output that ties each sentence to the IDs of the chunks supporting it, then verify in code that those chunks were in the context and, with a second pass, that they actually support the sentence. A citation pointing at the right document but the wrong paragraph is a quiet hallucination.

Evaluate like you mean it

You cannot improve what you don't measure. Build an evaluation set of real questions with known-good answers and source passages, then score for:

  • Retrieval: did the right passages come back?
  • Faithfulness / groundedness: is every statement supported by the sources?
  • Answer relevance and completeness: did it actually answer the question?

Run the set on every change to prompts, models, chunking or retrieval settings, and treat drops as regressions that block release. Automated LLM-based judges speed this up, but calibrate them against human review, and keep humans in the loop for high-stakes domains.

MetricQuestion it answersHow to score it
Retrieval recall at kDid the passage containing the answer reach the top k?Labelled question-to-passage pairs; fully automatic
Context precisionHow much of what we retrieved was relevant?Labels, or an LLM judge per passage
Groundedness (faithfulness)Is every claim in the answer supported by the retrieved text?An LLM judge that splits the answer into claims, calibrated against people
Answer relevance and completenessDid it answer the question that was asked?LLM judge plus human spot checks
Citation accuracyDoes each cited passage support the sentence it is attached to?Automatic ID checks plus a sampled review
Correct refusalDoes it decline when the corpus has no answer?Unanswerable questions included in the set

Open-source frameworks such as Ragas implement several of these (context precision, context recall, faithfulness and response relevancy among them). Use them to save time, but read what each metric actually computes before you put it in a release gate.

Building the evaluation set, step by step

  1. Collect a few hundred real questions from search logs, support tickets and subject-matter experts. Invented questions are too easy.
  2. For each, record the expected answer and the IDs of the passages that contain it.
  3. Add questions the corpus cannot answer, and adversarial ones, including injection attempts.
  4. Tag questions by topic and difficulty so a regression points at a cause.
  5. Run the set in CI on every change and fail the build on drops beyond an agreed threshold.
  6. Add every production failure you find to the set, so it never comes back unnoticed.

Calibrating an LLM judge

The research behind LLM-as-judge is encouraging and cautionary at once. Zheng et al. (2023) found that strong LLM judges can agree with human preferences about as often as humans agree with each other, and also documented position, verbosity and self-enhancement biases. So treat the judge as an instrument you calibrate. Have two people label a sample of answers against a written rubric, run the judge on the same sample, and read every disagreement.

Illustrative: on 100 answers, the judge flags 12 as ungrounded, the human reviewers flag 15, and 10 overlap. The judge is missing a third of the real failures. Tighten the rubric or the judge prompt and re-run before trusting it as a gate. Recalibrate whenever you change the judge model or prompt, and where you can, use a different model family for judging than for generating.

Guardrails and access control

A RAG system inherits the access model of its data. Enforce permissions at retrieval time — filter by the user's entitlements before anything reaches the model — so a user can never be shown context they couldn't open themselves. On top of that:

  • Defend against prompt injection, including instructions hidden inside retrieved documents. The OWASP Top 10 for LLM Applications lists prompt injection as its first risk, and it is a useful checklist for the rest. Its 2026 edition, published in August 2026, keeps prompt injection first and sensitive information disclosure second, and moves excessive agency up to third.
  • Filter inputs and outputs for sensitive data (PII, secrets) and off-topic or unsafe requests.
  • Limit what tools and actions the model can trigger, and require confirmation for anything irreversible.
  • Apply rate limits and cost limits per user.

Prompt-injection defences that hold up

OWASP's prompt injection prevention cheat sheet is blunt about one point: input filters and text labels are not a security boundary. Design so that a successful injection can do little.

  • Treat every retrieved chunk as untrusted data. Mark it clearly in the prompt, but never rely on the marking alone.
  • Clean content at ingestion. Strip hidden text, HTML comments and zero-width characters, and record how far each source is trusted.
  • Apply least privilege to tools. Use read-only credentials, act with the user's own permissions, and never let one model call read private data and send it outside without a check in between.
  • Validate output before rendering. Check for secrets, system-prompt fragments and unexpected links or images, which can carry data out of the conversation.
  • Require human approval for consequential actions, judged by what the action does rather than by words in the prompt.
  • Test adversarially, continuously. Keep injection cases in the evaluation set so every release is tested against them.

Worked example: permissions that lag (illustrative)

An internal assistant indexes an HR space and an all-staff space, and syncs document permissions every 15 minutes. Someone removed from the HR group can still retrieve HR passages for up to 15 minutes. For most content that is acceptable; for salary or disciplinary records it is not. The fix is to check permissions live against the source system at query time for sensitive collections, and to use the synced copy only for the rest. In a multi-tenant product, enforce the tenant filter inside the retrieval service rather than in the prompt, and consider separate indexes per tenant for regulated data; our SaaS development work treats this as part of the tenancy model.

We include LLM-specific testing in our VAPT services, and SemperWise, our cybersecurity line, runs VAPT and penetration testing engagements for teams that want an independent attempt to break what they have built.

Keep the index fresh

Stale answers are often an ingestion problem, not a model problem. Re-index incrementally when source documents change, delete chunks when documents are removed, and record the source version and date with every chunk so answers can show how current they are.

Changing the embedding model is a full re-index, because vectors from different models are not comparable. Build the new index alongside the old one, run the evaluation set against both, and switch with an alias so you can roll back in seconds.

Observe in production

Log queries, retrieved chunks, model versions and responses (with appropriate privacy controls and retention) so you can debug failures, collect user feedback and spot drift as your data and users evolve. Watch latency and cost per answer as closely as quality — they decide whether the assistant survives budget review.

A useful trace per answer holds the original and rewritten query, the IDs and scores of retrieved and re-ranked chunks, the prompt version, the model, tokens in and out, latency per stage and the user's feedback. Keep personal data out of traces where you can and set a retention period where you cannot. For Indian users that is a DPDP question as much as an engineering one; our DPDP compliance checklist covers the obligations. NIST's Generative AI Profile (NIST AI 600-1, July 2024) is a sensible framework for the wider risk review.

What drives the running cost

Whether you use Claude, GPT or open-weight models, the cost of a RAG system comes from a handful of drivers:

  • Tokens per answer, dominated by how much context you send. Eight passages instead of twenty is a direct saving.
  • Query volume, including retries and follow-ups.
  • Embedding and re-indexing, small per document but large after a model change.
  • Vector database and search hosting, sized by corpus and traffic.
  • Re-ranking, which runs on every query.
  • Evaluation runs, since every LLM-judge call is billed too.
  • People: reviewers who label answers and engineers who maintain ingestion. This is usually the largest line and the one most often left out.

Cheap wins: cache answers to frequent questions, use a smaller model for query rewriting and routing, cap context size, and stop generation early when retrieval confidence is low. For cost governance beyond the assistant, our FinOps playbook applies to AI spend as well.

Common RAG mistakes

  • Tuning prompts before measuring retrieval. Most bad answers start with bad context.
  • Vector search only. Product codes, names and error strings need keyword search.
  • Indexing everything. Drafts, duplicates and superseded versions compete with the truth.
  • Permissions applied after generation. By then the model has already read the restricted text.
  • An uncalibrated LLM judge as the release gate. It will pass confident, wrong answers.
  • No unanswerable questions in the evaluation set. You never learn whether it can say "I don't know".
  • Tools with broad credentials. One injected instruction becomes a data leak or an unwanted action.

Production readiness checklist

  1. Sources cleaned, versioned and tagged with owner, date and access rules.
  2. Hybrid retrieval with re-ranking, measured by recall at k on a labelled set.
  3. Answers grounded with checked citations and a confident "I don't know" path.
  4. Evaluation set in CI, with an LLM judge calibrated against human labels.
  5. Permissions enforced at retrieval time, with live checks for sensitive collections.
  6. Injection defences, output validation and least-privilege tools in place and tested.
  7. Incremental re-indexing, deletion handling and an index alias for rollbacks.
  8. Tracing, feedback capture, retention rules and dashboards for quality, latency and cost per answer.

The same discipline applies to assistants that act on live systems rather than documents. Our Clinic Answering Service, an AI receptionist for US practices built on the Claude API, books real appointments and checks insurance eligibility during the call: work where an invented answer is worse than none.

The teams that succeed with RAG treat it as a retrieval and evaluation problem with a language model attached — not a language model with some search bolted on. Whether you're building an internal knowledge assistant or a customer-facing chatbot or virtual assistant, talk to us about taking your prototype to production. The first consultation is free.

RAG in production FAQ

Why do RAG systems fail in production?

Mostly because retrieval returns the wrong or stale context, not because the model is weak. Duplicate and outdated documents, chunking that splits answers, vector-only search, missing permission filters and no evaluation set are the usual causes. Fix retrieval and measure it before tuning prompts.

How do you evaluate a RAG system?

Build a set of real questions with expected answers and source passages, including some the corpus cannot answer. Score retrieval recall, groundedness, answer relevance, citation accuracy and correct refusals on every change, using an LLM judge that you have calibrated against human reviewers.

How do you prevent prompt injection in a RAG application?

You cannot filter it out completely, so limit what a successful injection can do. Treat retrieved text as untrusted, clean content at ingestion, give tools read-only and per-user permissions, validate output before showing it, require human approval for consequential actions and keep injection cases in your test set.

Should we use RAG or fine-tuning?

Use RAG when answers come from documents that change and users need citations. Use fine-tuning to teach a consistent format, tone or classification behaviour. Fine-tuning is a poor way to keep facts current, and many systems use RAG with an untuned model.

How do you reduce hallucinations in a RAG chatbot?

Improve retrieval first, then instruct the model to answer only from the supplied context, require citations tied to specific passages, check those citations in code, and set a confidence threshold below which the assistant says it does not know and offers a person to ask.

Can an LLM judge replace human review?

Not entirely. LLM judges make evaluation fast and repeatable, but they have known biases such as favouring longer answers. Calibrate the judge against human labels, recheck it whenever the judge model or prompt changes, and keep people reviewing samples in high-stakes domains.

Written by the Radiatus engineering team. Questions or corrections? Email us.

Want help putting this into practice?

Talk to a senior engineer about your specific situation — no sales script.

Talk to an Engineer