API Reference
To use theRecursiveChunker via the API, check out the API reference documentation.
Installation
The RecursiveChunker is included in the base installation of Chonkie. No additional dependencies are required.If you would like to use custom tokenizers in JavaScript, please install the
@chonkiejs/token libraryInitialization
The RecursiveChunker usesRecursiveRules to determine how to chunk the text.
The rules are a list of RecursiveLevel objects, which define the delimiters and whitespace rules for each level of the recursive tree.
Find more information about the rules in the Additional Information section.
Recipes are supported on Python only
Parameters
Union[str, Callable, Any]
default:"character"
Tokenizer to use. Can be a string identifier or a tokenizer instance
int
default:"2048"
Maximum number of tokens per chunk
RecursiveRules
default:"RecursiveRules()"
Rules to use for chunking.
int
default:"12"
Minimum number of characters per chunk
Usage
Single Text Chunking
Batch Chunking
Using as a Callable
Return Type
The RecursiveChunker returns chunks asChunk objects:
Additional Information
The RecursiveChunker uses theRecursiveRules class to determine the chunking rules. The rules are a list of RecursiveLevel objects, which define the delimiters and whitespace rules for each level of the recursive tree.
RecursiveLevel expects the list of custom delimiters to not include
whitespace. If whitespace as a delimiter is required, you can set the
whitespace parameter in the RecursiveLevel class to True. Note that if
whitespace = True, you cannot pass a list of custom delimiters.