Using Chonkie takes two simple steps: First, install the package. Next, start chunking!
This page covers Chonkie Open Source. To get started with our API, visit the
API Reference.
Installation
Want more features? Install everything with pip install "chonkie[all]". See
Installation for more options.
JavaScript
Install the core package for local chunking
npm install @chonkiejs/core
Chonkie JS provides local support for TokenChunker, SentenceChunker, RecursiveChunker, FastChunker, TableChunker, SemanticChunker, and CodeChunker. Other chunkers are available through the API.
CHONK! 🦛✨
# First import the chunker you want from Chonkie
from chonkie import TokenChunker
# Initialize the chunker
chunker = TokenChunker() # defaults to using character tokenizer
# Here's some text to chunk
text = """Woah! Chonkie, the chunking library is so cool!"""
# Chunk some text
chunks = chunker(text)
# Access chunks
for chunk in chunks:
print(f"Chunk: {chunk.text}")
print(f"Tokens: {chunk.token_count}")
// First import the chunker you want from Chonkie
import { RecursiveChunker } from "@chonkiejs/core";
// Create a chunker
const chunker = await RecursiveChunker.create({
chunkSize: 512,
minCharactersPerChunk: 24,
});
// Chunk your text
const chunks = await chunker.chunk(
"Woah! Chonkie, the chunking library is so cool!"
);
// Use the chunks
for (const chunk of chunks) {
console.log(chunk.text);
console.log(`Tokens: ${chunk.tokenCount}`);
}