CodeChunker splits code into chunks based on its structure, leveraging Abstract Syntax Trees (ASTs) to create contextually relevant segments.
Overview
- Supports 165+ languages
- Powered by tree-sitter-language-pack
- Auto language detection via Magika, a language detection library made by Google
Supported Languages
Show all supported languages
Show all supported languages
Each language is identified by the key used with
get_language(key) and get_parser(key).General-Purpose Programming Languages
| Language | Key | License |
|---|---|---|
| ActionScript | actionscript | MIT |
| Ada | ada | MIT |
| Agda | agda | MIT |
| C | c | MIT |
| C++ | cpp | MIT |
| C# | csharp | MIT |
| Dart | dart | MIT |
| Go | go | MIT |
| Java | java | MIT |
| JavaScript | javascript | MIT |
| Julia | julia | MIT |
| Kotlin | kotlin | MIT |
| Nim | nim | MPL-2.0 |
| OCaml | ocaml/ocaml_interface | MIT |
| Perl | perl | Artistic-2.0 |
| Python | python | MIT |
| R | r | MIT |
| Ruby | ruby | MIT |
| Rust | rust | MIT |
| Scala | scala | MIT |
| Swift | swift | MIT |
| TypeScript | typescript | MIT |
| Zig | zig | MIT |
Web, UI & Markup
| Language | Key | License |
|---|---|---|
| HTML | html | MIT |
| CSS | css | MIT |
| SCSS | scss | MIT |
| Astro | astro | MIT |
| Vue | vue | MIT |
| Svelte | svelte | MIT |
| TSX | tsx | MIT |
| Markdown | markdown | MIT |
| Markdown Inline | markdown_inline | MIT |
| Mermaid | mermaid | MIT |
| XML | xml | MIT |
| YAML | yaml | MIT |
Config, Build & DevOps
| Language | Key | License |
|---|---|---|
| Bash | bash | MIT |
| Dockerfile | dockerfile | MIT |
| Git Ignore | gitignore | MIT |
| Git Commit | gitcommit | WTFPL |
| Make | make | MIT |
| Ninja | ninja | MIT |
| Meson | meson | MIT |
| Prisma | prisma | MIT |
| Requirements | requirements | MIT |
Systems, GPU & Low-level
| Language | Key | License |
|---|---|---|
| ASM | asm | MIT |
| CUDA | cuda | MIT |
| GLSL | glsl | MIT |
| HLSL | hlsl | MIT |
| LLVM | llvm | MIT |
| Verilog | verilog | MIT |
| VHDL | vhdl | MIT |
| WGSL | wgsl | MIT |
| WAST / WAT | wasm | Apache-2.0 + LLVM |
API Reference
To use theCodeChunker via the API, check out the API reference documentation.
Installation
CodeChunker requires additional dependencies for code parsing. You can install it with:For installation instructions, see the Installation
Guide.
Initialization
Automatic language detection using Magika can impact performance. For best results, specify the language directly via the
language parameter.Parameters
The programming language of the code. Accepts languages supported by
tree-sitter-language-pack.Tokenizer or token counting function to use for measuring chunk size.
Maximum number of tokens per chunk.
Whether to include AST node information (Note: with the base Chunk type, node
information is not stored).
Usage
Single Code Chunking
Batch Chunking
Using as a Callable
Return Type
CodeChunker returns chunks asChunk objects:
As of version 1.3.0, CodeChunker returns the base
Chunk type instead of the
specialized CodeChunk type. This simplifies integration with other chunkers
and refineries.