Skip to main content
All signatures on this page are verified against the current @exulu/backend source. For option details, see Configuration.

Namespace import

SentenceChunker

SentenceChunker.create()

Static async factory. The constructor is private.
Returns a CallableSentenceChunker — an object that is both callable and has class properties/methods.

Calling the chunker

SentenceChunk properties

chunk()

Chunk a single text string. Called internally when the chunker is invoked as a function.

Properties

After create(), these are available on the instance:

RecursiveChunker

RecursiveChunker.create()

Static async factory. The constructor is private.

Calling the chunker

RecursiveChunk properties

chunk()

Properties


RecursiveRules

Constructor

RecursiveLevelData[]
Array of level definitions. When omitted, the five built-in levels are used (paragraphs → sentences → punctuation → words → tokens).
whitespace and delimiters are mutually exclusive on a single level — passing both throws.

Properties and methods


MarkdownChunker

Enterprise Edition class. Instantiate directly:

chunk()

string
required
The markdown text. Tables are converted to numbered-list format; <page_break page=N> tags are tracked for page numbering.
number
required
Target max tokens per chunk (effective budget is reduced by prefix and active header context tokens).
string
Optional string prepended to every chunk. Token count subtracted from the effective budget.
boolean
default:"false"
Prepend <!-- Current page: N --> to each chunk.
string
Full chunk content: optional page comment + header context (for non-current headers) + optional prefix + slice of the document.
number
Page number (1-based) in effect at the chunk boundary. Always 1 when no <page_break> tags are present.

convertTablesToText()

Converts markdown tables in a string to numbered-list format and returns the result. Called automatically by chunk().
Useful for pre-processing content before passing it to another chunker.

ChunkerOperation and ChunkerResponse

These are the types that connect chunkers to ExuluContext.

ChunkerOperation parameters

Item & { id: string }
required
The fully hydrated item record. Includes id, name, content, description, and all custom fields defined in the context schema.
number
required
The token budget per chunk, derived from the embedder model’s max_chunk_size as reported by LiteLLM. Pass this directly to the underlying chunker’s chunkSize option.
ExuluStorage
required
S3-backed storage accessor. Use utils.storage.read(s3key) to retrieve file content for file-backed contexts. For text-only items, this is not needed.

ChunkerResponse

Item & { id: string }
The original item, returned unchanged. Required.
string
The text content of this chunk. This is the text that will be embedded.
number
Zero-based position of this chunk. Must be contiguous (0, 1, 2, …) after filtering empty chunks — re-index with .map((c, i) => ({ ...c, index: i })) after any filtering step.
Record<string, unknown> | undefined
Arbitrary JSON-serializable metadata stored in the metadata JSONB column of the chunks table. Common uses: { page: 3 }, { section: "Introduction" }, { source_url: "https://..." }. Null bytes in string values are stripped automatically.

defaultChunker

The built-in ChunkerOperation used by ExuluContext when no chunker is configured. Concatenates item.name and item.content (falling back to item.description), runs SentenceChunker.create({ chunkSize: maxChunkSize }), and returns the results as a ChunkerResponse. Items with no usable text return { item, chunks: [] }.

Writing a custom chunker

Implement ChunkerOperation to handle file-backed, multi-source, or domain-specific chunking:
Assign it to the context:

Next steps

Configuration

Every option for all three chunkers and chunk-size guidance.

ExuluContext

Assign a ChunkerOperation to a context.