← blog · December 3, 2026

Retrieval Quality in RAG: Chunking, Hybrid Search, Reranking and Measuring Before You Tune

Most RAG failures happen before the model, when the wrong chunk is retrieved. Building an evaluation set, structure-aware chunking, merging BM25 and vector search with RRF, adding a reranker, and the silent pitfalls.

When a RAG (retrieval-augmented generation) system gives a wrong answer, the first reflex is to blame the model, lengthen the prompt, or switch to a bigger model. Yet most of these failures happen before the model is involved at all: the right information simply is not in the context it was given. The model builds a plausible answer from wrong or incomplete pieces. This post covers the two steps where the problem usually lives, splitting documents into chunks and retrieving the right ones, and how to manage their quality with measurement instead of guesswork.

Build the measurement first

Before you change chunk size, embedding model, or search method, you need an evaluation set. Without one, every change amounts to looking at a handful of questions and deciding it "feels better".

An evaluation set is a simple table: a question of the kind real users ask, and the chunk or document ID that contains its answer. Between 50 and 200 questions is enough for most systems to start. Take part of them from real usage logs. Questions you write yourself tend to borrow the document's own wording, which makes retrieval look easier than it is. Users ask with words the document never uses, with abbreviations and with typos.

Two metrics usually cover the retrieval step:

  • Recall@k: is the correct chunk within the top k results? If you pass five chunks to the model, k is five. If the right chunk is not among them, no model can find the answer.
  • MRR (mean reciprocal rank): at what position does the correct chunk appear? This matters once you want to shrink the context or cut cost.

Keep these separate from generation. Grading answer correctness with a model is useful, but it does not replace a retrieval metric: when an answer is bad, only separate measurements tell you whether retrieval or generation failed.

Chunking: three approaches

Fixed-size chunking. Split text into a fixed number of tokens with some overlap between chunks. It is easy to set up and works surprisingly well for plain prose. Its weakness is that it cuts sentences, tables and code blocks in half.

Structure-aware chunking. Use the document's own boundaries: Markdown and HTML headings, paragraphs, code blocks, table rows. For structured text such as technical documentation, contracts and manuals this wins clearly, because the author already divided the topic. If a section is too long, split it internally by size.

Semantic chunking. Compare embeddings of consecutive sentences and split where the topic shifts. On paper it is the smartest option. In practice it is expensive, hard to predict, and rarely beats structure-aware splitting on structured documents.

Our recommendation is clear: chunk structured documents by structure, start unstructured text (chat logs, extracted PDFs) with overlapping fixed-size chunks, and add semantic chunking only if your evaluation set shows a difference.

Chunk size and context headers

Small chunks retrieve more precisely, because the vector represents a single idea. But a small chunk can be meaningless on its own: "This value defaults to 30 seconds" does not say which setting it refers to. Large chunks turn the vector into an average of several topics that matches none of them well.

The cheapest way out is to prefix every chunk with the document title and the section path it sits under. A small chunk starting with "Installation guide > Network settings > Timeout" retrieves precisely and reads meaningfully to the model. The prefix should go into both the embedded text and the text passed to the model.

The second technique is "search small, return large": search over small chunks, then give the model the whole section or the neighbouring chunks of each match. If context is expensive, try headers first.

Retrieval: vectors alone are not enough

Vector search is good at finding text with similar meaning. It is poor at exact matches: error codes, product versions, function names, order numbers. For "error E1042", vector search may rank highly a chunk that talks about error codes in general but never mentions E1042.

That is why hybrid search should be the default for technical content: run the query through keyword search (BM25) and vector search, then merge the two lists. The most robust way to merge is Reciprocal Rank Fusion. Each document gets 1 / (k + rank) for its position in each list and the scores are summed; 60 is a common choice for k. Do not try to add raw scores: BM25 scores and cosine similarity live on different scales, and weighting them needs constant retuning.

def rrf(result_lists, k=60):
    scores = {}
    for results in result_lists:
        for rank, doc_id in enumerate(results, start=1):
            scores[doc_id] = scores.get(doc_id, 0) + 1 / (k + rank)
    return sorted(scores, key=scores.get, reverse=True)

top = rrf([bm25_results, vector_results])[:20]

Reranking

Hybrid search gives you a good candidate list but does not reliably put the best chunk on top. That is the job of a reranker (cross-encoder): it reads the question and a candidate together and scores relevance. Vector search embeds query and document separately; a reranker sees both at once and is therefore much more accurate. The cost is speed, so it only runs over the top 20 to 50 candidates.

A practical pipeline: fetch 30 to 50 candidates with hybrid search, rerank them, pass the top 3 to 8 chunks to the model. On most evaluation sets the biggest jump in Recall@5 comes from this step.

Pitfalls

Changing the embedding model without rebuilding the index. Vectors from different models do not share a space. If queries are embedded with the new model and documents with the old one, search raises no error; it just returns nonsense. Store which model produced each vector and rebuild the index when the model changes.

Models that expect different prefixes for queries and documents. Some embedding models expect a specific prefix or instruction on queries and a different one on documents. If the model card says so and you ignore it, accuracy drops noticeably and nothing ever reports an error.

Language mismatch. Searching non-English questions with an embedding model trained mostly on English loses a lot compared to a multilingual model. Agglutinative languages also hurt keyword search: an inflected word does not match its stem. Use a stemmer for the language, or at least n-gram matching, on the keyword side.

Incomplete deletes on document updates. When a document changes, adding new chunks is not enough; old ones must go. Derive chunk IDs from the document ID and replace all chunks of a document in a single operation. Otherwise the model sees two contradicting versions of the same topic.

Applying permission filters after search. If you drop documents the user cannot see after retrieval, all top k results may be filtered out, leaving an empty list. Worse, if you forget the filter, unauthorized content reaches the model. Store access information in chunk metadata and filter inside the search.

Blindly converting tables and PDFs to text. Multi-column PDFs and tables turn into interleaved lines when flattened. Use a layout-aware converter for these and chunk tables per row, keeping column headers with each row.

When not to use RAG

If your knowledge base is a few hundred pages or less and rarely changes, putting all of it in context and using prompt caching is simpler and often more accurate. If questions require structured operations such as counting, summing or filtering ("how many orders were cancelled last month"), the answer comes from a database query, not document search; giving the model a query tool is far more reliable than RAG.

Finally, retrieval can only be as good as your documents. If no document states the answer clearly, the best pipeline will just put the wrong chunk on top. Questions that keep failing in your evaluation set usually point to missing documentation, not a missing algorithm.