Skip to main content

Overview

Recursive splitter intelligently splits text using a prioritized list of separators. It tries the first separator, and if segments are still too large, recursively applies the next separator. Highly effective for structured text like code and markdown, ensuring logical units stay together. Splitter Class: RecursiveChunker Config Class: RecursiveChunkingConfig

Dependencies

No additional dependencies required. Uses standard library.

Examples

Parameters

ParameterTypeDescriptionDefaultSource
chunk_sizeintTarget size of each chunk1024Base
chunk_overlapintOverlapping units between chunks200Base
min_chunk_sizeint | NoneMinimum size for a chunkNoneBase
length_functionCallable[[str], int]Function to measure text lengthlenBase
strip_whitespaceboolStrip leading/trailing whitespaceFalseBase
separatorslist[str]Prioritized list of separators["\n\n", "\n", ". ", "? ", "! ", " ", ""]Specific
keep_separatorboolKeep separator in chunksTrueSpecific
is_separator_regexboolTreat separators as regex patternsFalseSpecific