Chunking is the least glamorous part of a RAG pipeline and the one most likely to quietly wreck your results. A retriever can only return what you gave it: if a key fact is split across two chunks, the model never sees the full picture. If chunks are too large, the relevant sentence drowns in noise.
This guide compares the three chunking strategies you will actually use in production: fixed-size, recursive, and semantic chunking. You will see how each one works, working code patterns, and a practical way to decide which fits your data.
What chunking actually controls
Chunking decides three things: how much text goes into each embedding, where the boundaries fall, and how much context overlaps between neighbors. Three variables matter:
- Chunk size (usually 200-800 tokens). Smaller chunks give the retriever precise targets; larger chunks give the generator more context.
- Overlap (usually 10-20% of chunk size). Overlap keeps sentences that straddle a boundary readable in at least one chunk.
- Boundary rules. Splitting mid-sentence is the classic failure mode. Good strategies split at paragraph or sentence boundaries first.
Chunk size is measured in tokens, not characters, because embeddings and model context windows work in tokens. A rough rule: one token is about four characters of English text. Chunk size is only half of that equation; the model doing the embedding matters too, and we compared the best embedding models of 2026 head to head.
Fixed-size chunking
Fixed-size chunking cuts text into blocks of N tokens (or characters) with a fixed overlap. It is the simplest strategy and the default in many quickstart tutorials.
def fixed_size_chunks(text, size=500, overlap=50, unit="chars"):
chunks, start = [], 0
while start < len(text):
end = min(start + size, len(text))
chunks.append(text[start:end])
if end == len(text):
break
start = end - overlap
return chunks
Strengths: predictable, trivial to implement, every chunk is the same size so your embedding costs and index behavior are uniform.
Weaknesses: it splits wherever the counter lands, which is often mid-sentence or mid-paragraph. A definition that starts at the end of one chunk and finishes at the start of the next becomes invisible to semantic search.
Use fixed-size chunking when you need something running today and your documents are uniform, like logs or transcripts where structure is loose anyway.
Recursive chunking
Recursive chunking tries to split at natural boundaries first and only falls back to smaller units when a piece is still too large. It works through an ordered separator list: paragraph breaks, then line breaks, then sentences, then words.
from langchain_text_splitters import RecursiveCharacterTextSplitter
splitter = RecursiveCharacterTextSplitter(
chunk_size=500,
chunk_overlap=50,
separators=["nn", "n", ". ", " ", ""]
)
chunks = splitter.split_text(document)
LangChain‘s RecursiveCharacterTextSplitter implements exactly this: it splits on the first separator, and any piece that still exceeds the chunk size gets split again with the next separator down the list.
Strengths: boundaries land at paragraphs and sentences, so chunks read coherently. It is a strict upgrade over fixed-size for prose documents and costs nothing extra.
Weaknesses: it knows nothing about meaning. A section that changes topic mid-paragraph still gets glued together, and a long table or code block can still be sliced awkwardly.
Recursive chunking is the default I recommend for most RAG projects. It beats fixed-size on document-like text with no additional dependencies.
Semantic chunking
Semantic chunking decides boundaries from meaning, not character counts. It embeds sentences, then groups consecutive sentences whose embeddings are similar and starts a new chunk where similarity drops.
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
model = SentenceTransformer("all-MiniLM-L6-v2")
sentences = split_into_sentences(document) # your sentence splitter
embeddings = model.encode(sentences)
sims = [cosine_similarity([embeddings[i]], [embeddings[i+1]])[0][0]
for i in range(len(embeddings) - 1)]
threshold = np.percentile(sims, 25) # tune this percentile
chunks, current = [], [sentences[0]]
for s, sim in zip(sentences[1:], sims):
current.append(s)
if sim < threshold:
chunks.append(" ".join(current)); current = []
if current:
chunks.append(" ".join(current))
Libraries like LlamaIndex (SemanticSplitterNodeParser) package this idea with more tuning knobs. The percentile threshold is the main control: a higher percentile produces more, smaller chunks.
Strengths: chunk boundaries follow topic shifts, which is exactly what retrieval wants. On documents that mix topics, this finds structure that character-based methods cannot.
Weaknesses: it costs an embedding pass over every sentence before indexing even starts, the threshold needs tuning per corpus, and it can produce wildly uneven chunk sizes.
How to compare them on your own data
Do not pick a strategy from a blog post (including this one). Run a small retrieval evaluation on your own corpus:
- Write 20-30 realistic questions your users would ask, each with the document and passage that contains the answer.
- Index the same corpus three times, once per strategy, keeping chunk size roughly equal.
- Measure recall at k: for each question, does the correct passage appear in the top 5 retrieved chunks?
This takes an afternoon and answers the question for your data, which is the only answer that matters. Public benchmarks exist for chunking, but their corpora are rarely shaped like yours.
Which strategy should you pick
- Fixed-size: quick prototypes, uniform machine-generated text, or when you need perfectly predictable chunk counts.
- Recursive: the safe default for documentation, articles, books, and PDFs. Start here.
- Semantic: documents that switch topics without clear headings, long meeting transcripts, or when recursive chunking gives you chunks that mix unrelated content.
A pattern that works well in practice: start with recursive chunking at 400-600 tokens with 10-15% overlap, evaluate, and only move to semantic chunking if your eval shows topic-mixing problems. Chunking is the cheapest part of your RAG pipeline to change, so treat the first choice as a starting point, not a commitment. For how chunking fits into the whole system, our end-to-end guide to building a RAG pipeline in Python walks through every stage around it.