AI

Building Production RAG Systems

What actually matters when you move a Retrieval Augmented Generation prototype from a notebook into a reliable production system.

Ankit KumarJan 14, 20267 min read
Diagram of a production Retrieval Augmented Generation pipeline
A production RAG pipeline connects document ingestion, retrieval, evaluation, generation, and source citations.

A RAG demo can look impressive in a notebook, but production systems demand much more than connecting an LLM to a vector database. Reliable retrieval, measurable evaluation, grounded answers, latency control, observability and citation quality determine whether users can actually trust the system.

Retrieval quality beats model choice

Most of the perceived intelligence in a RAG application comes from what the system retrieves, not only from the model that writes the final response. If the retrieved documents are irrelevant, incomplete or outdated, even a strong model will generate weak answers.

Before replacing models, improve document preparation, metadata filtering, chunk quality, hybrid retrieval and re-ranking. These changes often provide a larger improvement than simply choosing a bigger or newer language model.

RAG pipeline showing ingestion, chunking, embeddings, vector search, re-ranking and LLM generation
A reliable RAG system depends on the full retrieval pipeline, not only on the final generation model.

Chunking is a design decision, not a default

Fixed-size chunking is useful as an initial baseline, but it can split a complete idea across multiple chunks. That produces fragmented retrieval results and forces the model to answer with incomplete context.

Structure-aware chunking respects headings, paragraphs, lists, code blocks and tables. This approach is especially useful for technical documentation, policy documents and knowledge bases with clear hierarchy.

Comparison between fixed-size chunking and structure-aware document chunking
Structure-aware chunks preserve context better than arbitrary fixed-size text segments.

Evaluate retrieval and generation separately

Treating RAG as one black box makes debugging difficult. When an answer is wrong, you need to know whether the retrieval layer missed the right source, whether the selected context was poorly ranked, or whether the model failed to use good context correctly.

Evaluate retrieval with questions such as: Did the expected document appear in the top results? Did the most relevant chunk rank highly enough? Then evaluate generation separately for groundedness, correctness, clarity and citation accuracy.

rag-evaluation.ts
const evaluationResult = {
  question: "How does hybrid search improve retrieval?",
  expectedSource: "retrieval-guide.md",
  retrievedSources: ["retrieval-guide.md", "vector-search.md"],
  retrievalPassed: true,
  answerGrounded: true,
  citationAccurate: true,
};

Citations build trust

Users should be able to inspect the sources behind an AI-generated answer. Citations help people verify claims, understand context and decide whether they should rely on the response.

They also help developers debug the system. If a response contains an incorrect claim, the cited context quickly reveals whether the issue came from document ingestion, retrieval ranking or generation behavior.

“A useful RAG answer should not only answer the question. It should also show the user where the answer came from.”

Enjoyed this article?

Get new posts in your inbox.

Occasional writing about software engineering, AI, security, cloud infrastructure, and the projects I build.

No spam. Unsubscribe whenever you want.

Topics

AIRAGLLMLangChainVector Databases

Next article

Understanding Kubernetes from First Principles