How to Design a RAG System Architecture
A RAG system has two pipelines: one indexes documents, the other answers questions from them. Here is how to design each part so answers stay grounded.
On this page
Short answer
A RAG architecture is the design of the two pipelines that let a language model answer from your documents: an indexing pipeline that splits, embeds and stores content, and a query pipeline that retrieves the best passages, assembles them into a prompt and generates a grounded answer, with guardrails and logging around both.
What is a RAG architecture?
A RAG architecture is the design of the two pipelines that let a language model answer questions from your own documents: an indexing pipeline that prepares content, and a query pipeline that finds the best passages and turns them into a grounded answer. Retrieval-augmented generation, or RAG, grounds the model in retrieved text instead of letting it answer from memory alone.
The two pipelines run at different times and speeds. Indexing runs when documents change, and it can take minutes, since nobody is waiting on it. The query pipeline runs on every question, so it must answer in seconds. Designing them separately, with a clear contract between them, is what keeps the system both fresh and fast.
| Pipeline | Job | Parts |
|---|---|---|
| Indexing | Prepares documents for search | Source connectors, chunking, embeddings, vector store |
| Query | Finds passages and writes the answer | Query embedding, retrieval, re-ranking, prompt assembly, generation |
A third layer wraps both pipelines: guardrails that block off-topic or unsafe answers, and logging that records what was retrieved and said. Without that layer, a team cannot tell whether a bad answer came from bad documents, bad retrieval or a bad prompt, and fixing it becomes guesswork. For the production side, see how enterprise RAG runs in production.
How does the indexing pipeline work?
Indexing starts at the sources. Connectors pull documents from the help centre, the wiki, ticket systems and shared drives, and each document keeps its title, owner, update date and access rules as metadata. The metadata matters later: it lets the query pipeline filter by what the user is allowed to see and prefer current documents over stale ones.
Each document is then split into chunks, usually a few hundred words each, with overlap so a sentence is not cut in half at a boundary. Chunks that are too large dilute the match, while chunks that are too small lose the context around a fact. Each chunk is turned into an embedding by a hosted model and stored in the vector store with a link back to its source.
Indexing must also handle change. When a document is edited, its old chunks are replaced rather than left beside the new ones, and when a document is deleted, its chunks go too. A nightly check compares the source list with the index and flags documents that failed to index, so stale content does not linger. See how to implement RAG for the build steps behind this pipeline.
How do you choose the vector store and index?
The vector store is where embeddings live, and its job is to return the nearest chunks to a query vector in milliseconds. Managed vector databases handle scaling, backups and updates, while a self-hosted store gives more control over cost and data location. Most teams start managed, since the store is rarely the part that decides answer quality.
The index inside the store trades speed for accuracy. An approximate index, such as a graph-based one, returns near neighbours fast enough for large collections, while an exact search is slower but never misses a close chunk. Small collections can use exact search; large ones need the approximate index, and the choice is revisited as the collection grows.
Namespaces and filters keep the store organised. One namespace per product or customer keeps results separate, and metadata filters limit retrieval to documents the user may see or to a date range. Without filters, a query can return a draft, an old version or a document from another product, and the answer will cite the wrong source.
How does retrieval work at query time?
Retrieval starts by turning the question into the same kind of embedding used at indexing time, then searching the vector store for the nearest chunks. Vector search finds passages that mean the same thing as the question, while keyword search catches product names, codes and exact terms that embeddings sometimes miss. A blend of the two usually beats either one alone.
The first pass returns ten or twenty candidates, and a re-ranking step scores them against the question and keeps the best five. Re-ranking costs more per query, so it is worth adding only after measuring whether the first pass is good enough. Query rewriting can help too: a short or vague question is expanded with context from the conversation before it is searched. See how re-ranking works for that stage in more detail.
Retrieval quality decides answer quality more than the model does. If the wrong passages are retrieved, even a strong model will write a confident wrong answer. Teams test retrieval on real questions first, checking whether the right passage appears in the top five, before they judge the answers the model writes.
How does generation use what retrieval finds?
Generation takes the retrieved passages and assembles them into a prompt with the question, then asks the model to answer using only those passages. The prompt should tell the model to say it does not know when the passages do not contain the answer, and to cite the passages it used. Citations let users check the answer against the source instead of trusting it blindly.
The context budget is the main limit. A model can only read so many tokens at once, so the prompt must fit the best passages, the question and the instructions inside that budget. Sending ten long passages wastes tokens on weak matches; sending the best five with tight chunks leaves room for a clear answer. The budget is set per model and checked in testing.
Model choice matters less than retrieval, but it still matters. An instruction-tuned model follows the 'use only these passages' rule better than a raw completion model, and a smaller, cheaper model is often enough once retrieval is good. Teams pick the model after retrieval works, not before, and they keep the choice easy to change.
Where do guardrails and observability sit?
Guardrails sit around the query pipeline, not inside the model. They check the question before retrieval, blocking requests outside the system's scope, and they check the answer before it reaches the user, blocking off-topic, unsafe or empty answers. A guardrail that only checks the final answer is weaker than one that also checks what was retrieved.
Observability means logging the full path of each question: what was retrieved, what the prompt contained, what the model said, and what the user did next. When an answer is wrong, the log shows whether retrieval, the prompt or the model was at fault, which decides the fix. Without logs, every bad answer looks the same and fixes are guesses.
Evaluation runs on a schedule, not once. A set of real questions with known good answers is run through the system weekly, and the share of answers that cite the right passage is tracked. When the score drops, the team looks at the retrieval logs first, since retrieval is the usual cause. See RAG best practices for the operating rules that keep answers accurate.
How do you design a RAG architecture in 6 steps?
Designing a RAG architecture is a sequence of choices, one per layer, made before any code is written. The steps below fit a first system for one product and one document set, and each choice can be revisited as the collection grows.
- List the sources. Name every document set, its owner, its update rhythm and who may see it.
- Fix the chunking and embedding. Choose a chunk size and an embedding model, and test them on real questions before building further.
- Choose the vector store. Start with a managed store, one namespace per product, and metadata filters for access and dates.
- Design retrieval. Blend vector and keyword search, add re-ranking only after measuring the first pass, and set the number of passages per answer.
- Write the generation rules. Set the context budget, the citation rule and the 'say you do not know' instruction in the prompt.
- Add guardrails and logging. Log every question's retrieval and answer, and run the evaluation set weekly.
Build the smallest version that answers real questions, then measure retrieval before adding parts. A system whose retrieval is measured beats a larger system whose retrieval is assumed.
Example (hypothetical): a support team designs its RAG system
Example (hypothetical): a support team has 2,000 help articles and wants a chatbot that answers from them. The team indexes the articles in chunks of about 400 words, which gives roughly 12,000 chunks, and stores them in a managed vector database with one namespace for the public help centre and one for internal guides.
At query time the system retrieves 20 candidates with a blend of vector and keyword search, re-ranks them and keeps the best 5 for the prompt. The context budget is 4,000 tokens, and the five passages use about 2,500, leaving room for the question and instructions. The model is told to cite the passages it used and to say it does not know when they do not contain the answer.
In the first month, 6,000 questions arrive and 4,800 are answered with a citation, which is 80 in 100. Of the 1,200 without a citation, the logs show 900 failed at retrieval, so the team fixes chunking on the longest articles first instead of changing the model. The fix lifts cited answers to 5,400 of 6,000, or 90 in 100.
What are the common mistakes?
The most common RAG architecture mistakes are indexing everything without access rules, judging answers before testing retrieval, and shipping with no logging.
- Indexing without access rules. If the store holds documents the user may not see, retrieval can leak them into an answer.
- Chunks too large or too small. Large chunks dilute the match, while tiny chunks lose the context that makes a fact true.
- Skipping re-ranking measurement. Adding re-ranking before measuring the first pass spends money without knowing if it helps.
- No evaluation set. Without real questions and known good answers, the team cannot tell whether a change helped or hurt.
- Treating the model as the fix. When answers are wrong, the cause is usually retrieval or stale documents, not the model.
Review the architecture when the document set grows or the questions change. A design that worked for 2,000 articles may need new namespaces and filters at 100,000, and a retrieval setup that worked for short questions may need rewriting for long ones.
Key takeaways
- RAG has two pipelines: indexing prepares documents, the query pipeline answers from them
- Chunk size, embeddings and the vector store decide what retrieval can find
- Blend vector and keyword search, and add re-ranking only after measuring the first pass
- Generation needs a context budget, citations and a rule to say it does not know
- Log every question's retrieval and answer, and evaluate on real questions weekly
Frequently asked questions
What is a RAG architecture?
It is the design of the two pipelines that let a language model answer from your documents: indexing, which splits, embeds and stores content, and the query pipeline, which retrieves passages and generates a grounded answer. Guardrails and logging wrap both pipelines so bad answers can be traced to their cause.
How big should RAG chunks be?
A few hundred words per chunk suits most document sets, with overlap so sentences are not cut at a boundary. Chunks that are too large dilute the match, while chunks that are too small lose context. Test two sizes on real questions and keep the one whose retrieval scores better.
What is hybrid search in RAG?
It is the blend of vector search, which finds passages with similar meaning, and keyword search, which catches exact names, codes and terms. Vector search alone can miss a product name, while keyword search alone misses rephrased questions. A simple blend of the two beats either one alone on most document sets.
When should a RAG system use re-ranking?
After measuring the first retrieval pass. If the right passage is already in the top five most of the time, re-ranking adds cost without much gain. If it is often ranked sixth or lower, a re-ranker that scores the top twenty candidates and keeps the best five is usually worth the extra cost per query.
How do you know if a RAG system is working?
Run a set of real questions with known good answers through the system on a schedule, and track how often the answer cites the right passage. Check retrieval quality first, since it decides answer quality. When the score drops, look at the retrieval logs before changing the model.
Should a small team build or buy a RAG system?
Most small teams should buy the parts that are not their product: a managed vector database, a hosted embedding model and a hosted language model. Build only the indexing and retrieval logic that is specific to their documents, since that is where answer quality is decided.