Recursive chunking

Also known as: recursive character text splitting

On this page 7

Recursive chunking, also called recursive character text splitting, is a method that divides a document into retrievable pieces by applying a ranked list of separators, starting with the coarsest boundary and falling back to finer ones only when a piece still exceeds the maximum chunk size. In the Retrieval & knowledge layer of artificial intelligence systems, it is the most widely used default for preparing text for embeddings and vector search in RAG pipelines.

The method aims to keep natural units of meaning together, such as paragraphs and sentences, while guaranteeing a predictable upper bound on chunk length. It sits between simple fixed-size chunking and more expensive semantic chunking, which is why many ingestion pipelines use it as their baseline.

How recursive chunking splits text

Recursive chunking works as a top-down splitting algorithm. The splitter tries the first separator in its list, typically a double newline that marks a paragraph break, and checks the length of every resulting piece against the chunk size limit.

Pieces that fit are kept, and pieces that are still too long are passed recursively to the next separator, such as a single newline, then a sentence-ending period followed by a space, then a space, and finally individual characters. A merge step then combines adjacent small pieces until each chunk approaches the target size, so the output does not consist of many tiny fragments.

Because the algorithm only descends to a finer separator when it must, coarse boundaries win whenever possible. A short paragraph therefore stays intact, while an unusually long paragraph is broken at sentence ends rather than at an arbitrary token position. This graceful degradation is the defining property of the method and the reason it handles mixed documents, which contain both short notes and long passages, better than a single fixed rule.

The following table shows a common default separator hierarchy for prose and what each level preserves.

OrderSeparatorBoundary it representsUsed when
1Double newlineParagraphAlways tried first
2Single newlineLine or list itemA paragraph exceeds the limit
3Period and spaceSentenceA line is still too long
4SpaceWordA sentence exceeds the limit
5Empty stringCharacterA single token sequence is too long
Default separator hierarchy for plain text

Most implementations also apply a chunk overlap, repeating a small window of text from the end of one chunk at the start of the next. Overlap reduces the risk that a fact split across a boundary becomes unretrievable from either chunk.

Key parameters and typical values

Three parameters control the behavior of a recursive splitter: chunk size, chunk overlap and the separator list. Their best values depend on the embedding model, the document type and the questions users ask.

ParameterTypical rangeEffect of a higher valueMain risk
Chunk size256 to 1,024 tokensMore context per chunkDiluted embeddings, weaker precision
Chunk overlap10 to 20 percent of sizeFewer facts cut at boundariesDuplicate content and larger index
Separator list4 to 8 levelsFiner fallback controlOver-tuned rules for one format
Length functionCharacters or tokensToken counts match model limitsCharacter counts misjudge token use
Recursive chunking parameters

Measuring length in tokens rather than characters is the safer choice, because embedding models enforce token limits and the ratio of characters to tokens varies by language. Chunks that silently exceed the model limit are truncated during embedding, which removes content from the index without any error.

Recursive chunking compared with other chunking strategies

Recursive chunking is best understood as a structure-aware compromise. It respects document layout more than fixed-size splitting, yet it does not analyze meaning the way semantic or late chunking does.

StrategyBoundary logicCostTypical weakness
Fixed-size chunkingEvery N tokensVery lowCuts sentences and tables
Recursive chunkingRanked separators with fallbackLowBlind to topic shifts within a paragraph
Semantic chunkingEmbedding similarity between sentencesModerateSensitive to threshold choice
Late chunkingToken embeddings pooled after full-document encodingHigherNeeds long-context embedding models
Parent document retrievalSmall chunks indexed, large parents returnedModerateMore storage and logic
Comparison of chunking strategies

In published comparisons, recursive chunking often performs close to semantic chunking on general prose at a fraction of the compute cost. Gains from more advanced methods tend to appear on long, loosely structured documents where topics change without paragraph breaks.

Adapting separators to document formats

The separator list is the main lever for format-specific splitting. Markdown documents benefit from heading markers as the first separators, so that each section stays together, while source code benefits from language-aware separators such as class and function definitions.

  • Markdown and HTML: split on top-level headings first, then subheadings, then paragraphs.
  • Source code: split on class and function boundaries before blank lines and statements.
  • Legal and policy text: split on numbered clauses so that each obligation stays whole.
  • Languages without spaces, such as Chinese or Japanese: add full-width punctuation as sentence separators.

Adding metadata to each chunk, such as the document title and the heading path, further improves retrieval because a chunk taken from the middle of a section otherwise loses its surrounding context.

Common mistakes and how to avoid them

Most problems with recursive chunking come from default settings applied without evaluation. Teams should measure retrieval quality with metrics such as recall@k on a set of real questions before and after changing any parameter.

SymptomLikely causeFix
Answers miss details split across chunksNo or tiny overlapAdd 10 to 20 percent overlap
Retrieved chunks are vagueChunk size too largeReduce size and test recall
Tables arrive as broken rowsNewline separators inside tablesExtract tables as separate units
Chunks exceed the model limitCharacter-based length functionCount tokens with the model tokenizer
Symptoms, causes and fixes

The short version

AI search tools cannot read a whole manual at once. They need it cut into small pieces first. Recursive chunking is a careful way to cut.

It first tries to cut between paragraphs. If a paragraph is still too long, it cuts between sentences. Only as a last resort does it cut between words. The goal is pieces that are small but still make sense, like cutting a cake along its layers instead of at random.

Where it makes a difference

A support team at a software company builds an internal assistant over about 4,000 help articles written in Markdown. The first version uses fixed 500-token chunks, and agents complain that answers often cite half of a troubleshooting procedure, because step lists are cut in the middle.

The team switches to recursive chunking with Markdown headings as the first separators, a 512-token limit measured with the embedding tokenizer and a 64-token overlap. Each chunk also carries its article title and heading path as metadata. On a test set of 200 real support questions, recall@5 rises noticeably and complete procedures now appear in a single chunk, so agents spend less time opening the source articles.