ServicesWorkJournalAboutContact
Start a project
AI Agents/Jul 19, 2026

How to build a production RAG pipeline (not just a demo)

Content TeamArchitectural Insights
How to build a production RAG pipeline (not just a demo)
15 min read

The five architecture layers that separate a working RAG demo from a production system, with real vector database, reranking, and monitoring choices.

Naive RAG pipelines fail at retrieval roughly 40 percent of the time in production, and the failure is invisible from the outside. The LLM generates a confident, well-structured answer, grounded in the wrong document. Nobody sees an error message. The user just gets a wrong answer delivered with total confidence, which is worse than no answer at all.

Every RAG tutorial teaches the same four steps: embed documents, store them, retrieve the top matches, generate an answer. That works in a notebook against a small, clean document set. It falls apart the moment a real user asks a real question against real, messy production data, and it almost never falls apart at the model layer. The model is fine. The gap between a demo and a production system lives in four layers most tutorials skip entirely: query transformation, hybrid retrieval with reranking, evaluation, and ongoing monitoring.

1784565440180 5 layerRAGsystemarchitecturediagram

The 30-second version

LayerWhat it doesWhat breaks without it
Ingestion and chunkingPrepares and indexes source contentGarbage in, garbage retrieved, covered in depth elsewhere
Query transformationRewrites the raw user question before searchingUser phrasing rarely matches document phrasing, retrieval misses
Hybrid retrieval and rerankingCombines keyword and vector search, then rescoringPure vector search misses exact terms; pure keyword misses meaning
GenerationThe LLM call that produces the final answerUsually fine on its own, the least likely failure point
Evaluation and monitoringContinuous, automated quality checks in productionRegressions go undetected until a customer notices

A RAG demo and a production RAG system differ on every axis that doesn't show up in a quick internal test: sub-2-second latency at real query volume, mixed-format documents instead of one clean PDF, role-based access control so people don't retrieve what they shouldn't see, and automated evaluation catching quality drops before a customer does.

Query transformation: the layer most tutorials skip

Sending the raw user question straight to the vector database is close to a mistake by default. People phrase questions the way they talk, not the way documents are written. "What happens if I miss the deadline" can retrieve almost nothing useful, while "late submission policy penalties" retrieves the right section immediately, even though both are asking the same thing. That gap is exactly what query transformation closes.

In practice this means rewriting, expanding, or decomposing the user's query before it hits retrieval: generating a version phrased closer to how the source documents are written, breaking a multi-part question into separate retrieval passes, or expanding an ambiguous query into a few variations and merging the results. This is one of the highest-leverage, least-implemented steps in the whole pipeline, precisely because it's invisible in a demo where the tester already phrases questions the way the documents are written.

Hybrid retrieval and reranking

Pure vector search misses exact keyword matches, a product code, a specific clause number, a named entity, because semantic similarity doesn't guarantee lexical overlap. Pure keyword (BM25) search misses semantic similarity, a query and a passage that mean the same thing but use different words. Hybrid search runs both and combines the results, and it's consistently the single biggest quality improvement available on top of a naive vector-only pipeline.

Reranking adds a second stage on top of that: take the top 50 to 100 candidates hybrid search returns, then rescore each one with a cross-encoder model that evaluates the query and the candidate together rather than independently. Cross-encoders are slower per comparison than the embeddings used for first-pass retrieval, but a reranking step yields a 20 to 30 percent improvement in the quality of the chunks actually passed to the LLM, a large enough gain that skipping it is hard to justify once volume can absorb the added latency. Applying metadata filters, document type, date range, department, before the vector search even runs narrows the search space further and reduces noise before reranking has to do the work.

Choosing a vector database for production

The right choice depends more on scale and existing infrastructure than on raw benchmark numbers, but current production deployments converge on a few clear patterns:

  • pgvector on Postgres is the default recommendation for most new RAG projects in 2026. If you're already running Postgres, adding pgvector avoids standing up a separate database system entirely, and it handles up to 50 to 100 million vectors comfortably, more than enough for most business use cases.

  • Qdrant posts strong latency numbers (around 6 milliseconds p50) with native hybrid search support, and is one of the most commonly recommended choices for teams building a new production deployment without existing Postgres infrastructure to lean on.

  • Weaviate also supports hybrid search natively and is a reasonable alternative to Qdrant with similar production maturity.

  • Pinecone is worth its cost when developer velocity matters more than infrastructure cost, typically early-stage teams with small engineering headcount. At real enterprise scale, the same workload on self-hosted Qdrant or Milvus often costs meaningfully less, and for regulated industries with data sovereignty requirements, a fully managed external service can be a non-starter regardless of cost.

  • Milvus is the choice once you're genuinely operating at billion-vector scale, past what most business use cases will ever reach.

5-layer RAG system architecture diagram

Evaluation: measuring quality before a customer does

Open-source frameworks like RAGAS and DeepEval give a standardized way to evaluate a RAG pipeline against defined metrics, context relevance, context recall and precision, and faithfulness (whether the generated answer actually reflects what was retrieved), rather than eyeballing whether responses sound plausible. These frameworks typically use an LLM-as-judge pattern under the hood, a separate model scoring each response on a defined scale, which scales far better than human review for high-volume systems but carries a real caveat: judge models have their own biases and blind spots, and results should be spot-checked against human judgment periodically, not trusted blindly.

This evaluation work needs to happen before launch, against a test set built from real or realistic questions, not just after something goes wrong in production.

Monitoring: catching regressions in production, not after complaints

Evaluation at launch tells you the pipeline worked on test day. Monitoring tells you it's still working three months later, after document updates, embedding model changes, or usage patterns shifted in ways nobody explicitly tested for.

A workable production pattern: sample 5 to 10 percent of live queries for full evaluation rather than trying to score every single interaction, log faithfulness and relevancy scores to a dashboard (LangSmith, Langfuse, and TruLens are common choices), and set an explicit alert threshold, a seven-day rolling faithfulness average dropping below a defined floor is a concrete, actionable signal rather than a vague sense that answers feel worse lately.

Indexing refresh cadence is part of this too, and it should match how fast the underlying content actually changes: daily refreshes for dynamic content like a product catalog or compliance documentation, hourly for genuinely real-time use cases like live customer support, and a full re-index on a weekly cadence to absorb embedding model upgrades or chunking strategy revisions cleanly rather than letting the index drift into an inconsistent mixed state.

Security and compliance, if the use case needs it

For RAG systems used in regulated industries, banking, insurance, healthcare, government, or anywhere output feeds into a consequential decision, the pipeline can't be treated as a black box. Role-based access control needs to propagate from the source systems into the vector index itself, so a user querying through the RAG interface can never retrieve content they wouldn't have had access to in the original system. Citation and audit trails become mandatory: which document version produced which answer, and for teams operating under frameworks like the EU AI Act, formal documentation of the evaluation results that justified each deployment. Building this in from the start is meaningfully cheaper than retrofitting it after a compliance review flags the gap.

A reference stack that has real production mileage

Python with LangChain or LlamaIndex for orchestration, Qdrant or pgvector for vector storage depending on existing infrastructure, a cross-encoder reranker (Cohere Rerank is a common choice) layered on top of hybrid search, an LLM API from Anthropic or OpenAI for generation, RAGAS for pre-launch evaluation, and LangSmith or a comparable observability tool for production monitoring. This isn't the only combination that works, but it's the one with the most demonstrated production usage as of 2026, and it's a reasonable starting point rather than a mandate.

Real cost comparison

ComponentNarrow deploymentReal production scale
Vector databasepgvector on existing Postgres, near-zero added infra costDedicated Qdrant/Pinecone instance, scales with vector count and query volume
RerankingSkippable at low volumeAdds real per-query latency and cost, justified once quality matters at scale
Evaluation setupA few hours with RAGAS against a small test setOngoing: building and maintaining a representative, evolving test set
MonitoringManual periodic spot-checksDashboard plus alerting, genuine ongoing operational cost

Frequently asked questions

Not with the same rigor. A small, low-stakes internal tool can reasonably skip reranking and heavy monitoring. Query transformation and basic evaluation are worth keeping even at small scale, since they're cheap relative to the quality gap they close.

Ready to Build?

Let's create something together

Get in touch with us today.

The bottom line

The four layers that separate a working demo from a production RAG system, query transformation, hybrid retrieval with reranking, evaluation, and ongoing monitoring, are exactly the layers most tutorials skip because they don't show up as failures in a clean test. They show up three weeks after launch, as a slow drift in answer quality nobody's watching for, or as a support agent confidently citing the wrong policy. Build evaluation and monitoring in from day one rather than as a response to the first bad answer a customer reports.

If your RAG pipeline works in testing but you're not confident it's holding up in production, Flowagenz can audit the retrieval, evaluation, and monitoring layers against your actual query traffic, not just re-check the demo. Happy to walk through your current setup on a short call.

Share Article