What is semchunk?
semchunk is a Python library for splitting text into smaller chunks while keeping as much local semantic context as possible. It uses a hierarchical chunking algorithm and works with any tokenizer or token counter, including those from Tiktoken and Transformers. It sits in the Parsing & Ingestion category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python.
Overview
semchunk is a Python library for splitting text into smaller chunks while keeping as much local semantic context as possible. It uses a hierarchical chunking algorithm and works with any tokenizer or token counter, including those from Tiktoken and Transformers.
It is aimed at developers building retrieval-augmented generation (RAG) pipelines who need to break long documents into chunks before embedding and indexing them. You pass a tokenizer name or a custom token-counting function plus a target chunk size, and semchunk returns the chunks.
Within the parsing and ingestion stage of a RAG system, semchunk handles the splitting step. It supports chunk overlap, chunk offsets, multiprocessing for large batches, and an optional AI-powered chunking mode that uses Isaacus enrichment models.
What it does
- Works with any tokenizer or token counter, including Tiktoken encodings, Transformers tokenizers, OpenAI model names, or a custom function
- Returns chunk offsets when you pass offsets=True, so you can map chunks back to the source text
- Supports chunk overlap by a ratio (values < 1) or an absolute token count (values >= 1)
- Optional multiprocessing via the processes argument to speed up chunking large batches of texts
- Optional AI-powered chunking using Isaacus enrichment models such as kanon-2-enricher
- Available on PyPI and conda-forge, with a community Rust port (semchunk-rs)
Getting started
Install semchunk from PyPI, then build a chunker by passing a tokenizer and a target chunk size.
Install semchunk
Install with pip (or uv). It is also available on conda-forge.
pip install semchunkBuild a chunker and chunk text
Create a chunker with chunkerify() by passing a tokenizer name (here an OpenAI Tiktoken encoding) and a chunk size, then call it on your text. Passing a list of texts returns a list of lists of chunks.
import semchunk
chunk_size = 4 # tokens per chunk
text = 'The quick brown fox jumps over the lazy dog.'
chunker = semchunk.chunkerify('cl100k_base', chunk_size)
assert chunker(text) == ['The quick brown fox', 'jumps over the', 'lazy dog.']Get offsets and overlap (optional)
Pass offsets=True to also return where each chunk starts and ends, and overlap to overlap chunks by a ratio (< 1) or an absolute number of tokens (>= 1).
chunks, offsets = chunker(text, offsets=True, overlap=0.5)Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Splitting long documents into chunks before embedding them for a RAG pipeline
- Preparing text for a vector database while keeping local semantic context intact
- Chunking with the same tokenizer your embedding or LLM uses, so chunk sizes match the model's token budget
- Processing large batches of documents quickly using multiprocessing
How semchunk compares
semchunk alongside other open-source parsing & ingestion tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| MarkItDown | ★ 199k | A Microsoft Python utility that converts many file types, including Office docs and PDFs, into Markdown for LLMs. |
| MinerU | ★ 84.6k | A document extraction tool that converts PDFs and Office files into clean Markdown or JSON, with strong handling of complex layouts and CJK content. |
| Docling | ★ 71.2k | An IBM-originated document conversion pipeline that turns PDF, DOCX, PPTX, HTML, and more into structured, LLM-ready Markdown or JSON. |
| Marker | ★ 41.1k | A fast pipeline that converts PDFs and other documents to Markdown, JSON, or HTML while preserving tables, equations, and formatting. |
| OpenDataLoader PDF | ★ 30.4k | OpenDataLoader PDF turns any PDF into structured Markdown, JSON, or HTML with bounding boxes, and auto-tags untagged files into screen-reader-ready Tagged PDFs. |
| Repomix | ★ 29.5k | Repomix packs an entire repository into one file that is easy to feed to AI tools like Claude, ChatGPT, and Gemini. |
| Unstructured | ★ 15.8k | A library for ingesting and preprocessing many document types into clean, chunked elements ready for RAG pipelines. |
| semchunk | ★ 671 | Split text into semantically meaningful chunks for embedding and retrieval |

