ExuluChunkers is a namespace exported from @exulu/backend that groups the built-in text chunking implementations. Chunking is the step that splits an item’s text into embeddable segments before embedding generation runs. ExuluContext handles this automatically using the defaultChunker when you configure an embedder model; you only need ExuluChunkers directly when you want to customise the chunking strategy.
Why chunking matters
Embedding models have a maximum token input length (themax_chunk_size reported in LiteLLM’s /model/info response). Text longer than this limit must be split before embedding. The split strategy also affects retrieval quality — chunks that are too long lose specificity; chunks that are too short lose context.
A practical starting point: set chunkSize to the embedding model’s max_chunk_size and observe retrieval quality. For 1 024-dimensional models with a 1 024-token limit, chunks of 512–1 024 tokens typically give good results. The optimal size depends on your content and query patterns, not on a universal rule.
The chunker contract
All chunkers inExuluChunkers and any custom chunker you write are expected to satisfy either:
- The callable interface — the class is a callable function returning chunk objects from the underlying library, or
- The
ChunkerOperationtype — a plain async function consumed byExuluContext.
ExuluContext, you implement ChunkerOperation:
ChunkerResponse is the return type — an object with the original item and an array of chunks:
The default chunker
defaultChunker is the ChunkerOperation ExuluContext uses when you configure an embedder model but do not supply a chunker. It:
- Combines
item.nameanditem.content(falling back toitem.description) into a single text string. - Runs
SentenceChunker.create({ chunkSize: maxChunkSize })over that string. - Filters out empty chunks and re-indexes to produce contiguous
0..n-1indexes.
ChunkerOperation instead.
Available chunkers
SentenceChunker
Splits text at sentence boundaries while respecting a token limit per chunk. The default chunker insidedefaultChunker. Supports overlap to preserve context across chunk boundaries.
MarkdownChunker
An Enterprise Edition chunker optimised for markdown and document-converted content. It:- Converts markdown tables to numbered-list format for better embedding quality.
- Splits at logical breakpoints (headers → paragraphs → sentences → whitespace) rather than pure token counts.
- Prepends the active header hierarchy to each chunk so retrieval context is preserved.
- Handles
<diagram>tags by never splitting their contents. - Supports
<page_break page=N>tags (inserted by the PDF processor) to track page numbers per chunk.
MarkdownChunker does not implement ChunkerOperation directly — wrap it in an adapter when assigning to ExuluContext.chunker.
RecursiveChunker
Hierarchically splits text using a configurable rule set: from paragraphs down to sentences, punctuation, words, and finally raw tokens. The defaultRecursiveRules levels are:
- Paragraphs —
\n\n,\r\n,\n,\r - Sentences —
.,!,? - Pauses — punctuation and bracket characters
- Words — whitespace split
- Tokens — raw token split
Choosing a chunker
Integrating with ExuluContext
Assign anyChunkerOperation to the chunker option on ExuluContext:
Next steps
Configuration
Every option for SentenceChunker, RecursiveChunker, MarkdownChunker, and RecursiveRules.
API reference
Method signatures, ChunkerOperation/ChunkerResponse types, and custom chunker guidance.