CodeChunker
Split code into chunks based on code structure
The CodeChunker
splits code into chunks based on its structure, leveraging Abstract Syntax Trees (ASTs) to create contextually relevant segments.
API Reference
To use the CodeChunker
via the API, check out the API reference documentation.
Installation
CodeChunker requires additional dependencies for code parsing. You can install it with:
Initialization
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 the list of corresponding AST Node
objects within each CodeChunk
.
Whether to return chunks as CodeChunk
objects or plain text strings.
Usage
Single Code Chunking
Batch Chunking
Using as a Callable
Return Type
CodeChunker returns chunks as CodeChunk
objects: