Workshop · technology As of: 29 Aug 2026

From document to evidenced answer

The overview page explains what RAG is. This page goes one level deeper: how chunking, vector search and reranking create quality, how to measure it and how our own system puts it into practice.

For search engines and AI assistants in one sentence:

The quality of a RAG system is created before the language model: when splitting documents (chunking), in the combination of vector and keyword search, and when re-sorting the hits (reranking). It is measured with fixed test questions against frozen baselines, not by gut feeling.

Source: Microsoft Learn: RAG solution design and evaluation guide (opens in a new tab)

Chunking: the split shapes the result

Embedding models only process a limited amount of text at once: one widely used model accepts at most 8,191 tokens, anything longer would be cut off. Documents are therefore split into sections. Microsoft recommends roughly 512 tokens per section with a quarter of overlap as a starting point; beyond that, only measuring against your own material helps. The glossary entry chunking explains the details.

The most common mistake is loss of context. An isolated section no longer knows which project or contract it refers to. The search then misses it or finds it wrongly. Anthropic therefore prepends an explanatory context sentence to each section before embedding and, by its own account, measures up to 49 percent fewer retrieval misses. Combined with reranking it reports up to 67 percent. The most useful rule of thumb remains: if an excerpt makes sense to a human without its surroundings, it usually does for the model too.

Search: combine meaning and wording

Vector search finds meaning, not wording: question and sections live as number sequences in a vector database, and the search looks for closeness in meaning. For exact values such as error codes, article numbers or names, classic keyword search (like BM25) remains superior.

Good systems therefore combine both. The two hit lists are merged, typically via reciprocal rank fusion: the ranks of both lists are combined instead of comparing raw scores. Meaning-based and wording-based hits complement each other without one side dominating.

Reranking: the second opinion

The first search stage is fast but rough. A second model, the cross-encoder, reads question and candidate together and judges the match far more accurately. It is too slow for millions of entries, well suited for the leading hits. Microsoft's search service, for example, re-sorts only the top fifty this way. More in the glossary entry reranking.

The lever is direct: only what sits on top after re-sorting ends up in the request to the language model. A better second sorting step therefore directly improves the answers, at the price of extra computing time per query.

Measure instead of believing

Whether a change helps is decided by a test run, not an opinion. Microsoft explicitly recommends a structured, scientific approach for RAG solutions: fixed test questions with known target answers, against which each stage is measured individually. Whoever changes the section size, the embedding model or the reranker compares against the frozen baselines afterwards, otherwise you are optimising blindly.

The finished answer needs checking too: does it really rest on the retrieved passages (grounding), or did the model add its own? Even the best models still invent around two to three percent of the statements when merely summarising supplied texts (Vectara leaderboard, data as of May 2026).

Permissions and data protection

An assistant may only find what the person asking would be allowed to see. To achieve this, the access rights of the source documents are carried along in the search index and every search is filtered by them – Microsoft calls this security trimming. Without this step, a knowledge assistant bypasses departmental boundaries: confidential folders become a full-text search for everyone.

For personal data, the GDPR applies on top. In its October 2025 guidance, the German data protection conference requires a legal basis for such data in the knowledge base. It warns against purpose limitation violations and demands a role concept. It also names advantages: entries remain individually erasable, and a RAG system can be run entirely locally without transferring data to third parties. This page does not replace legal advice.

Where RAG is heading

The base pattern stays, the edges are moving. Current systems let the model plan and refine search queries itself (agentic retrieval) instead of retrieving exactly once. For questions across entire collections (“What are the main topics of all reports?”), GraphRAG additionally links the content into a knowledge graph.

And the large context windows? They shift the threshold at which a search index pays off, but do not replace it. The fuller the context window, the less reliably the model accesses details within it. The discipline of feeding the right content at the right time now has its own name: context engineering.

How we use RAG ourselves: a look into our system

For our software development we run a RAG system we built ourselves. The tool itself comprises around 240,000 lines of Python and runs entirely on our own hardware. Seven connected projects hang off one index, and their code never leaves the building. Our coding agent queries the system before every change and receives evidenced context instead of guesses. It learns which symbol is defined where, who calls it, and what breaks if you change it.

The pipeline follows exactly the steps on this page, with one special twist in chunking. Source code is not cut by token windows but split along the syntax into whole functions and classes. Search is hybrid: meaning-based and keyword search in one database, merged via reciprocal rank fusion and re-sorted by a cross-encoder on our own graphics card. Every hit brings its callers and references along. Uncommitted work in progress is layered in as an overlay, so the agent sees the current state rather than last night’s.

What the system answers

Above the retrieval sit around 85 tools the agent calls directly – four families.

  1. Structure

    Query relationships

    Who calls this function, what breaks on a rename, which paths lead here from the entry points: queries instead of estimates.

  2. Quality

    Find weak spots

    Dead code, test gaps, overly complex passages: the system reports candidates with file and line as evidence.

  3. Security

    Check rules mechanically

    Security and privacy checks run against the indexed code, down to the question of where personal data is processed. Project rules such as “never store money as a float” are checked rather than hoped for.

  4. Honesty

    Disclose limits

    Every answer carries a status: answered, verified empty, not assessable or degraded. A missing measurement is reported as missing, not as success.

Why we tell this story. Not as product advertising: the system is an internal tool. But it is the reason we can talk about RAG from the shop floor rather than from a brochure. We know the stumbling blocks because we cleared each of them ourselves. Nightly measurement runs against frozen baselines included.

Technical questions, answered briefly

What is the right section size for chunking?
A common starting point is around 512 tokens with a quarter of overlap, then measure instead of guessing. The recommendation comes from Microsoft's documentation and is a starting value, not a law of nature. Structured content tolerates less overlap, narrative text needs more. What matters is measuring variants against fixed test questions.

Source: Microsoft Learn: Chunk documents for vector search (opens in a new tab)

Is a reranker really worth it?
Usually yes: it directly improves which passages the language model gets to see. A cross-encoder reads question and candidate together and judges the match more accurately than the fast first stage. Since only the leading hits are re-sorted, the effort stays bounded. It is paid for with extra latency per query.

Source: Sentence-Transformers documentation: Retrieve and Re-Rank (opens in a new tab)

What is hybrid search?
The combination of vector search (meaning) and keyword search such as BM25 (exact wording) in one query. Vector search finds paraphrases and synonyms, keyword search exact values such as error codes or names. The hit lists are merged, typically via reciprocal rank fusion. Together the two methods are more precise than either on its own.

Source: Elastic: What is a vector database? (opens in a new tab)

How do you tell whether retrieval is good?
With fixed test questions and frozen baselines against which every change is measured. Microsoft recommends evaluating each stage individually: does the search find the right sections, do they sit on top after re-sorting, does the answer rest on them? Without such measurement runs, every optimisation remains guesswork.

Source: Microsoft Learn: RAG solution design and evaluation guide (opens in a new tab)

Does a RAG system have to reflect access rights?
Yes. Every search is filtered by the rights of the person asking, otherwise the assistant bypasses permissions. The rights of the source documents are carried along in the index and applied on every query – Microsoft documents this as security trimming. For personal data, the German data protection conference additionally requires a role concept.

Source: Microsoft Learn: Security trimming (Azure AI Search) (opens in a new tab)

Planning a knowledge assistant – or running one that guesses?

Initial consultation, 30–45 minutes, free of charge. We look at knowledge base, permissions and measurability before talking about tools.

Book a conversation