Skip to main content
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 (the max_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 in ExuluChunkers 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 ChunkerOperation type — a plain async function consumed by ExuluContext.
When you assign a custom chunker to 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:
  1. Combines item.name and item.content (falling back to item.description) into a single text string.
  2. Runs SentenceChunker.create({ chunkSize: maxChunkSize }) over that string.
  3. Filters out empty chunks and re-indexes to produce contiguous 0..n-1 indexes.
For contexts whose items have structured or file-backed content, supply a custom ChunkerOperation instead.

Available chunkers

SentenceChunker

Splits text at sentence boundaries while respecting a token limit per chunk. The default chunker inside defaultChunker. 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 default RecursiveRules levels are:
  1. Paragraphs — \n\n, \r\n, \n, \r
  2. Sentences — . , ! , ?
  3. Pauses — punctuation and bracket characters
  4. Words — whitespace split
  5. Tokens — raw token split
Customise the rule set:

Choosing a chunker

Integrating with ExuluContext

Assign any ChunkerOperation 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.