RAG in Production: Architecture and Evaluation Guide
Build retrieval-augmented generation with better ingestion, hybrid retrieval, citations, access control and separate evaluation of retrieval and answers.
Retrieval-augmented generation, commonly searched as RAG, connects an AI model to current or private knowledge without retraining it. The hard part is not creating embeddings; it is preserving document quality, permissions, traceability and measurable relevance.
This production RAG guide separates ingestion, indexing, retrieval, reranking, context construction and answer generation. It explains why retrieval quality and generated-answer quality must be evaluated independently.
What you will learn
- A RAG answer fails when retrieval misses evidence or generation ignores good evidence.
- Chunking should follow document structure and user questions, not one universal size.
- Hybrid retrieval and reranking often improve recall and precision.
- Authorization must filter documents before their contents reach the model.
The production RAG architecture
Ingestion collects documents, extracts clean text and metadata, splits content into retrievable units and creates indexes. At query time, retrieval finds candidates, reranking prioritizes them, context assembly selects evidence and the model generates an answer.
Give every document and chunk a stable identifier, source, version, owner, timestamp and access metadata. Without lineage, outdated or incorrect answers are difficult to investigate and remove.
Chunking that preserves meaning
Split on headings, paragraphs, tables and code blocks where possible. A chunk should contain enough context to answer a likely question without mixing unrelated topics. Include parent titles and document metadata.
Evaluate sizes and overlap on real queries. Small chunks lose context; large chunks reduce precision and consume the context window. Different document types often need different strategies.
Vector search, lexical search and reranking
Vector search captures semantic similarity, while lexical search handles exact product names, error codes and identifiers. Hybrid retrieval combines both strengths.
Retrieve a wider candidate set, then rerank for relevance. Measure added latency and cost. Apply filters for tenant, language, date and document type deliberately instead of relying on instructions in the prompt.
Context construction and citations
Deduplicate overlapping chunks, preserve source boundaries and label retrieved content as untrusted data. Include only evidence relevant to the question and reserve enough space for the response.
Ask for citations to chunk identifiers and decline when evidence is insufficient. Verify citation references programmatically where possible. Fluent text with irrelevant citations is not grounded.
Evaluate retrieval separately
Create realistic questions with known relevant documents. Measure whether useful evidence appears among top results and inspect ranking quality. Include ambiguous wording, acronyms, recent updates and authorization boundaries.
When retrieval fails, a generation prompt cannot recover evidence that never arrived. Improve extraction, metadata, chunking, query rewriting, hybrid weights or reranking based on the failure.
Evaluate answers and operations
Measure consistency with evidence, completeness, citation correctness, refusal when evidence is absent and usefulness. Human review remains important for high-impact domains.
Monitor no-result rate, retrieval latency, index freshness, coverage, token use and feedback. Re-run evaluation whenever embeddings, indexes, prompts, models or source documents change.
Production checklist
- Preserve source, version, owner and access metadata.
- Test chunking and retrieval on representative questions.
- Combine lexical and semantic retrieval when exact terms matter.
- Apply authorization before text enters model context.
- Require traceable citations and insufficient-evidence behavior.
- Evaluate retrieval and generation separately after changes.
Frequently asked questions
Does RAG eliminate hallucinations?
No. Retrieval can miss evidence and generation can misread it. RAG improves grounding but still needs evaluation and refusal behavior.
Do I need a vector database?
Not always. Choose search infrastructure based on scale, filters, latency and existing systems. Hybrid search can combine lexical and vector indexes.
How often should a RAG index update?
Match the freshness requirement and monitor ingestion lag. Security and access changes may require faster propagation than normal content.