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

🔄 Multi-Language Support

Currently Supported:

Python: Full AST parsing with decorators, imports, docstrings

Markdown/RST: Documentation chunking with code block detection

Configuration Files: JSON, YAML, TOML, INI, Dockerfiles

Text Files: README, LICENSE, requirements.txt, scripts

🔄 Coming Soon:

JavaScript/TypeScript

C++/Java/Go

🗂 Supported Chunk Types

module

class

method

function

documentation

configuration (JSON, YAML, TOML)

text

imports

🏢 Production Features

Deterministic IDs: Same code → same chunk ID across runs

Progress Indicators: Real-time processing feedback

Error Resilience: Graceful handling of malformed code

Statistics Generation: Detailed analytics and metrics

Batch Processing: Process multiple repositories from config file

Permission Handling: Intelligent output path resolution

📦 Installation

pip install chunkhive

Quick Start

Basic usage (creates in current directory)

chunkhive chunk local ./my_project

With output directory

chunkhive chunk local ./my_project -o ./output

With custom name and statistics

chunkhive chunk local ./my_project --name my_dataset --stats

chunkhive chunk repo https://github.com/user/repo --name my_dataset --stats

Clone and chunk any GitHub repository

chunkhive chunk repo https://github.com/user/repo

With filtering and limits

chunkhive chunk repo https://github.com/langchain-ai/langchain
--extensions .py,.md
--max-files 100
--name langchain_chunks

Single File Processing

chunkhive chunk file example.py

chunkhive chunk file example.py -o ./chunks.jsonl --stats

Repository Analysis

Analyze repository metadata

chunkhive analyze https://github.com/crewAIInc/crewAI

chunkhive analyze ./local/repo --output analysis.json

Show Examples

chunkhive examples

Check Version & Info

chunkhive version # Show current version

chunkhive info # Show system information

📦 Output Schema (Simplified)

{
  "chunk_id": "primary_a1b2c3d4",
  "file_path": "src/example.py",
  "chunk_type": "function",
  "language": "python",
  "code": "...",
  "ast": {
    "name": "my_function",
    "parent": "MyClass",
    "symbol_type": "function",
    "docstring": "Function documentation",
    "decorators": ["@decorator"],
    "imports": ["import module"]
  },
  "span": {
    "start_byte": 123,
    "end_byte": 456,
    "start_line": 10,
    "end_line": 25
  },
  "hierarchy": {
    "parent_id": "parent_chunk_id",
    "children_ids": ["child1", "child2"],
    "depth": 2,
    "is_primary": true
  },
  "metadata": {
    "byte_accuracy": "exact_bytes",
    "repo_info": {
      "agentic_detection": {"langchain": "usage"},
      "dependencies": {"python_packages": ["pandas", "numpy"]},
      "git": {"remote_url": "https://github.com/user/repo"},
      "structure": {"file_types": {".py": 50, ".md": 10}}
    },
    "repository_context": {
      "similar_files": ["src/other.py"],
      "total_similar_files": 5
    }
  }
}

🛠 Use Cases

Code embedding model training

RAG pipelines

Agentic AI systems

Code search & navigation

QA dataset generation

Static analysis & tooling

Enterprise codebase intelligence

AI training data generation

📜 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.8.tar.gz (53.6 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.8-py3-none-any.whl (61.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chunkhive-0.1.8.tar.gz
  • Upload date:
  • Size: 53.6 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.8.tar.gz
Algorithm Hash digest
SHA256 e473632fbe68d4de52f6aa83ee7c44ecedb18b2d77d5ad40ccd019e7d23923fa
MD5 84b50cb43395299b7891574a8b4f3e1f
BLAKE2b-256 bafd890739db3ef1d18685d67f90d33a42ae6eb49f3e7d936e256d1defe05d59

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chunkhive-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 61.2 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 6a6448aa286068fc7ef43f3a7aff895628ea00feb97f5dc694ab0fce17d4f640
MD5 10bcb936ca001d6f398ea0f6b12b5431
BLAKE2b-256 31e42b089f6ac4f76145f58ba7df18248bfe8e1da530f5a683719ddfcebf3813

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