Recursive Chunking Explained: How RAG Splitters Respect Text Structure

Recursive Chunking Explained: How RAG Splitters Respect Text Structure

Recursive chunking is the most widely used text-splitting strategy in retrieval-augmented generation: instead of cutting a document at fixed intervals, it tries to split on paragraph breaks first, then line breaks, then sentences, and only falls back to raw characters when nothing else works. Is it better than fixed-size splitting? For most real documents, yes — chunks end at natural boundaries, so embeddings stay coherent and retrieval accuracy improves, at the cost of a few more settings to tune.

The idea is simple. A document already has structure: paragraphs group related sentences, sentences group related words. Recursive chunking respects that structure by working through a ranked list of separators, splitting on the strongest boundary available and only moving down the list when a piece is still too large. The result is chunks that usually end where a human would end a thought, not where a counter ran out.

Key takeaways

  • Recursive chunking tries separators in order — paragraphs, lines, sentences, spaces, then characters — and only splits finer when a piece is still too large.
  • It is the default splitter in LangChain and the most common baseline in production RAG systems.
  • Chunks keep natural boundaries, so embeddings are more coherent and retrieval is usually more accurate than with fixed-size splitting.
  • Two settings dominate: chunk size, which caps chunk length, and chunk overlap, which repeats text across neighbours.
  • It still cannot understand document structure such as tables or headings, so it is a general-purpose tool rather than a specialist one.

What is recursive chunking?

Recursive chunking is a splitting method that works down a hierarchy of separators. Given a document and a target chunk size, the splitter first tries to divide the text at double newlines, which usually mark paragraph breaks. Any piece still larger than the target is split again on single newlines, then on sentence-ending punctuation, then on spaces, and finally on individual characters if nothing else will do.

The name comes from this repeated, or recursive, application of the same rule: split on the best separator available, then re-split any piece that is still too big. Small pieces are then merged back together until they approach the target size. The practical effect is that a chunk ends at a paragraph break whenever possible, at a sentence break when it must, and in the middle of a word only as a last resort.

This behaviour is why recursive chunking is often described as structure-aware without being truly semantic. It does not understand what the text means. It simply trusts the author’s own punctuation and paragraphing, which is usually a good guide to where one idea ends and another begins.

How recursive chunking works

LangChain’s RecursiveCharacterTextSplitter is the reference implementation, and its default separator list is ["\n\n", "\n", " ", ""], with sentence handling folded into the space and character stages in many configurations. A typical setup adds an explicit sentence separator as well. The splitter measures each piece with a length function — character count by default, or a tokenizer when you need token-accurate sizing — and merges small pieces until adding another would exceed the chunk size.

Overlap works the same way as in fixed-size splitting: the tail of one chunk is repeated at the head of the next, so a sentence that straddles a boundary still appears whole somewhere. An overlap of 10 to 20 per cent of chunk size is a common starting point, and it matters here too, because even a good splitter sometimes has to break a long paragraph across two chunks.

The merging step is what keeps chunks usefully full. Without it, a document of short paragraphs would produce many tiny chunks, each too small to answer a question on its own. By combining small pieces up to the size limit, recursive chunking produces chunks of roughly even length that still respect boundaries.

Recursive chunking in practice

A standard LangChain configuration looks like this:

from langchain_text_splitters import RecursiveCharacterTextSplitter

splitter = RecursiveCharacterTextSplitter(
    chunk_size=1000,
    chunk_overlap=200,
    length_function=len,
    separators=["\n\n", "\n", ". ", " ", ""],
)
chunks = splitter.split_text(document_text)

This setup targets chunks of about 1,000 characters, overlaps neighbours by 200 characters, and tries paragraph breaks before line breaks, sentence ends, spaces and raw characters. It is a sensible default for mixed prose, and it is the configuration many teams never need to change. LlamaIndex offers similar behaviour through its SentenceSplitter, which splits on sentences and groups them up to a target size.

The official LangChain guide to the recursive text splitter shows the same pattern applied to real documents, including language-aware variants that split code on function and class boundaries rather than prose punctuation. That matters when your corpus includes source code, where a split inside a function definition is as damaging as a split inside a sentence.

As with any splitter, the only honest way to judge it is against your own questions. Build a small test set, retrieve the top chunks for each question, and check whether the chunk holding the answer appears. Our guide to retrieval accuracy explains how to run that check, and it is the step that separates a tuned pipeline from a guessed one.

Nested rectangular blocks splitting from large to small in a branching pattern
Recursive chunking works down a hierarchy of separators, splitting large pieces into smaller ones only where the text demands it.

Strengths of recursive chunking

The main strength is coherence. Because chunks end at paragraph or sentence boundaries, each embedding represents a complete thought rather than a fragment. Retrieval models match complete thoughts more reliably, and language models answer better from complete context than from pieces that start mid-sentence.

It is also remarkably general. The same splitter handles reports, articles, transcripts and documentation without per-document configuration, because it adapts to whatever separators the text actually contains.

Finally, it is cheap. Recursive splitting needs no embedding model, no language model call and no parsing step — just string operations. Indexing cost is essentially the same as fixed-size splitting, which makes it an easy upgrade: same pipeline, better boundaries, no new infrastructure.

Weaknesses of recursive chunking

Recursive chunking trusts punctuation, and punctuation can lie. A document with inconsistent formatting — single newlines used as paragraph breaks, abbreviations full of periods, lists without blank lines — will be split in odd places. The splitter cannot tell a genuine sentence end from a decimal point in a version number, so noisy documents still produce noisy chunks.

It also has no sense of document structure beyond line breaks. A table split across chunks loses its headers, a heading can end up separated from the section it introduces, and a long list may be chopped without regard for where items begin. For documents where structure carries meaning, a splitter that understands headings and tables does better.

Chunk sizes vary more than with fixed-size splitting, because merging stops at the first piece that would overflow the limit. A document of short paragraphs can produce chunks well under the target size, which means more chunks, more embeddings and slightly higher cost.

Recursive chunking compared with other strategies

Strategy How it splits Main strength Main weakness Best for
Recursive chunking Separator hierarchy: paragraphs to characters Respects natural boundaries Trusts punctuation blindly General-purpose documents
Fixed-size chunking Equal character or token counts Simple and predictable Cuts mid-sentence Uniform plain text
Semantic chunking Topic shifts detected by embeddings Chunks match real topics Slow and costly Long, varied prose
Document-based chunking Headings, sections and tables Preserves document structure Needs reliable parsing Manuals and contracts

Best for: general-purpose RAG pipelines over mixed prose — reports, articles, documentation and transcripts — where you want better retrieval than fixed-size splitting without paying for embedding-based or structure-aware methods.

How to tune recursive chunking

Start with a chunk size of 500 to 1,000 tokens and overlap of 10 to 20 per cent, then test. The right size depends on your embedding model and your questions: short factual questions favour smaller chunks that match precisely, while explanatory questions favour larger chunks that carry enough context for a full answer.

Customise the separator list for your documents. Markdown files benefit from heading-aware separators, code benefits from language-aware splitting, and documents with unusual line-break conventions may need their separators reordered. The default list is a good starting point, not a law.

Watch the distribution of chunk lengths after splitting. If most chunks are far below your target size, your documents may have many short paragraphs, and a larger target or a different merging approach could help. If many chunks hit the character fallback, your text may lack the separators the splitter expects, and cleaning up the source formatting — or improving document parsing upstream — will do more than any splitter setting.

Common mistakes with recursive chunking

The most common mistake is treating the defaults as finished. The default chunk size and separators are reasonable, but they were not chosen for your documents. A team that never tests alternatives is leaving retrieval quality on the table for the sake of ten minutes of experimentation.

The second mistake is sizing chunks in characters while the rest of the pipeline counts tokens. A 1,000-character chunk is roughly 200 to 250 tokens of English prose, but that ratio shifts with formatting and language. If your context window and costs are measured in tokens, pass a tokenizer as the length function so chunk sizes mean what you think they mean.

The third mistake is forgetting that splitting is only one step. Retrieval quality also depends on how documents are ingested, how metadata is attached and how results are ranked. A good splitter cannot rescue a pipeline with dirty extraction or no chunking strategy for tables and figures. Treat chunking as part of the ingestion pipeline, not as a setting you fix once and forget.

Decision checklist

Use this checklist before adopting recursive chunking in production.

  • You have tested chunk sizes above and below your starting point against real questions.
  • Overlap is set to roughly 10 to 20 per cent of chunk size.
  • The separator list matches your document formats, including any Markdown or code in the corpus.
  • Chunk sizes are measured in tokens if your costs and context limits are counted in tokens.
  • You checked the chunk length distribution and confirmed most chunks sit near the target size.
  • Retrieval accuracy improved over your fixed-size baseline on the same test set.
  • You have a plan to re-tune when new document types enter the corpus.

Frequently asked questions

What is recursive chunking?

Recursive chunking splits a document by trying a ranked list of separators — paragraphs, then lines, then sentences, then spaces, then characters — and only splitting more finely when a piece is still too large. It keeps chunks at natural text boundaries wherever possible.

Is recursive chunking better than fixed-size chunking?

Usually, yes, for documents with real paragraph and sentence structure. Chunks end at natural boundaries, so embeddings are more coherent. On uniform plain text with little structure, the two perform similarly.

What is the best chunk size for recursive chunking?

There is no universal answer. Start with 500 to 1,000 tokens and 10 to 20 per cent overlap, then test smaller and larger sizes against your own questions and keep whichever retrieves best.

Does recursive chunking work for code?

Yes, when configured with language-aware separators. LangChain’s recursive splitter can split Python, JavaScript and other languages on class and function boundaries, which keeps code chunks syntactically complete.

What is the difference between recursive chunking and semantic chunking?

Recursive chunking uses punctuation and line breaks to find boundaries, which is fast and free. Semantic chunking embeds sentences and splits where topic similarity drops, which finds real topic changes but costs an embedding pass over every sentence.

When should I move beyond recursive chunking?

Move on when your documents have structure the splitter cannot see — tables, nested headings, forms — or when retrieval tests show topic-level splits would help. That is where document-based or semantic chunking earns its cost.

Latest articles

Scroll to Top