Skip to main content
OmniChunk — code, documents, RAG

Structure-aware chunking for reliable RAG.

Turn code and documents into traceable chunks.
Preserve useful structure, set explicit size budgets, and keep indexes in sync.

PyPI version CI Test coverage Supported Python versions MIT license

Documentation · Quick start · Examples · Contribute


A Markdown document becomes two chunks: the heading and first paragraph at bytes [0, 40), then the second paragraph at [40, 63). Both retain the Retention heading as metadata.

Why OmniChunk?

Preserve structure Trace every chunk Control your index
Follow code declarations, document headings and paragraph boundaries. Retain scope and import context where supported. Keep canonical UTF-8 source ranges, source identity and revision metadata alongside the retrieval payload. Budget the final rendered payload. Detect edits, reuse unchanged embeddings and apply explicit index updates.

Local structural processing. No mandatory dependencies in the base install. Choose your own embedding model and retrieval backend; add parsers, tokenizers and integrations as you need them.

Quick start

Python 3.10+:

pip install omnichunk
from omnichunk import Chunker

source = "# Retention\n\nKeep backups for 30 days.\n\nDelete expired copies.\n"
chunker = Chunker(max_chunk_size=48, size_unit="chars", context_mode="none")

for chunk in chunker.chunk("policy.md", source):
    print(chunk.byte_range.start, chunk.byte_range.end, repr(chunk.text))
0 40 '# Retention\n\nKeep backups for 30 days.\n\n'
40 63 'Delete expired copies.\n'

Both chunks retain Retention in chunk.context.heading_hierarchy. Source ranges address the original text; chunk.contextualized_text is the payload to embed when you enable rendered context.

Code and model tokens

Add AST parsers and a tokenizer when your workflow needs them:

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

Use the tokenizer that matches your downstream model. The default split policy checks the complete rendered payload against the selected budget. Tokenizer assets may download on first use; cache them for offline runs. See all options and defaults and the source and budget contracts.

Built for code and documents

Input What you can retain
Source code AST boundaries, declarations, scopes, comments and import context. The code extra includes Python, JavaScript, TypeScript, Rust, Go and Java grammars.
Markdown and prose Headings, paragraph boundaries, lists, tables and fenced code, with exact source locations.
Structured documents Load notebooks, RST and LaTeX; add the formats extra for PDF/DOCX text extraction. Ranges refer to canonical extracted text.

Additional grammars are available through all-languages. Parser availability and extraction depth vary; language_capabilities() reports the installed capabilities and diagnosed fallbacks. See installation and runnable recipes for format, semantic and boundary-policy options.

Fits your retrieval stack

Workflow Integration
LangChain Native OmniChunkTextSplitter with chunk IDs, metadata and source references.
LlamaIndex Native nodes, hierarchy relationships and an identity-aware ingestion pipeline.
Qdrant / pgvector Optional acknowledged sinks with resumable delivery through IndexJournal.
Your own pipeline Plain Python chunks, sync/async/batch APIs, iterators, JSONL/CSV and vector payload exports.

Follow the indexing guide for adapters, cached ingestion and recoverable updates, or browse the API reference.

Keep a changing corpus in sync

chunker = Chunker(max_chunk_size=256, context_mode="none")
previous = chunker.chunk("policy.txt", "Retain backups for 30 days.")
changes = chunker.chunk_diff("policy.txt", "Retain backups for 60 days.", previous_chunks=previous)

print(changes.removed_ids)  # Remove old records from your index.
print([chunk.text for chunk in changes.added])  # Embed and upsert new payloads.

Persistent workflows can use a SQLite delivery journal to resume pending writes and reuse prepared vectors. Delivery is at least once; see delivery and recovery semantics before connecting a remote index.

From the terminal

omnichunk ./src --glob "**/*.py" --max-size 512 --size-unit chars --format jsonl > chunks.jsonl

Use chunk_file() for individual files and structured loaders. See files, directories and CLI recipes for more examples. Try the local project search and RAG example to retrieve cited code and documentation.

Measured, with the tradeoffs visible

The evaluation guide and published experiments retain source provenance, shared-budget comparisons, costs, wins and losses. Retrieval quality depends on your corpus, queries, encoder and retriever; there is no universal quality or speed lead. Evaluate settings on representative data.

Go deeper

Start here Reference and project
Installation and extras Classes, methods and parameters
Chunking recipes Source, budget and execution contracts
Indexing and integrations API stability
Runnable examples Changelog · Roadmap

OmniChunk is currently beta. Before upgrading an existing index, follow the migration guide. The contract reference covers parser fallbacks, overflow policies, canonical extraction, streaming memory and optional service boundaries.

Contributing

Bug reports, focused fixes, documentation and reproducible evaluations are welcome. Start with the contribution guide for development setup and checks.

Report a bug · Security policy · Code of conduct · MIT license

Metadata

Release files for omnichunk 2.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for omnichunk 2.3.0
File Size Uploaded Provenance Actions
omnichunk-2.3.0.tar.gz 1.1 MB With provenance Details for omnichunk-2.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for omnichunk 2.3.0
File Interpreter ABI Platform Actions
omnichunk-2.3.0-py3-none-any.whl Python 3 none any Details for omnichunk-2.3.0-py3-none-any.whl

Total release size: 1.3 MB

Release files / omnichunk-2.3.0.tar.gz

Download URL omnichunk-2.3.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
26e7ee4d92768b68266e1accc94943e15ee7e94d6f6cde5dc31d9f4f65862fd6
BLAKE2b-256 checksum
How to use checksums
d2d8b31e6688503983eec40b64c9cd00eeeb77cde6233b96a016125152fc4a9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / omnichunk-2.3.0-py3-none-any.whl

Download URL omnichunk-2.3.0-py3-none-any.whl
Size 190.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62a31585f4b34866655fbdcab4f157ac23d9ff1042f8134e32733ba5e7c7f052
BLAKE2b-256 checksum
How to use checksums
2cb4f1b65c986c1288089d1367bf4f27c4e905a2c0aba604d2642e8316d0eb6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Security for omnichunk 2.3.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for omnichunk-2.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page