Build a RAG system in the order that makes it answer well
A RAG system connects vector search to a language model so assistants answer from your own documents. This guide walks the pipeline: data preparation, chunking strategies, embedding models, vector database choice, retrieval with hybrid search, evaluation with RAGAS-style metrics, and production rollout with permissions and monitoring. Pexon builds RAG platforms; retrieval decides whether the assistant is trusted.
The claim: retrieval quality dominates model choice
A RAG system (retrieval-augmented generation) connects a vector search to a language model, so your assistants answer from your own documents instead of from the model's training data. Before the model writes a word, the system finds the relevant passages, hands them over with the question, and the model answers from that context. The architecture is settled; the engineering is in the retrieval layer.
This guide is the complete build, in the order the work actually runs: data preparation, chunking, embeddings, the vector database, retrieval, evaluation, and the production rollout with permissions and monitoring. Each section names the decision, what the choice changes, and the failure mode you are buying if you skip it.
Our position, stated plainly so it can be argued with: on a well-built retrieval pipeline, a mid-size open-weight model beats a frontier model bolted onto bad retrieval. The failures users notice in enterprise RAG — the assistant answering from the wrong document, or refusing to answer from the right one — are retrieval failures wearing a model failure's clothes, and the fix is almost never a bigger model.
The pipeline
Six steps, and the order is the method
- Prepare the data before you chunk a single document. The retrieval layer inherits every defect of the corpus. Deduplicate, normalise formats, decide what belongs in the index at all, and record the provenance of each document. Garbage in, plausible-sounding garbage out.
- Chunk by meaning, not by character count. The chunk is the unit the model reads, so its boundaries decide what the search can find. Fixed-size chunks are the floor, recursive and semantic strategies the next step up — the comparison table below scores them against document types.
- Embed with a model matched to your language and your domain. The embedding model turns chunks into vectors, and the distance between vectors is what search ranks. Match the model to your language and your document domain; a general model on technical documents retrieves differently from one tuned on them.
- Choose the vector store on operations, not on benchmarks. The database holds the vectors and answers the similarity search. The decision that matters is managed versus self-hosted, because it decides where your data lives and who operates the search layer — then hybrid search for the retrieval itself.
- Evaluate before you celebrate. A RAG system without a test set is a demo. Build a set of real questions and golden answers, measure faithfulness, context recall and context relevance, and record the numbers. The metrics table below is the minimum set.
- Roll out with permissions, monitoring and an owner. Permission-aware retrieval — the index knows who may read what — is what turns the assistant into something a compliance officer signs off. Monitoring and an owner come with it; an unowned assistant is a liability with a chat window.
Chunking strategies
Which chunking strategy fits which document
| Strategy | Fits | Advantage | Weakness |
|---|---|---|---|
| Fixed-size | Uniform records, logs, well-formed entries | Trivial to implement and reproduce | Splits meaning mid-sentence; poor on prose |
| Recursive | Code, structured text, nested documents | Respects natural boundaries like paragraphs and sections | Still heuristic; needs tuning per corpus |
| Semantic | Prose, contracts, engineering documentation | Chunks follow meaning, so retrieval matches intent | Costs an extra embedding pass; slower to build |
Qualitative guidance from retrieval engineering practice, not a measured benchmark — the right size and overlap depend on your documents, your model and your questions. What is universal: measure the outcome on your own test set, not on a published number.
The vector store and the embeddings are one decision, not two
The vector database and the embedding model are usually chosen separately and regretted together. The store decides scaling, hybrid search and the operations burden; the embedding model decides what the search means. The pairing matters because hybrid search — keyword and vector together — is where most production systems land, and it constrains both choices.
The managed-versus-self-hosted question is the one to decide first, because it is the data-sovereignty question. A self-hosted vector store on your own infrastructure keeps the corpus inside the estate, which is the difference between a defensible DSGVO story and a subprocessor list. The cost is operations: a vector database is infrastructure with an owner, backup and a recovery drill, not a library you import.
On the embedding side, match the model to your language and your domain. The sibling site's own comparison of German-language embedding models found the gap between a tuned model and a generic one is real and measurable on domain documents — the same logic applies to any industry vocabulary. Start with the strongest model for your language, then evaluate whether a cheaper one holds the retrieval quality.
Executable artefact
The minimal pipeline, in the shape a prototype should take
Versions and providers are placeholders. The shape is the point: documents in, chunks out, vectors into the store, and the retrieval call that answers a question.
# Minimal RAG pipeline sketch (conceptual, not a stack recommendation)
# 1. Load and prepare
documents = load_corpus("documents/") # dedupe, normalise, provenance
# 2. Chunk
chunks = semantic_chunk(documents) # or recursive; measure, then pick
# 3. Embed
vectors = embed(chunks, model="your-language-model")
# 4. Store
collection = vector_store.add(vectors) # hybrid search on, permissions tagged
# 5. Retrieve
hits = collection.search(query, top_k=8) # permission-filtered at query time
# 6. Generate
answer = llm(context=hits, question=query)
# 7. Evaluate — before you call it done
metrics = ragas.evaluate(testset, answers) # faithfulness, context recall, relevanceSeven numbered lines, one per pipeline step, because the evaluation line is the one most prototypes are missing.
Evaluation is a test set, three metrics and a recorded baseline
The evaluation question — is this system good enough — is answered by measurements on your own documents, and the minimum set has three metrics. Faithfulness asks whether the answer follows the retrieved context rather than inventing beyond it. Context recall asks whether retrieval found what was needed to answer. Context relevance asks whether what it found was on topic rather than merely similar.
The test set is the unglamorous half of the work. It needs real questions from the people who will use the system, golden answers you agree on, and a spread across the document types and difficulty levels the deployment will actually see. Twenty questions from the pilot users are worth more than two hundred generated from a template, because the generated set encodes the assumption that you already know what will be asked.
The baseline is what makes the metrics useful. Record the numbers before you tune anything, then change one variable at a time — chunk size, embedding model, retrieval strategy — and compare. The whole discipline collapses without the baseline, because the improvement you cannot measure is the improvement you will re-argue at the next review.
Our position: a RAG demo that answers a question you asked is not a working system. A working system is one whose retrieval quality you can quote, whose permissions you can audit and whose failures you have already seen in evaluation.
RAG metrics
The three numbers that tell you whether retrieval works
| Metric | Question it answers | Direction to move |
|---|---|---|
| Faithfulness | Does the answer stay inside the retrieved context? | Up — hallucinations are context drift, not model failure |
| Context recall | Did retrieval find the passage the answer needed? | Up — a low score means the chunking or the index is losing the document |
| Context relevance | Of what was retrieved, how much was on point? | Up — noise in the context degrades the answer even when recall is fine |
The three form a chain: recall says whether the knowledge is findable, relevance says whether the search is precise, faithfulness says whether the model stays honest with what it got. Fix them in that order.
The production rollout: permissions, monitoring, and an owner
The step that separates a company brain from a prototype is permission-aware retrieval. The index carries access metadata per document — which roles may read it — and the query is filtered by the caller's identity before the search runs, so the model never sees context the user could not open directly. That single mechanism is what lets a compliance officer sign off, because it preserves the access rules the organisation already operates.
Monitoring is the second half: retrieval quality degrades as documents are added, and nobody notices until the assistant starts answering from the wrong source. Track the metrics against the baseline, watch the new-document pipeline for format drift, and treat the retrieval layer as infrastructure with an owner and an on-call rotation, not as a service someone deployed once.
The DSGVO angle follows from the architecture. A self-hosted vector store with permission-filtered queries and controlled logs keeps the corpus and the access record inside the estate, which is the argument a European industrial company can defend. The enterprise RAG platform we build is exactly this: retrieval with permissions as the boundary, evaluation as the contract, and the rollout run like infrastructure.
Questions we get asked when the prototype is working and the production build is not
What does RAG mean?
RAG stands for retrieval-augmented generation. Before the model answers, the system searches your documents for relevant passages and hands them to the model alongside the question. Answers then rest on your knowledge instead of the model's training cutoff, which is why RAG is the standard architecture for company chatbots and document search.
How long does it take to build a RAG system?
A first working prototype takes a few days. A production system with clean data preparation, evaluation and a permission model takes several weeks, because the retrieval quality work is iterative: chunking choices, embedding selection and evaluation feedback loops each need their own pass.
Which vector database should we start with?
Start with whatever your stack already runs, then judge on scaling, hybrid search and operations rather than benchmark hype. The comparison that matters is between managed and self-hosted options, because the choice decides where your data lives and who operates the search layer.
How do I know if my RAG system works well?
Measure it on your own test set with retrieval and generation metrics: faithfulness (does the answer follow the retrieved context), context recall (did retrieval find what was needed) and context relevance (was what it found on topic). The metrics are meaningless without a test set drawn from your real documents and questions.
What does a RAG system cost?
Open-source components carry no licence fees; the costs are infrastructure, the vector database and model API usage. The honest estimate for a production system with real availability and monitoring lands in the tens of thousands of euros, and the fixed-price entry sprint Pexon offers is a controlled way to find out before committing.
Next step
Build the retrieval layer once, with the evaluation already attached
Fixed-price entry sprint, four weeks. We build the data preparation, the chunking, the vector store and the evaluation harness for one use case, and hand you the retrieval-quality numbers instead of a demo. The sprint is yours to keep whether or not we build the production platform.
