ChunkHive
Hierarchical, semantic code chunking with embeddings 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
✨ New Features
- 🌳 Hierarchical Chunking - Preserves code structure
- 🧠 Semantic Embeddings - Turn code into vectors (NEW in v0.3.1!)
- 🔍 Vector Search - Find code by meaning, not just names
- 🤖 4 Pre-trained Models - CodeBERT, UniXcoder, and more
- ⚡ Fast & Scalable - Process large codebases efficiently
Semantic Search (NEW!)
# Generate embeddings
chunkhive embed generate chunks.jsonl -o chunks_embedded.jsonl
# Generate with model choice
chunkhive embed generate chunks.jsonl --model unixcoder -o embedded_unixcoder.jsonl
# Create index
chunkhive embed index data\embeddings\chunks_embedded -o chunks_embedded.jsonl
# search query :
chunkhive embed search-index "your query" --index data\embeddings\crewai_index -k 2
# List available models
chunkhive embed models
# Search semantically ( for debugging,testing etc)
chunkhive embed search "authentication function" --chunks chunks_embedded.jsonl
What's New in v0.3.1
🎉 Semantic Embeddings!
- Generate vector embeddings for code chunks
- 4 pre-trained models (CodeBERT, UniXcoder, CodeSage, MiniLM)
- Fast similarity search with FAISS
- Natural language code search
🔄 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.
Metadata
Release files for chunkhive 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| chunkhive-0.3.1.tar.gz | 211.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chunkhive-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 474.7 kB
Release files / chunkhive-0.3.1.tar.gz
| Download URL | chunkhive-0.3.1.tar.gz |
|---|---|
| Size | 211.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e440cbfc29de96db5a724e7b3661ca2eceb15d59aabcad1c2d22951a0581ac7
|
|
BLAKE2b-256 checksum How to use checksums |
8afc3f14a6ac1e0e53d9054393442ee46ce9c665f6e2a1f23b90ff0603877214
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Release files / chunkhive-0.3.1-py3-none-any.whl
| Download URL | chunkhive-0.3.1-py3-none-any.whl |
|---|---|
| Size | 262.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a26ee02a41fbb6635b9713fd8f91dfdeebd330875c98521147f0b94fa73a368
|
|
BLAKE2b-256 checksum How to use checksums |
7fb42e6de5542b50b6a7905ead856097aa7a96ddba231efb48f45bb455bd9148
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Security for chunkhive 0.3.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.