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.0.1
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.0.1.tar.gz | 80.5 kB | Details |
Built distributions (wheels)
Total release size: 44.4 MB
Release files / chunkr_rs-1.0.1.tar.gz
| Download URL | chunkr_rs-1.0.1.tar.gz |
|---|---|
| Size | 80.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6adf43a3a85847d3a0abaea76940091623def946865a5624c2411d7c67d40f43
|
|
BLAKE2b-256 checksum How to use checksums |
19ccff06341ea4054e5bf54309e5517961e91ce6e4d7350f2b7265afa0d05106
|
| 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.0.1-cp38-abi3-win_amd64.whl
| Download URL | chunkr_rs-1.0.1-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
548648b79a62c0beda202665146bf355a902f794d6237c6974e4a21c16666a34
|
|
BLAKE2b-256 checksum How to use checksums |
4c85be03248c7b507ed11f15b3926f0d50561d432687dfbc3dd37716e689b1e7
|
| 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.0.1-cp38-abi3-win32.whl
| Download URL | chunkr_rs-1.0.1-cp38-abi3-win32.whl |
|---|---|
| Size | 4.6 MB |
| Tags | CPython 3.8 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
067553a0c4620e4d731b77ad6fac9362585936a41385c918b0aa0037bbea2b89
|
|
BLAKE2b-256 checksum How to use checksums |
5e2029e937332db9affb00eddce551e1bc25f1ac3c027a0672f9716ce5769e03
|
| 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.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | chunkr_rs-1.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
4d4c89fc81de8e4ada91090946c96611b75f5341a4101970b3aaf68b11e4f76b
|
|
BLAKE2b-256 checksum How to use checksums |
b227b2a84fa0a64e1d1059df3d479a1d5954d91a1fd3fdf6dc8bb84c9f636c2a
|
| 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.0.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | chunkr_rs-1.0.1-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 5.1 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
75e7cbd2086a90ba2026cb0f564ade7718d96ffd80b985a5a283e49b3c6d3c45
|
|
BLAKE2b-256 checksum How to use checksums |
2b78d1b76cd58f7de32d100caafc2e7d7090e9e0b16111140dd365d7b002ecf4
|
| 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.0.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | chunkr_rs-1.0.1-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 5.3 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
082da257541f5f6bd1d875175bec5e3c7181ba2d7ab9e0808fb69f1d0e77877b
|
|
BLAKE2b-256 checksum How to use checksums |
9daf154fe83b3dedc6990ba8499611c53ce76284419fd1f1759afbe4736becc6
|
| 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.0.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | chunkr_rs-1.0.1-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
16692a3b0ad45fa3404c51a266130681554c27baa5ee408f94d5f04ce22c967a
|
|
BLAKE2b-256 checksum How to use checksums |
e75e2e620ee1b18545e3d0628f932c3fac1e457d1b3fcf44be468d67aeb1e540
|
| 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.0.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | chunkr_rs-1.0.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
98a51d0cbe891cf219e303b83b8374bb2fba853d7c66d670e3377340e64c25b2
|
|
BLAKE2b-256 checksum How to use checksums |
1bb3d83bcf53634aae319514c482b52eb2070567ee95bca1bcb2f47e6090e3bf
|
| 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.0.1-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | chunkr_rs-1.0.1-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
732abcfd95abf26210cd8d84a629437703a7372f0ed84215ffd493cbf43f953e
|
|
BLAKE2b-256 checksum How to use checksums |
a4c48a43a3f739055d24f846fde41ba42e8da237601b34cb220e62ce77cce8ee
|
| 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.0.1-cp38-abi3-macosx_10_12_x86_64.whl
| Download URL | chunkr_rs-1.0.1-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 |
9456c997fcd23a5ff88776c43266e8701e784b271529b51243a6fd8558618eb3
|
|
BLAKE2b-256 checksum How to use checksums |
55c2633285c1ec9649a7cac98c0e0dd65660bfea65f3eea92e35d6247792a735
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|