Skip to content

Omnichunk

Build retrieval chunks with verifiable source locations, explicit size limits and enough structure to preserve the meaning of code and documents. Omnichunk is a Python library for the chunking stage of a RAG pipeline. Your application chooses the embedding model, retrieval backend and answer generator.

First chunks

pip install omnichunk

The examples on this site describe the repository's current API. For unreleased changes, install a checkout with pip install -e .; use the migration guide when upgrading an existing index.

from omnichunk import Chunker

source = "# Retention policy\n\nCustomer backups expire after 30 days.\n"
chunker = Chunker(max_chunk_size=256, size_unit="chars")
chunks = chunker.chunk("policies/retention.md", source)

for chunk in chunks:
    # Embed this payload; its rendered context also fits the configured limit.
    assert len(chunk.contextualized_text) <= 256
    print(chunk.contextualized_text)

    # Cite the original text, with zero-based, half-open UTF-8 byte coordinates.
    start, end = chunk.byte_range.start, chunk.byte_range.end
    assert source.encode("utf-8")[start:end].decode("utf-8") == chunk.text

Character sizing is the default. For a model token limit, install a compatible tokenizer and configure it explicitly:

pip install "omnichunk[tiktoken]"
chunker = Chunker(max_chunk_size=512, size_unit="tokens", tokenizer="cl100k_base")

Choose the tokenizer used by your embedding model. Reserve additional space for prompt instructions, citation labels and separators when assembling LLM context. See the source and budget contracts for overlap, lossless reconstruction, overflow and token accuracy.

Choose a workflow

You need Start with
Practical chunking, files, streaming, hierarchy and diffs Chunking recipes
Every chunk setting, accepted values and defaults Chunk options
Types, classes, methods and function signatures Python API reference
A local retrieval pipeline with updates, deletions and citations Index, retrieve and synchronize
AST boundaries and code entities Install omnichunk[code]; inspect language_capabilities() for actual parser support.
PDF, DOCX or notebooks Install format extras, use chunk_file(), and retain canonical extracted text for citations.
Search a local code and docs project Runnable retrieval and RAG example
Semantic boundaries Supply an embedding callback; see the runnable examples.
Parent context, diffs, framework conversion or vector export Python API and examples
Reproducible evaluation Performance methodology
A safe upgrade of a persisted index Migration guide

What to evaluate before adoption

The base install has no mandatory third-party dependencies. Optional parsers, tokenizers and loaders affect capabilities and output; pin them with the chunking configuration for reproducible index generations. Streaming yields chunks but still retains source and parser state. SQLite synchronization is atomic locally; delivery to an external vector database is the application's responsibility.

Retrieval quality depends on your corpus, queries, embedding model and retriever. Omnichunk does not currently establish a cross-corpus quality lead or universal throughput SLA. The roadmap defines the evidence and production capabilities needed to earn that position.

API stability · Changelog · Source and issues