RAG Systems Explained: Architecture, Components & Implementation
A comprehensive guide to RAG systems. Architecture, core components, pipeline design and implementation considerations for production deployments.
A comprehensive guide to RAG systems. Architecture, core components, pipeline design and implementation considerations for production deployments.
A RAG system (retrieval-augmented generation) connects a language model to your organisation's data so it can answer questions grounded in real documents rather than general training knowledge. It's the most practical AI architecture for business knowledge applications.
If you have not read our intro piece, start with What Is RAG? for the basics. This article goes deeper into the architecture.
Every RAG system has these building blocks:
Handles ingestion. Takes your raw documents (PDFs, Word files, HTML, databases) and converts them into text. This might involve OCR for scanned documents, table extraction, or stripping formatting.
Splits processed text into smaller pieces (chunks) that the retrieval system can index and search. Chunk size, overlap, and boundary strategy all affect quality. Too small and you lose context. Too large and you dilute relevance.
Converts text chunks into numerical vectors (embeddings) that capture semantic meaning. Similar concepts end up as similar vectors. Popular choices include OpenAI's text-embedding-3-large, Cohere Embed, and open-source models like BGE.
Stores embeddings and enables fast similarity search. When a query comes in, the vector DB finds the chunks most semantically similar to the question. Options include Pinecone, Weaviate, pgvector, and OpenSearch.
Orchestrates the search. Converts the user query to an embedding, queries the vector DB, and optionally applies re-ranking, filtering, or hybrid search (combining vector + keyword search).
Takes the retrieved chunks plus the user's question and generates a natural-language answer. GPT-4, Claude, and Llama are common choices.
Structures the output: source citations, table formatting, stripping unsafe content, or converting to the format your application needs.
Here's the end-to-end flow:
The bottleneck is almost always retrieval, not generation. If the system retrieves the wrong chunks, the LLM cannot save it. Focus your optimisation effort on steps 1 to 3.
Options range from simple (fixed-size with overlap) to sophisticated (semantic chunking based on topic boundaries). For most business documents, 500 to 1000 token chunks with 100 token overlap is a solid starting point.
After initial retrieval, a re-ranker model scores the top results for relevance to the specific question. Adds latency but significantly improves answer quality. Cohere Rerank and cross-encoder models are popular choices.
Tagging chunks with metadata (document type, department, date, access level) lets you filter results before or during retrieval. Critical for multi-tenant systems and access control.
You cannot improve what you do not measure. Key metrics for RAG systems:
Build an evaluation dataset early. Real questions from real users with expected answers. Run it after every change.
A retrieval augmented generation (RAG) system connects a language model to an organisation's own data so it can answer questions grounded in real documents rather than general training knowledge. A RAG system has three main phases: ingest, retrieve and generate. RAG is the most practical AI architecture for business knowledge applications.
A retrieval augmented generation (RAG) system has seven building blocks. A document processor turns files into text, a chunking engine splits text into pieces, and an embedding model converts chunks into numerical vectors. A vector database stores them for similarity search, a retrieval engine runs the search, a large language model (LLM) writes the answer, and a response formatter adds source citations.
Wrong answers from a retrieval augmented generation (RAG) system usually trace back to retrieval, not generation. If the system retrieves the wrong chunks of text, the language model cannot save it, so optimisation effort belongs in ingestion, the search and assembling the context. Chunking strategy, the embedding model and the retrieval method matter more than which large language model (LLM) you choose.
For most business documents, chunks of 500 to 1000 tokens with a 100 token overlap are a solid starting point for a retrieval augmented generation (RAG) system. Chunks that are too small lose context, and chunks that are too large dilute relevance. Options range from simple fixed-size chunks with overlap to semantic chunking based on topic boundaries.
Measure a retrieval augmented generation (RAG) system on retrieval precision, retrieval recall, answer faithfulness, answer relevance and hallucination rate. Precision asks whether retrieved chunks are relevant, recall whether all relevant chunks are found, and faithfulness whether the answer accurately reflects the sources. Build an evaluation dataset early from real user questions with expected answers, and run it after every change.
Ask the author
Ask it here and it comes straight to the founder. No sales call, no obligation, and a real answer even if the answer is that you do not need us.
Kasun Wijayamanna
Founder, replies within one business day
Tell us what you are working on. We will come back with a practical recommendation and clear next steps.
Built here. Your data stays here.
Thanks for reaching out. We will get back to you within one business day.
See what else we do