chunkr is a high-performance document chunking library built in Rust with first-class Python native bindings for Large Language Models (LLMs) and Retrieval-Augmented Generation (RAG) applications. It delivers throughput up to hundreds of MB/sec with zero superfluous heap allocations, advanced structure awareness, OpenAI BPE tokenization, semantic clustering, proposition decomposition, query-adaptive sizing, agentic topic segmentation, and multi-core parallel processing.
📦 Installation
Rust
Add chunkr to your Cargo.toml:
[dependencies]
chunkr = "1.0"
Python
Install chunkr-rs via pip:
pip install chunkr-rs
Or build from source with maturin:
maturin develop --release
🚀 Supported Chunking Strategies
| Strategy | Chunker Class | Description |
|---|---|---|
| Recursive | RecursiveChunker |
SIMD recursive separator splitting (~600+ MB/s) |
| Token BPE | TokenChunker |
OpenAI BPE token splitting (cl100k_base, o200k_base) |
| Sentence | SentenceChunker |
Abbreviation-safe sentence boundary splitting |
| Paragraph | ParagraphChunker |
Multi-paragraph grouping across \n\n |
| Semantic | SemanticChunker |
Distance threshold breakpoint clustering |
| Proposition | PropositionChunker |
Atomic factual claim extraction & subject propagation |
| Contextual | ContextualChunker |
Anthropic-style situational document preface injection |
| Query-Aware | QueryAwareChunker |
Search query hotspot detection & adaptive sizing |
| Agentic | AgenticChunker |
Discourse transition & topic segmentation |
| Hierarchical | HierarchicalChunker |
Parent-child pairs & multi-level tree generation |
| Markdown | MarkdownChunker |
Header hierarchy (#–######) & breadcrumb paths |
| Code | CodeChunker |
Syntax-aware chunking (Rust, Python, JS, Go, etc.) |
Python Quickstart
import chunkr
sample_text = (
"Convolutional neural networks specialize in visual imagery. "
"Recurrent networks process sequential text.\n\n"
"In conclusion, deep learning powers modern vision systems."
)
# 1. Recursive Character Chunking
recursive_chunker = chunkr.RecursiveChunker(chunk_size=500, overlap=50)
docs = recursive_chunker.chunk(sample_text)
for doc in docs:
print(doc.content, doc.metadata)
# 2. Token-Based Chunking (OpenAI cl100k_base / GPT-4)
token_chunker = chunkr.TokenChunker(chunk_size=100, overlap=20, encoding="cl100k_base")
token_docs = token_chunker.chunk(sample_text)
# 3. Query-Aware Adaptive Chunking
query_chunker = chunkr.QueryAwareChunker(query="neural networks", hotspot_sentences=1, context_sentences=2)
query_docs = query_chunker.chunk(sample_text)
# 4. Agentic Topic Chunking
agentic_chunker = chunkr.AgenticChunker(min_chars=100, max_chars=1000)
agentic_docs = agentic_chunker.chunk(sample_text)
# 5. Markdown Structure Chunking (with header breadcrumbs)
md_chunker = chunkr.MarkdownChunker(chunk_size=1000, overlap=100)
md_docs = md_chunker.chunk("# Title\n## Section\nContent...")
# 6. PDF Document Loading & Chunking
loader = chunkr.PDFLoader()
pages = loader.load_pages("path/to/document.pdf")
pdf_chunks = recursive_chunker.chunk(pages[0].content)
Rust Quickstart
use chunkr::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let text = "Convolutional neural networks specialize in visual imagery. Recurrent networks process sequential text.\n\nIn conclusion, deep learning powers modern vision.";
// 1. Recursive Chunker
let recursive_chunker = RecursiveChunker::new()
.with_chunk_size(500)
.with_overlap(50);
let chunks = recursive_chunker.chunk(text)?;
// 2. Query-Aware Adaptive Chunker
let query_chunker = QueryAwareChunker::new("convolutional neural networks")
.with_hotspot_sizing(1, 0)
.with_context_sizing(3, 1);
let query_chunks = query_chunker.chunk(text)?;
// 3. Hierarchical Parent-Child Tree Chunker
let hier_chunker = HierarchicalChunker::with_sizes(150, 20, 50, 10)?;
let tree = hier_chunker.chunk_tree(text)?;
// 4. PDF Document Loading & Chunking
let loader = PDFLoader::new();
let pdf_pages = loader.load_pages_from_file("tests/test_files/sample_doc.pdf")?;
let pdf_chunks = recursive_chunker.chunk_documents(&pdf_pages)?;
Ok(())
}
📊 In-Memory Speed Benchmark: Chunkr (Rust/Python) vs. LangChain
Pure in-memory Python runtime comparison (import chunkr vs. langchain-text-splitters):
💡 Contributing
Contributions are welcome! Please check out the Contribution Guide to get started.
📝 License
Licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for chunkr-rs 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chunkr_rs-1.1.0.tar.gz | 83.9 kB | Details |
Built distributions (wheels)
Total release size: 45.3 MB
Release files / chunkr_rs-1.1.0.tar.gz
| Download URL | chunkr_rs-1.1.0.tar.gz |
|---|---|
| Size | 83.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
75e231dc8ab6cdb183413cd5354253b163b78e981101d52345f01fe2c8c09635
|
|
BLAKE2b-256 checksum How to use checksums |
0012b04e5997cbac820f9dd94326b456909f6b5874eb677adda05cb6d4ea007e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / chunkr_rs-1.1.0-cp38-abi3-win_amd64.whl
| Download URL | chunkr_rs-1.1.0-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
b5ceb6a47873085b7e22afda437ffef383c7efbe097ec4df6b36b13ccfefb17a
|
|
BLAKE2b-256 checksum How to use checksums |
5449be602e371bdf1e633fda17bea611e6bad5a9195206129c9b77f00f63f381
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / chunkr_rs-1.1.0-cp38-abi3-win32.whl
| Download URL | chunkr_rs-1.1.0-cp38-abi3-win32.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.8 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
177fbc9951f77e160735dc36b5c7fb1a31a295985af9e654521b0f318aefab89
|
|
BLAKE2b-256 checksum How to use checksums |
98c1ea14f131cd2cf34a3355c2872f1b14363380290041491a21852d8c94b6f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / chunkr_rs-1.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | chunkr_rs-1.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.1 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
625246b53eb23721d35caad28bf9d91b4eb3bbb004cc46dfa5df7fac7ca224b6
|
|
BLAKE2b-256 checksum How to use checksums |
f5f83c68464a60ce9b98c3348838e05afea5767806a1e8f588f0062cd55911b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / chunkr_rs-1.1.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | chunkr_rs-1.1.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
199861955d041ed30d3b3b1109d26dfb4829aa67492dc1064c1d8a3bcb5fe2a3
|
|
BLAKE2b-256 checksum How to use checksums |
9da3466c621b632a4c7e793198de37386f91c73c91fb24f2b97eaae9f78f6c4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / chunkr_rs-1.1.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | chunkr_rs-1.1.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 5.4 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
513350eea909897773b2ffbba746f4247a977feef0546b37c1582a1d49f89365
|
|
BLAKE2b-256 checksum How to use checksums |
acd1b2016f643dde2d1270d3846349e1c2f78bf699617f89ab6b401447b352e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / chunkr_rs-1.1.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | chunkr_rs-1.1.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 5.1 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
be463d067c72752a5926c02733442bd08ae3dc507a103985c1351bc9605a40b9
|
|
BLAKE2b-256 checksum How to use checksums |
f69efab1f1aed799a1bf2c9c648b1fae72861d8c7244b13048ac3f03c60d01e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / chunkr_rs-1.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | chunkr_rs-1.1.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 5.1 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
bdfad626e2078a81c2bc16c5d222fa8d885e7de527b04244b294426653fc3530
|
|
BLAKE2b-256 checksum How to use checksums |
e5b817033e971f0f5972976f730ebbb3bbfcc81cdb3d1082d00bceaaf28ca996
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / chunkr_rs-1.1.0-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | chunkr_rs-1.1.0-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
11863645d0e6c942b36ca46828fb18bbc9d95ccb47356fa966593349017695aa
|
|
BLAKE2b-256 checksum How to use checksums |
02dd0615c98aa0913f1310414ce93074885750c16a4299825e95859bf492ca15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / chunkr_rs-1.1.0-cp38-abi3-macosx_10_12_x86_64.whl
| Download URL | chunkr_rs-1.1.0-cp38-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.8 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
0f3d15cac0465c753b1d0e3f7367ffbaa08156a5546f750fbb67243d35010b69
|
|
BLAKE2b-256 checksum How to use checksums |
86e60ecd7f4703f2cff771c9848d3362cc91eb679ad69c94359625f8fe923278
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|