snipsplit
Token-aware text chunker for RAG ingestion. Sentence-respecting, overlap-friendly. Rust core, Python frontend.
The problem
Your RAG ingestion pipeline needs to split long documents into chunks that fit a context budget. Naive token-window chunking cuts mid-sentence and degrades retrieval. Sentence-only splitting blows the token budget on legal/medical text. The right thing is to greedy-pack sentences into a token-budgeted window, with optional overlap, and fall back to token-level slicing only when a single sentence is genuinely too long.
snipsplit does exactly that, in Rust, fast enough that bulk ingestion
of 100k documents runs in seconds rather than minutes.
Install
pip install snipsplit
30-second quickstart
from snipsplit import Chunker
chunker = Chunker(max_tokens=512, overlap_tokens=64, encoding="cl100k_base")
text = open("long_document.txt").read()
for chunk in chunker.split(text):
print(chunk.token_count, chunk.start, chunk.end, chunk.text[:60])
For batch ingestion across many docs:
texts = [open(p).read() for p in paths]
all_chunks = chunker.split_many(texts, parallel=True) # list[list[Chunk]]
API
class Chunker:
def __init__(
self,
*,
max_tokens: int = 512,
overlap_tokens: int = 0,
min_tokens: int = 1,
encoding: str = "cl100k_base", # or "o200k_base"
) -> None: ...
def split(self, text: str) -> list[Chunk]: ...
def split_many(self, texts: Sequence[str], *, parallel: bool = False) -> list[list[Chunk]]: ...
class Chunk:
text: str
start: int # byte offset in the original text
end: int # byte offset (exclusive)
token_count: int # exact BPE token count
Algorithm
- Split into paragraphs on
\n{2,}, then sentences on[.!?]\s+plus a handful of abbreviations (Mr.,Dr.,e.g., etc.). - Greedy-pack sentences into a chunk while the running token count is
<= max_tokens. - If a single sentence exceeds
max_tokenson its own, slice it at token boundaries (BPE) instead. - Apply
overlap_tokensby re-prepending the last N tokens of each chunk to the next. - Drop chunks shorter than
min_tokens.
License
Dual-licensed under MIT or Apache-2.0 at your option.
Metadata
Release files for snipsplit 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| snipsplit-0.1.1-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
Release files / snipsplit-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | snipsplit-0.1.1-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f4ebc1610937097b9ca35943f2a7513a5332d47c0c2551b9a5c0ed37466f0d8f
|
|
BLAKE2b-256 checksum How to use checksums |
aab2088d8d5abf6794948aad8a8f87b55fe74e30d80ca5cd606e2c998cdfe293
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for snipsplit 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.