Expand description
Document chunking for RAG pipelines — the Rust port of docling-core’s
docling_core.transforms.chunker.
Two chunkers, matching docling’s semantics output-for-output:
HierarchicalChunkerwalks the document tree and yields one chunk per top-level item (paragraph, whole list, table, picture caption, …), each carrying the heading path it sits under. Tables are serialized in docling’s triplet form (row, column = value), pictures contribute their captions.HybridChunkerrefines the hierarchical chunks with a tokenizer: oversized chunks are split (at item boundaries first, then within the text by docling’ssemchunkalgorithm), and undersized neighbours that share the same headings are merged back together.
contextualize renders a chunk to the string an embedding model should
see: the heading path plus the chunk text.
Anything tokenizer-related is abstracted behind ChunkTokenizer; a
HuggingFace tokenizers implementation ships behind the chunking cargo
feature as [HuggingFaceTokenizer].
Structs§
- Chunk
Item - One document item contributing to a chunk — the analogue of an entry in
docling’s
DocMeta.doc_items. - DocChunk
- One chunk — the analogue of docling’s
DocChunk(text +DocMeta). - Hierarchical
Chunker - Structure-driven chunker: one chunk per document item, lists and inline
groups kept whole, heading path tracked as metadata — docling-core’s
HierarchicalChunkerwith default parameters. - Hybrid
Chunker - Tokenization-aware chunker on top of
HierarchicalChunker— docling’sHybridChunkerwith default parameters (merge_peers,repeat_table_headeron;omit_header_on_overflowoff).
Enums§
- Chunk
Item Kind - What kind of document item a
ChunkItempoints at — only what the hybrid splitting logic needs to know.
Traits§
- Chunk
Tokenizer - Token counting for
HybridChunker— docling’sBaseTokenizer.
Functions§
- contextualize
- Render a chunk for embedding: the heading path, then the text, joined with
newlines — docling’s
BaseChunker.contextualize(). - semchunk
- Split
textinto chunks of at mostchunk_sizetokens using the most semantically meaningful splitter available — thesemchunkalgorithm docling’s HybridChunker delegates plain-text splitting to.