RecursiveRules class used to customise the recursive splitting strategy. All options are verified against the current @exulu/backend source.
SentenceChunker
UseSentenceChunker.create() — the constructor is private.
Options
Maximum number of tokens per chunk. Chunks are never larger than this value. Set this to the embedding model’s
max_chunk_size as a ceiling; a value of 512 is a reasonable default for most 1 024-dimension models.Number of tokens to repeat at the start of the next chunk from the end of the current chunk. Must be non-negative and strictly less than
chunkSize. Use 10–20 % of chunkSize (e.g. 50–100 for a 512-token chunk) to preserve context across boundaries for natural-language content. Disabled by default.Minimum number of sentences to include in every chunk. When the token budget forces fewer sentences than this, the chunker extends the chunk past the token limit to satisfy the minimum. Default: 1.
Sentence fragments shorter than this character count are merged with the preceding or following sentence rather than treated as standalone sentences. Prevents punctuation artefacts (e.g. abbreviations) from becoming their own sentences.
Tokenizer model used for accurate token counting.
TokenizerModelName is a string union of supported model names. The default "gpt-3.5-turbo" tokenizer is compatible with most embedding models. If your embedding model uses a materially different tokenizer, specify the matching model name.Characters or strings that mark sentence boundaries. The chunker splits input at each delimiter and reassembles splits into chunks respecting
chunkSize.Where to attach the delimiter character when splitting.
"prev" keeps it with the preceding sentence (e.g. "Hello." stays whole). "next" moves it to the start of the next sentence. null discards the delimiter.Deprecated. Was used for character-based approximate token counting. Has no effect in current builds. Will be removed in a future version.
Example
Batch chunking
RecursiveChunker
UseRecursiveChunker.create() — the constructor is private.
Options
Maximum tokens per output chunk. If a
prefix is supplied, the prefix token count is subtracted from this limit automatically.The recursive splitting rule set. See RecursiveRules below. Defaults to five levels: paragraphs → sentences → punctuation → words → tokens.
Chunks shorter than this character count are merged with adjacent chunks. Prevents tiny artefacts at split boundaries.
Optional string prepended to every output chunk. Useful for providing domain context to the embedding model (e.g.
"Product documentation: "). The prefix token count is subtracted from chunkSize so output chunks still fit within the model limit.When
true, the chunker extracts Markdown and HTML headers from the input and prepends the active header hierarchy to each chunk. Improves retrieval quality for structured documents by ensuring every chunk carries its section context.Tokenizer model. See the SentenceChunker note above.
Example
RecursiveRules
RecursiveRules defines the ordered list of splitting strategies the RecursiveChunker tries from coarsest to finest.
Array of level definitions. When omitted, defaults to five built-in levels:
- Paragraphs:
["\n\n", "\r\n", "\n", "\r"] - Sentences:
[". ", "! ", "? "] - Punctuation/pauses:
["{", "}", '"', "[", "]", "<", ">", "(", ")", ":", ";", ",", "—", "|", "~", "-", "...", "”, ”’”]` - Words:
{ whitespace: true } - Tokens: fallback raw token split
RecursiveLevel:
Custom rules example
MarkdownChunker
MarkdownChunker is an Enterprise Edition class — instantiate directly (no factory):
advanced-markdown-chunker is not enabled, it logs a warning but does not throw — you can still call chunk().
chunk()
The markdown text to chunk. The method converts tables to numbered-list format before splitting.
<page_break page=N> tags are converted to HTML comments internally and used to track page numbers.Target maximum tokens per chunk. The actual internal budget is
chunkSize - prefixTokenCount - headerContextTokenCount. Uses a gpt-5 tokenizer for counting.Optional prefix prepended to every chunk. Token count is subtracted from the effective
chunkSize.When
true, prepends <!-- Current page: N --> to each chunk so the embedding and retrieval pipeline can filter or cite by page number.Return value
text is the final chunk content (header context + optional page comment + prefix + content). page is the page number in effect at the chunk boundary (1 if no <page_break> tags were present).
Wrapping for ExuluContext
MarkdownChunker.chunk() does not return ChunkerResponse. Wrap it:
Chunk size guidance
The rightchunkSize depends on your embedding model’s capabilities. Query LiteLLM’s /model/info endpoint at runtime for the max_chunk_size of your model:
Using the model’s full
max_chunk_size may degrade retrieval precision for short queries. Start at half the model’s maximum and adjust based on evaluation results.
Next steps
API reference
Method signatures, ChunkerOperation/ChunkerResponse types, and the custom chunker contract.
ExuluContext
Assign a ChunkerOperation to a context.