A fast document chunking library for RAG pipelines
Project description
⚡ rustchunker
Chunk 100,000 documents in ~13 seconds.
A blazing-fast document chunker for RAG pipelines.
Rust core · Python API · parallel across every CPU core.
Splitting documents into chunks is step one of every RAG pipeline. rustchunker does it with a Rust core and real multi-core parallelism — so a corpus that takes LangChain or LlamaIndex minutes takes rustchunker seconds.
| Chunking 100,000 real documents | Time |
|---|---|
| rustchunker ⚡ | 12.7s |
| semantic-text-splitter | 90.6s |
| chonkie | 108.7s |
| LangChain | 113.5s |
| LlamaIndex | 158.4s |
12 cores · cc_news corpus · sentence strategy. Full methodology, a
five-library comparison, memory, correctness, and the results that don't
favour us → BENCHMARKS.md.
✨ Why rustchunker
- ⚡ Built for scale — ~17–24k chunks/sec, and it pulls further ahead as the corpus grows.
- 🧵 Actually parallel —
chunk_filesfans your whole corpus across every core withrayon, GIL released. Pure-Python libraries can't (they're stuck paying multiprocessing overhead). - 🎯 Clean sentence boundaries — the
sentencestrategy splits only on real Unicode sentence ends: 100% clean boundaries in testing, vs 6–99% for the others. (Withoverlap > 0, chunk heads gain a few words of leading context that may begin mid-sentence — see Strategies.) - 🪶 Light — low memory, and zero Python runtime dependencies.
- 🔌 Drop-in —
pip install, two lines of code, fully typed. - 📄 Reads your files —
.txt,.md, and.htmlparsed and stripped for you.
📦 Install
pip install rustchunker
🚀 Quickstart
from rustchunker import chunk, chunk_files
# One string
for c in chunk("Your long document…", max_tokens=256, overlap=20, strategy="sentence"):
print(c.index, c.text)
# Thousands of files, in parallel across all cores
chunks = chunk_files(
["doc1.md", "doc2.txt", "doc3.html"],
max_tokens=256,
overlap=20,
strategy="sentence",
on_error="skip", # drop unreadable files instead of aborting the batch
)
Files must be UTF-8 (a leading byte-order mark is stripped for you). By default
chunk_files raises on the first file it can't read or parse; pass
on_error="skip" to drop failing files and keep the rest — handy when ingesting
a large, messy corpus where one bad file shouldn't sink the whole run.
Each Chunk has .text, .start / .end (character offsets into the source
document, so source[c.start:c.end] == c.text), .index, and .metadata
(source_file, total_chunks, strategy_used, …).
🧠 Strategies
strategy |
what it does |
|---|---|
"fixed" |
every N tokens, exact — the fast baseline |
"sentence" |
splits on real sentence boundaries (Unicode-aware; keeps "Dr." and "U.S.A." intact), never exceeding max_tokens |
overlap shares N trailing tokens between consecutive chunks — respecting word
boundaries — so context isn't lost at the seams. With the sentence strategy
this leading context is taken at word granularity, so an overlapped chunk's
head can begin part-way through a sentence (its interior boundaries stay
clean). (More strategies on the way.)
What "token" means here: a token is a whitespace-delimited word, not a model / BPE token (tiktoken, SentencePiece, …).
max_tokenscaps words per chunk. Word count only approximates an embedder's token budget (roughly ~0.75×), so leave headroom when sizing chunks against a hard model limit.
🎯 When to use it
Great fit: ingesting a corpus — a knowledge base, document store, or crawl of many files. That's where the parallelism pays off, and it's the common RAG ingestion case.
Honest caveat: for a single document, rustchunker is about as fast as LangChain — the win is at corpus scale, not per call. The full breakdown of "how much is the Rust core vs just using all cores" is in BENCHMARKS.md, decomposed and measured.
⚙️ How it works
The chunking runs in Rust via PyO3, and chunk_files
processes files in parallel with rayon while
releasing the Python GIL — so other threads keep running and you get true
multi-core throughput a pure-Python library can't reach without the overhead of
spawning processes.
🛠️ Building from source
git clone https://github.com/elbachir-salik/rustchunker
cd rustchunker
maturin develop --release # requires Rust + maturin; always use --release for real speed
pytest
📄 License
Dual-licensed under MIT or Apache-2.0, at your option.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rustchunker-1.0.1.tar.gz.
File metadata
- Download URL: rustchunker-1.0.1.tar.gz
- Upload date:
- Size: 606.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08625b616c0f1af924e6fd383675d69ffe5c74e5a97a7f11e852b35bd12b6549
|
|
| MD5 |
7b712b3714a70447d57a08d9f00238fd
|
|
| BLAKE2b-256 |
84c4ba170e7510bf4d327f9f01594aeae7e4f4a7600886f28e4c3915e987a3ba
|
File details
Details for the file rustchunker-1.0.1-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: rustchunker-1.0.1-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 447.6 kB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e97c03633bed058f21dd988251c249a9a23742e70ffa01b3780b2b435f5ed1ee
|
|
| MD5 |
7b793242009e781ab1d5903365c249d2
|
|
| BLAKE2b-256 |
7ac53b0dd76da9e0c69f616e31fd91082ac6f58bafc5dfc4863530671d5635ec
|
File details
Details for the file rustchunker-1.0.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rustchunker-1.0.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 560.2 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef1ddd8065346d3914e06076a368eda454a908f40fb5002bfd329d424d2899fe
|
|
| MD5 |
225c44972379214c8871a566305c7891
|
|
| BLAKE2b-256 |
dee72c063aa6a70a9f72cb9753844fc805a28d86c23c8ee062b51cb34a8e4ae5
|
File details
Details for the file rustchunker-1.0.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: rustchunker-1.0.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 569.0 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b59197c3cc95e478dc77681ca018443cce709e3f9718a866102615f1d6cfc07
|
|
| MD5 |
589e3a09378839359041ef81f861821e
|
|
| BLAKE2b-256 |
b049c084cc9799aa6302538763516be4a48ead0ba9d6a5f9ba581eed9b5341d3
|
File details
Details for the file rustchunker-1.0.1-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: rustchunker-1.0.1-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 501.6 kB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ec771e7ee438ec8ccbf6d1f90d95f4b230235492877445b52551fc4f2679eaa
|
|
| MD5 |
0ad890ab21f29da9817254d80cd9a85c
|
|
| BLAKE2b-256 |
94b01dfe6dc6b03842df7881fe8e877eab5c35f26ee27697eeeffcfd92518831
|
File details
Details for the file rustchunker-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: rustchunker-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 505.3 kB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4de1d2d7da8cd361b1e59493be037b30a42c5d0fe9ba86bf52effb69aa29ed80
|
|
| MD5 |
b0d10c8377bc69e1bf9dc9ce8fc5dc66
|
|
| BLAKE2b-256 |
2ef77f07b297c7b4278a25f4280deb0b54d1ad56eefa55e11d1bbf7969584b35
|