Skip to main content

Hierarchical, semantic code chunking for AI systems

Project description

chunkhive

Semantic, hierarchical code chunking for AI systems

Chunkhive is a production-grade code chunking engine designed for modern AI workflows such as code embeddings, retrieval-augmented generation (RAG), agentic systems, and dataset synthesis.

It converts raw repositories into clean, structured, semantically accurate chunks with byte-level precision and preserved hierarchy.


🚀 Why chunkhive?

Modern AI systems need more than naive text splitting.

chunkhive provides:

  • AST-first semantic correctness
  • Hierarchical structure awareness
  • Byte-accurate spans
  • Robust parsing across real-world repositories

🧠 Core Principle

AST is the Authority, Tree-sitter is Enrichment

  • Primary source of truth: Language AST (semantic accuracy)
  • Fallback & enrichment: Tree-sitter (structural robustness)
  • Result: Maximum parsing success across diverse codebases

✨ Features

  • Semantic AST-first chunking (no filename-based chunks)
  • Preserves hierarchy: Module → Class → Method / Function
  • Accurate parent–child relationships
  • Byte-level precision (start_byte, end_byte)
  • Clean symbol naming (ast.name)
  • Import & decorator capture
  • Robust handling of edge cases (empty files, __init__.py)
  • Supports documentation + code chunking flows

🗂 Supported Chunk Types

  • module
  • class
  • method
  • function
  • documentation

📦 Installation

pip install chunkhive


[![PyPI](https://img.shields.io/pypi/v/chunkhive)](https://pypi.org/project/chunkhive/)
[![Python](https://img.shields.io/pypi/pyversions/chunkhive)](https://pypi.org/project/chunkhive/)
[![License](https://img.shields.io/pypi/l/chunkhive)](https://pypi.org/project/chunkhive/)


---

## 📦 Output Schema (Simplified)

```json
{
  "chunk_id": "ts_123_456",
  "file_path": "src/example.py",
  "chunk_type": "function",
  "language": "python",
  "code": "...",
  "ast": {
    "name": "my_function",
    "parent": "MyClass"
  },
  "span": {
    "start_byte": 123,
    "end_byte": 456,
    "start_line": 10,
    "end_line": 25
  },
  "metadata": {
    "byte_accuracy": "exact_bytes"
  }
}

🛠 Use Cases

Code embedding model training

RAG pipelines

Agentic AI systems

Code search & navigation

QA dataset generation

Static analysis & tooling

📜 License

Apache License 2.0 — free to use, modify, and distribute, including commercial use.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chunkhive-0.1.1.tar.gz (43.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chunkhive-0.1.1-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

File details

Details for the file chunkhive-0.1.1.tar.gz.

File metadata

  • Download URL: chunkhive-0.1.1.tar.gz
  • Upload date:
  • Size: 43.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for chunkhive-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a5f63ac2170667c35f5c97dc0995fd2d8e6094fc2b58aabb26ddf25fc9abeabf
MD5 fef44b7b7bb640517768f2fe6020a7bd
BLAKE2b-256 93a3ed8e6801f4d3c5b734271ea2f9e69f0cf811240fb046e48e7dad90388b8f

See more details on using hashes here.

File details

Details for the file chunkhive-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: chunkhive-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 43.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for chunkhive-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1897bb1a338f12f8fdd41f56e1d03f32c32bf6201a582667e15000b11dda8cc1
MD5 f90a5ceb346232093f01d7cafc49d825
BLAKE2b-256 1d10c5e38e95bbe3d7c8e5ef002b9f1ece5d7af77fa7fe9fed0b0f7beeff61d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page