How do chunking and reranking work in RAG?
Chunking is the step in retrieval-augmented generation (RAG) that splits documents into short passages, each embedded and stored as its own vector. Reranking is a second retrieval pass that rescores the first set of results with a slower, more accurate model. Together they decide which text reaches the language model's prompt, so they set an upper bound on how good a RAG answer can be.
Every RAG system chunks its documents, whether it answers questions over support articles, legal contracts, code, or product manuals. The chunk size, the overlap, and where the boundaries fall all change what a search can find. Rerankers sit between vector search and the prompt in most production pipelines, because a cross-encoder catches relevant passages that a fast bi-encoder ranked too low. Teams tune both with a labelled question set and metrics such as recall@k and MRR.
Key ideas
- RAG retrieves chunks, not whole documents, so the chunking decides what the model can be shown.
- Small chunks match precisely but can split an answer, while large chunks keep it whole but dilute its embedding.
- Overlap guarantees that any answer up to the overlap length fits whole in some chunk, at the cost of extra storage.
- Splitting on sentences, paragraphs, and headings keeps related text together better than fixed token counts.
- A cross-encoder reranker reads the query and each candidate together and fixes the order of a fast first-stage search, but it cannot recover a chunk that was never retrieved.
- Recall@k and MRR on a labelled question set turn chunking and retrieval choices into measurable numbers.
Short takes on this topic
Common questions
What chunk size should I use for RAG?
There is no single best size. Many teams start between 256 and 512 tokens with 10 to 20 percent overlap, then compare a few sizes on a labelled question set. Short factual questions tend to favour smaller chunks, and questions that need a whole section favour larger ones.
What is semantic chunking?
Semantic chunking embeds each sentence and starts a new chunk where the similarity between neighbouring sentences drops, on the idea that a drop marks a change of topic. It needs no fixed size and follows the content. It costs an embedding call per sentence at indexing time, and on well-structured documents it often performs about as well as heading-aware splitting.
Is a reranker worth the extra latency?
Often, yes. A cross-encoder over 20 to 100 candidates usually adds tens to a few hundred milliseconds on a GPU, while generating the answer takes longer. It helps most when the right chunk is retrieved but ranked below the cut-off for the prompt. If the right chunk is not in the candidate list at all, better chunking or hybrid search will help more.
What is the difference between BM25 and vector search?
BM25 scores documents by exact term matches, weighting rare terms higher and normalizing for document length. Vector search compares learned embeddings, so it matches paraphrases but can blur rare names, codes, and numbers. Hybrid search runs both and merges the two ranked lists, often with reciprocal rank fusion.
Related explainers
- Retrieval-Augmented Generation — Ground language model outputs in retrieved documents to reduce hallucination
- Embeddings — Turning words and categories into vectors
- TF-IDF — Score how important a word is to a document in a collection — the backbone of search engines and text retrieval
- BERT & Masked Language Modeling — Mask a word, predict it from both sides — how BERT learns deep bidirectional representations
- Model Evaluation & Metrics — Precision, recall, F1, ROC curves, and regression metrics
- Norms & Distance Metrics — L1, L2, cosine similarity — measuring closeness in vector spaces
References
- Lewis et al. (2020), "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks"
- Karpukhin et al. (2020), "Dense Passage Retrieval for Open-Domain Question Answering"
- Nogueira and Cho (2019), "Passage Re-ranking with BERT"
- Cormack, Clarke, and Buettcher (2009), "Reciprocal Rank Fusion Outperforms Condorcet and Individual Rank Learning Methods"
Last updated