HomeAIAI agents

AI agents · How to ground it in your data

Your chatbot gives wrong answers about your data

A rag pipeline production architecture that grounds answers in your own documents: how it works, what it costs, and the checks that catch wrong answers.

Don't want to read the whole article?

No problem. We put everything in a 1-minute video, so you get the full idea fast.

By submitting, you agree that Sivaro may contact you about this topic.

Your chatbot gives wrong answers about your data
Your chatbot gives wrong answers about your data

Free Technical Audit

Expert Review

Get Started →
Your chatbot gives wrong answers about your data

Your team ships the assistant on Friday, and on Monday a user asks about a policy you know exists. The bot answers with confidence, cites nothing real, or quotes a page that was retired last year. That is not a model problem. Your rag pipeline production architecture is the part failing: the retrieval step is pulling the wrong chunks, and the model is faithfully answering from garbage.

RAG finds the right parts of your own documents and gives them to the model with each question, so the answers come from your data. The model does not learn your documents; it reads the chunks a retrieval step hands it. Fix the retrieval and the pipeline, and most "hallucinations" disappear. This guide covers the full production architecture of such a pipeline: the two halves that make it up, the choices that decide quality, the operating work nobody mentions, where the cost goes, and the failure modes that show up first. It is one part of the AI agents topic map, which answers the wider question of making an agent work in production.

In short

  • The right document may exist but not be retrieved, because the query phrasing differs from the document’s language (poor retrieval recall).
  • A production RAG system is two pipelines sharing one index, an offline ingestion pipeline and an online retrieval pipeline, and every quality gain comes from improving one of them or the seam between them [5].
  • The standard pipeline uses a fixed sequence — the orchestrator runs a search, assembles context, calls the model — and does not decide whether or how much to retrieve [1].
  • Ingestion is where most teams underbuild: a one-time load of static files breaks the week the corpus starts changing [4].
  • At low traffic, the complex split architecture is the wrong choice: below roughly 20–30 QPS or without a dedicated infrastructure owner, run a synchronous monolith instead [6].
  • Much of the work is data engineering on messy documents, not prompt tuning — freshness, traceability, and reformatting matter more than the model choice [4].
  • For one legal-domain team, a paid reranker made first-position hits worse (34 to 26), so they left it out of production after a 10,000-sample bootstrap test found no reliable gain [2].

At a glance

Fact Detail Ref
Two pipelines Offline indexing pipeline plus online retrieval pipeline [5]
Ingestion steps Chunk, enrich metadata, embed, persist to the index [1]
Query flow Embed question, search, optionally rerank, build prompt, generate [5]
Perceived latency target Typically under 3–5 seconds, streaming for perceived speed [5]
Scale threshold for async split Below 20–30 QPS or no infra owner, skip it [6]
Reranker decision Test on your own questions; leave out if no measured gain [2]
Incremental indexing Required whenever the corpus changes weekly or daily [4], [5]
Monitoring levels Infrastructure, API, LLM use, and answer quality [7]
Deployment shape FastAPI app in a container, settings in a secrets manager [7]
Framework limit LangChain and LangGraph are tools, not architecture [7]

Why the model answers wrong when the document is right there

The model answers wrong because the retrieval step never gave it the right text, not because the model lacks the knowledge. RAG converts the question into a search representation, pulls the closest document chunks, and passes them into the prompt as context [4]. The model does not learn your documents in that moment. It answers from what it was handed.

That single fact changes how you debug. When an answer is wrong, the first question is not "which model?" but "did the correct chunk make it into the prompt?" Retrieval quality and data freshness decide answer quality, because the generation step can only work with what it receives [4].

Common production failures are mostly retrieval failures: poor recall where the right document exists but is not retrieved, poor context precision where noise confuses the model, and multi-hop questions that need cross-document reasoning [5]. Most RAG engineering is fixing these failures systematically, not swapping models [5].

Before: a confident answer, no source, hours of guessing.
After: the same question traced to the exact chunk that was retrieved, or a clear signal that retrieval missed.

If you want the plain-language definition first, see what a RAG pipeline is.

The two pipelines that make up the architecture

A production RAG system has two pipelines: an ingestion pipeline that processes and indexes documents, and a query pipeline that retrieves and synthesizes answers [5]. They share one index. Every quality improvement comes from improving one of them or the interface between them [5].

The ingestion pipeline

The ingestion pipeline turns raw documents into searchable chunks. Documents or media are pushed or pulled in, then the pipeline processes each file through four steps [1]:

  1. Chunking — break the file into semantically relevant parts, ideally one idea per chunk [1].
  2. Enrich chunks — add metadata fields the pipeline generates from the content, such as title, summary, and keywords [1].
  3. Embed chunks — vectorize the chunk and any metadata fields used for vector search [1].
  4. Persist chunks — store them in the search index [1].

A wider enterprise design adds a landing zone before the vector database so a failed write can be replayed from the raw copy, and runs ingestion as a scheduled job or an event-triggered worker rather than a local script [4][7].

The query pipeline

The query pipeline handles each user question at request time. It embeds the query, performs vector search (optionally combined with BM25 keyword search), reranks results, assembles the prompt with the retrieved context, and generates a response [5]. An API gateway in front handles authentication, rate limiting, and routing [3].

The orchestrator here follows a fixed sequence. It accepts the query, runs a search, assembles context, and calls the model — it does not decide whether to search, which index to query, or how many retrieval steps to take; you make those decisions at design time [1]. That predictability is a feature in production, and a limit when questions need multi-step reasoning.

Synchronous monolith or split services: the deployment choices

Most teams should start with a synchronous monolith and split only when traffic or team size forces it. The distributed design is not the right starting point for most teams, and the docs say so plainly: below roughly 20–30 QPS, or without a dedicated infrastructure owner, skip the split and run a synchronous monolith [6].

The table compares the two common shapes.

Choice What it looks like When it wins When it costs you
Synchronous monolith One service runs embedding, search, rerank, and generation in one call chain Low traffic, small team, early project A slow embedding provider or index stalls every request [6]

| Async split services | Gateway, queue, embedding service, vector DB, reranker, inference server, observability | High traffic, dedicated infra owner | Needs distributed tracing; slow iteration while the design is still changing [6] |

The high-traffic default stack is a message broker (Kafka or Redis Streams) between gateway and embedding tier, a disk-backed HNSW index such as Qdrant, and a dedicated inference server with continuous batching such as vLLM, plus Prometheus or OpenTelemetry for tracing [6]. The main trade-off is operational complexity: you trade a monolith's simplicity for independent scaling and fault isolation per stage [6].

If your traffic is high but your queue consumers keep choking, see scaling Kafka consumers without breaking production. A disk-backed HNSW vector index is RAM- and disk-bound, so scale it independently from the embedding tier [6].

Comparing retrieval and generation options

Retrieval choices matter more than generation choices for answer quality. Production RAG architectures typically split ingestion, embedding, retrieval, and generation into separate services [1][5][6][7].

Layer Option Plain trade-off
Retrieval Pure vector search Handles meaning, misses exact IDs and product names [5]
Retrieval Hybrid (vector plus BM25, merged by reciprocal rank fusion) Covers both meaning and exact terms; usually beats pure vector [5]
Retrieval Agentic retrieve-as-a-tool Some scenarios, such as multistep reasoning, dynamic source selection, query decomposition at runtime, and combining retrieval with actions, exceed what a fixed pipeline can handle [1]
Reranking Cross-encoder reranker Can improve order; test it, because it can also make results worse [2]
Reranking No reranker Simpler, cheaper; default until the simpler version cannot keep up [6]
Ingestion Fixed-size chunking Simple and common in production; chunk size and overlap are real levers [4]
Ingestion Semantic or structural chunking More context-aware, more work to tune; small chunks are precise but thin on context [8]

A reranker is not automatically an upgrade. A legal-domain team ran a 100-query comparison and the paid reranker reduced first-position hits from 34 to 26 and mean reciprocal rank at 30 from 0.467 to 0.416; a 10,000 paired bootstrap resample found no reliable gain, so they left it out [2]. Compare candidates on the same questions before letting any component into production [2].

How to choose for your team

The choice depends on traffic, corpus churn, and headcount, not on the framework's feature list.

If you are under 20–30 QPS with a small team, run the synchronous monolith with hybrid search and no reranker until you measure a problem [6]. If your corpus changes weekly or daily, build incremental ingestion from the start, because a one-time load breaks the first time a document changes [4]. If questions need cross-document comparison or dynamic index selection, standard RAG's fixed sequence will not carry them, and agentic retrieval — where an agent treats retrieval as a tool it calls on demand — is the honest option [1].

If you are choosing between teaching the model your data and letting it look it up, read fine-tuning versus RAG in 2026. RAG fits knowledge that changes; fine-tuning fits behavior that must be stable. Long context windows are not a substitute either: cost scales with token count and models underweight the middle of long inputs, so RAG keeps the context bounded and relevant [5].

Frameworks are tools, not architecture. A production system built on LangChain or LangGraph still needs clean data, validated chunking, evaluated retrieval, prompt versioning, monitoring, security, and deployment infrastructure — no framework automates these [7]. Teams often mix framework connectors with their own code, keeping the framework where it helps [7].

Running it day to day: freshness, latency, and watching answers

Running it day to day: freshness, latency, and watching answers

Running RAG in production is mostly keeping the index fresh and knowing which stage is slow. Static corpora are easy; dynamic corpora require a full incremental indexing pipeline, which is one of the most underestimated operational requirements [5].

Freshness first. Incremental ingestion keeps the vector store updated as new or changed documents arrive, and companies add documents weekly, daily, and sometimes hourly [4]. A landing zone decouples systems so a failed write to the vector database can be replayed without losing the raw copy [4].

Latency second. An interactive RAG system must complete the retrieval-augment-generate cycle within an acceptable window, typically targeting 1–2 seconds total for interactive applications (retrieval under 500ms and generation under 1000ms), with streaming to improve perceived responsiveness [5]. When latency is not, nobody can tell which stage is slow because there is no per-stage tracing [6]. Debugging a distributed pipeline needs distributed tracing; without it, engineers lose more time chasing latency across services than they saved by splitting the monolith [6].

Quality third. Monitor at four levels: infrastructure health, the API (requests, errors, 95th-percentile latency), LLM use (tokens, cost per question, model errors), and quality (sample-based evaluation and user feedback) [7]. Without monitoring you cannot see retrieval degrading after an embedding model update, more made-up answers, runaway token costs, or failed loading jobs that leave the knowledge base stale [7].

A simple operating loop:

  1. Evaluate each step independently, then check the end result your users experience [1].
  2. Document hyperparameters and evaluation results, and aggregate across many queries [1].
  3. Pin image and library versions explicitly; RAG stacks break silently on transitive dependency bumps, especially tokenizer and model mismatches [6].
  4. Set a queue consumer group per environment so staging and production do not consume each other's messages [6].

Where the cost goes

Cost in a RAG pipeline sits in three places: the vector store's memory and disk, the LLM tokens per answer, and the reranking and embedding compute. The docs tie most of these to design choices you control.

Vector database fit is the first line. A purpose-built vector store often fits RAG workloads better than vectors stored inside a warehouse, especially on cost and retrieval behavior [4]. A single vector DB node runs out of RAM once the corpus grows past what fits comfortably in memory, which is a sizing decision, not a surprise [6].

Token cost is the second line. You cannot fit an entire enterprise document corpus into a single prompt because context windows are finite and LLM costs scale with token count, so retrieval narrows the corpus to the most relevant documents [5]. Monitor tokens, cost per question, and model errors, or token costs run away without anyone noticing [7].

Compute is the third line. A paid reranker can add cost without a measured gain: in a separate 100-query comparison, a paid reranker reduced first-position hits from 34 to 26 and mean reciprocal rank at 30 from 0.467 to 0.416, with no reliable gain across 10,000 paired bootstrap resamples [2]. Incremental ingestion is important because your documents change frequently [4]. For the serving side, see the cost-efficient model serving architecture.

When this is the wrong choice

RAG is not the answer to every question, and the sources name the limits.

The corpus never changes and the model already knows the domain. RAG's advantage is knowledge currency, so a static corpus with no freshness need gets less from a retrieval stack [5].

Questions need multi-step reasoning or dynamic source selection. Standard RAG's orchestrator does not decide whether to search, which index to query, or how many steps to take [1]. Consider agentic RAG, where retrieval becomes a tool the agent invokes on demand [1].

Traffic is low and the team is small. Below roughly 20–30 QPS or without a dedicated infrastructure owner, skip the split architecture and run a synchronous monolith [6].

RAG systems retrieve only the most relevant chunks at query time to keep prompts manageable and costs bounded [5]. Combine retrieval with long-context handling where the document fits, but watch the middle-of-context weighting problem [5].

RAG supplies the model with relevant documents retrieved at query time and injects them into the prompt so the model can answer from that context rather than from its static training data [5]. Mixing them up wastes budget on the wrong lever; see is fine-tuning worth it for production.

How to check in your own system

Five signs tell you the retrieval layer, not the model, is the problem.

  1. The right document exists but never appears in the prompt — check retrieval recall on a labeled question set [5].
  2. Answers are fluent but cite noise — check context precision, where retrieval returns chunks that confuse the model [5].
  3. Keep documents updated and check ingestion runs so answers stay fresh [4][7].
  4. Latency spikes without a clear cause — check per-stage tracing; without it you cannot tell which stage is slow [6].
  5. Cost per question climbs — check tokens per answer and whether an unproven reranker is in the path [7][2].

The cheapest check you can run this week:

  1. Pull some real questions users asked and the answers they got wrong.
  2. For each, look at the chunks that were retrieved, not the final answer.
  3. Mark whether the correct chunk was in the retrieved set. If yes, the model misused it; if no, retrieval failed.
  4. Test a hybrid retrieval run against pure vector search on the same set of questions [5].
  5. Only then test a reranker, and keep it only if it wins on your own questions [2].

Key terms

RAG: Retrieval-Augmented Generation is a pattern where the model answers using context pulled from your own documents at question time [4].
Ingestion pipeline: The offline pipeline that chunks, enriches, embeds, and stores documents into the index [1].
Query pipeline: The online pipeline that embeds the question, retrieves chunks, builds the prompt, and generates the answer [5].
Chunk: A retrievable piece of a document, ideally holding one idea, that the system can return as context [1].
Embedding: A numeric vector representing meaning, used to find chunks close to the question [4].
Vector database: A store that holds embeddings and supports fast similarity search plus metadata filtering [4].
Hybrid search: Vector search combined with BM25 keyword search, merged by reciprocal rank fusion [5].
A reranker was evaluated but removed from production because it did not reliably improve retrieval results [2].
Incremental ingestion: An ingestion mode that updates only new or changed documents instead of reloading everything [4].
Agentic RAG: A design where an agent treats retrieval as a tool it calls on demand rather than a fixed sequence [1].

Common questions

Why does my RAG chatbot give wrong answers when the document exists?

The right document exists but retrieval never pulled it into the prompt. Poor recall from query-document language mismatch is a top production failure, and the model can only answer from what it is given [5]. Check retrieval before touching the model.

What are the two pipelines in a production RAG architecture?

A production RAG system has an offline indexing pipeline and an online retrieval pipeline, sharing one index [5]. The indexing pipeline loads, chunks, embeds, and stores documents; the retrieval pipeline embeds the query, searches, reranks, and generates [5].

Do I need a reranker in my RAG pipeline?

Only if you measure a gain on your own questions. A legal-domain team's paid reranker made first-position hits worse (34 to 26) and showed no reliable gain after resampling, so they left it out [2]. Default to no reranker until the simpler version cannot keep up [6].

Should I use agentic RAG or standard RAG?

Use standard RAG for queries that map to a single search against a single index. Use agentic RAG when questions need multi-step reasoning, dynamic source selection, runtime query decomposition, or combining retrieval with actions [1].

How do I keep the index fresh in production?

Run incremental ingestion so the vector store updates as new or changed documents arrive [4]. Keep a landing zone so a failed write can be replayed, and monitor ingestion failures that leave the knowledge base stale [4][7].

Is RAG just data engineering?

Mostly, yes. A RAG system that companies actually use is a data engineering pipeline that keeps unstructured data fresh, searchable, and traceable, then retrieves the right context at the right time [4]. The LLM call is the last step, not the hard part.

Grounding an agent in your data is one of three production requirements, alongside testing every answer and giving the agent only the tools it needs. The broader map is the AI agents topic map; on infrastructure, see AI agent production infrastructure and agentic workflow production best practices.

When should I split RAG into async services?

When traffic and headcount force it. Below roughly 20–30 QPS or without a dedicated infrastructure owner, a synchronous monolith is the better default [6]. Scale each stage against its own bottleneck signal when you do split [6].

References

References
  1. Design and Develop a RAG Solution on Azure - Azure Architecture Center
  2. production-rag-case-study — anonymized engineering case study
  3. Case Study: Enterprise RAG System | AI System Design Guide
  4. Production RAG System Guide 2026: Ingestion to Retrieval
  5. RAG Architecture Diagram — Production RAG Systems
  6. RAG Architecture: Production Pipeline for High Traffic
  7. RAG Architecture Guide for Production | Technovids
  8. Building a Production-Ready RAG Pipeline: A Complete Guide

Want to talk this through?