chunk-engine
API Reference

API Reference

The operations every SDK exposes, the parameters they share, and where to find each language's exact signatures.

View raw

All three SDKs are bindings over one engine, so they expose the same operations — batch chunking, streaming, Markdown conversion and image extraction — over the same 36 extensions. Only the naming and the argument style follow each language's conventions.

This page is the shared half: the operation map and the parameters that mean the same thing everywhere. The exact signature of every function lives on the per-language page.

Operations

OperationPython (py-chunks)JavaScript (js-chunks)Rust (rs-chunks)
Chunk a documentget_chunks(source, …)getChunks(source, opts?)get_chunks(path, …), get_chunks_from_bytes(bytes, filename, …)
Chunk + extracted imagesget_chunks(…, list_images=True)ChunksResultgetChunks(…, { listImages: true })ChunksWithImagesget_chunks_with_images_from_bytes(…) (bytes only)
Convert to Markdownget_markdown(source)getMarkdown(source)get_markdown(path), get_markdown_from_bytes(bytes, filename)
Markdown + imagesget_markdown(…, list_images=True)MarkdownResultgetMarkdown(…, { listImages: true })MarkdownWithImagesget_markdown_with_images_from_bytes(…) (bytes only)
Iterate chunksstream_chunks(source, …)streamChunks(source, opts?)formats::<fmt>::stream(path, …) — per format
One known formatchunk_docx(path, …) and 17 more pairs— (route by filename)formats::docx::chunk(…), chunk_with_options(…)
Host-parsed PDF MarkdownchunkPdfMarkdown, chunkPdfMarkdownWithImages, normalizePdfMarkdown
Fit chunks to a token budgetfit_tokens(chunks, counter, budget, …)fitTokens(chunks, counter, budget, opts?)
Chunk a bare stringchunk_text(text, …)chunkText(text, opts?)get_chunks_from_bytes(text.as_bytes(), "text.txt", …)

Three asymmetries are real and deliberate, not gaps in this table:

  • Rust has no path-based image entry point at the dispatch level. The crate re-exports six functions; the two *_with_images_* ones take bytes. For images from a path, call the format module — formats::docx::chunk_with_images("report.docx", …).
  • Rust has no dispatch-level streaming. Streaming is per-format (formats::csv::stream, formats::pdf::stream, …) because the iterator types differ per format. See Streaming.
  • Token fitting is per-SDK and parity-exempt. fit_tokens / fitTokens are separate implementations, not one shared code path, because their output depends on the tokenizer you pass — and tokenizers differ between languages. Characters are parity-safe; tokens are not. There is no Rust version: the crate has no host language to borrow a tokenizer from, so a caller composes one themselves. One further asymmetry inside the pair: Python's counter also accepts a tiktoken Encoding, a HuggingFace tokenizer, or a name string ("cl100k_base", a model id) — JavaScript takes a callable only, because JS has no one canonical tokenizer registry to resolve names against.

Shared parameters

Every batch entry point in every language takes the same five chunking parameters with the same defaults. They are declared once here; the per-language pages show where each sits in the signature.

ParameterDefaultApplies toMeaning
mode / mode"default"allChunking strategy — see Chunking Modes.
window_size / windowSize3sliding_windowUnits per window. The unit is format-specific (blocks, rows, paragraphs).
overlap / overlap1sliding_windowUnits shared between consecutive windows. Must be < window_size.
sentences_per_chunk / sentencesPerChunk3sentenceSentences grouped into one chunk.
paragraphs_per_page / paragraphsPerPage15page_awareUnits per synthesized page when the format has no real pages.
filename / filenamebyte sourcesRouting only. Never written to disk under that name.
list_images / listImagesfalseimage-bearing formatsSwitches the return shape to the …WithImages variant.

mode accepts the same ten strings everywhere: default, section, semantic, sentence, sliding_window, page_aware, structural, row, table, sheet. Not every format accepts every mode — a format validates mode against the strategies it supports and rejects the rest.

The spreadsheet sentinel

On the source-agnostic entry points, sentences_per_chunk does double duty for delimited and spreadsheet formats: it carries rows_per_chunk. For spreadsheets the value 3 — the default — is read as "the caller did not ask" and mapped to rows_per_chunk = 1, which means a deliberate 3 is not expressible through get_chunks. To set rows explicitly, call the format entry point: chunk_xlsx(path, rows_per_chunk=3) in Python, or formats::xlsx::chunk / chunk_with_options in Rust. CSV and TSV have no sentinel — sentences_per_chunk is passed through as rows_per_chunk verbatim (clamped to a minimum of 1), except in page_aware, where paragraphs_per_page supplies the row count instead.

Knobs that are not on the shared surface

rows_per_chunk, include_headers, delimiter, encoding, skip_empty_rows, sheet_names, serialize_as and max_chunk_chars are delimited/spreadsheet options. They are reachable as follows:

KnobPythonJavaScriptRust
delimiter, encodingon every source-agnostic entry point, and on chunk_csvnot exposedformats::csv::chunk, or ChunkOptions
rows_per_chunk, include_headers, skip_empty_rowschunk_csv / chunk_xlsxnot exposedformats::csv::chunk, formats::xlsx::chunk, or ChunkOptions
sheet_names, serialize_as, max_chunk_charschunk_xlsxnot exposedformats::xlsx::chunk

In Rust, ChunkOptions is the only route to rows_per_chunk, include_headers, delimiter, encoding and skip_empty_rows through a single uniform struct.

Per-language reference

On this page