Introduction
Retrieval-Augmented Generation (RAG) has moved from experimental prototype to production requirement for teams building AI applications that need to answer questions over private, up-to-date, or domain-specific data. A large language model alone is bounded by its training cutoff and its parametric memory. RAG solves this by retrieving relevant documents at inference time and feeding them to the model as context, grounding answers in sources you control. But "retrieval plus generation" is only the starting point. A production RAG system requires careful choices around document chunking, embedding models, vector stores, reranking, prompt design, evaluation, and observability.
This article walks through the architecture of a production RAG system, the key implementation decisions, worked examples, and the limitations teams should plan for. All examples are hypothetical and intended to illustrate patterns, not to represent a deployed system.
Core Architecture
A production RAG pipeline has two distinct stages: indexing and retrieval-and-generation.
Indexing pipeline
The indexing pipeline prepares documents so they can be retrieved efficiently at query time.
- Document ingestion. Source documents arrive from multiple locations: internal wikis, PDFs, support tickets, product documentation, and structured databases. The ingestion layer normalizes formats, extracts text, and attaches metadata such as source URL, author, last-modified date, and access permissions.
- Chunking. Long documents are split into smaller chunks so each retrieved piece fits within the model's context window and remains semantically coherent. Common strategies include fixed-size chunking, recursive character splitting, and semantic chunking based on paragraph or section boundaries. Overlapping chunks help prevent cutting a relevant sentence in half. Teams typically start with 500-1000 token chunks with 100-token overlap, then adjust based on retrieval quality metrics.
- Embedding. Each chunk is converted into a dense vector using an embedding model. The model choice determines what kinds of similarity the system can capture: semantic, keyword, code, or multilingual. Teams often evaluate multiple embedding models (e.g., all-MiniLM-L6-v2, bge-large-en-v1.5) to determine which best captures domain-specific nuances.
- Storage. Chunks, their vectors, and metadata are stored in a vector database or a hybrid search index that supports both vector similarity and traditional filtering. Popular options include Pinecone, Weaviate, Milvus, and Elasticsearch with k-NN plugin.
Retrieval and generation pipeline
When a user asks a question, the retrieval-and-generation pipeline runs.
- Query embedding. The user's question is embedded with the same model used during indexing.
- Retrieval. The system queries the vector index for the most similar chunks, often combined with keyword search (hybrid search) and metadata filtering. Top-k results are typically between 5 and 20 to balance relevance and context window constraints.
- Reranking. A cross-encoder or lightweight reranker reorders the initial results to improve relevance before they reach the model. This step can significantly improve answer quality by filtering out marginally relevant but noisy chunks.
- Context assembly. The top chunks are assembled into a prompt, with citations attached to each source. Careful assembly ensures the model stays within context window limits while preserving the most relevant information.
- Generation. The model answers the question using only the assembled context, ideally citing sources for each claim. The prompt should explicitly instruct the model to cite sources when making claims.
Chunking and Embedding Strategies
Chunking is one of the most consequential design decisions. A chunk that is too large dilutes signal with irrelevant text; a chunk that is too small loses context. Teams often start with recursive character splitting at 500-1000 tokens with 100-token overlap, then tune based on retrieval quality metrics like precision@k and answer groundedness.
Embedding model selection should match the data. General-purpose text embeddings work for prose, but codebases benefit from code-aware embeddings, and multilingual corpora require models trained on the relevant languages. Teams should evaluate multiple embedding models to determine which best captures domain-specific nuances and avoids bias.
Vector Stores and Hybrid Search
Pure vector similarity misses exact matches, such as product codes, error messages, or proper nouns. Hybrid search combines vector similarity with BM25 or keyword search, then fuses the results using reciprocal rank fusion or a learned ranker. Metadata filtering - for example, restricting results to documents the user is permitted to see - is essential in multi-tenant or permissioned environments.
Reranking and Context Assembly
Initial retrieval often returns twenty to fifty candidates. A cross-encoder reranker scores the query against each candidate more precisely than a bi-encoder embedding, allowing the system to pass only the top five to ten chunks to the language model. Context assembly must respect the model's context window, prioritize the most relevant chunks, and insert citation markers so answers can be traced back to sources.
Evaluation
Production RAG systems need offline and online evaluation. Offline metrics include retrieval recall (does the right document appear in the top k?), answer groundedness (is every claim supported by retrieved context?), and answer relevance. Human evaluators should review a sample of queries monthly. Online signals include user thumbs-up/down, follow-up questions, and agent escalation rates. Evaluation datasets must be hypothetical or anonymized; never evaluate on real user data without consent.
Observability and Maintenance
Log every query, the retrieved chunks, the reranked order, the prompt sent to the model, and the generated answer. Track latency per stage, token usage, and error rates. Documents change over time, so the indexing pipeline must support incremental updates, deletion of obsolete chunks, and re-embedding when the embedding model changes.
Limitations
RAG does not eliminate hallucination; a model can still misinterpret retrieved context. Retrieval quality caps answer quality: if the right document is not retrieved, the model cannot answer correctly. Permission-aware retrieval adds operational complexity, and vector embeddings can leak sensitive information if access controls are not enforced at the storage layer.
Conclusion
Production RAG is an engineering discipline, not a single API call. Start with a simple pipeline - ingestion, chunking, embedding, vector search, and generation - then add reranking, hybrid search, evaluation, and observability as you learn where the system fails. All examples in this article are hypothetical; teams should validate each design decision against their own data, users, and requirements.
For related guidance on model selection, see Evaluating and Selecting AI Models for Production Workloads.