SemanticChunker splits text into chunks based on semantic similarity, ensuring that related content stays together in the same chunk. This chunker now includes advanced features like Savitzky-Golay filtering for smoother boundary detection and skip-window merging for connecting related content that may not be consecutive. This chunker is inspired by the work of Greg Kamradt.
API Reference
To use theSemanticChunker via the API, check out the API reference documentation.
Installation
SemanticChunker requires additional dependencies for semantic capabilities. You can install it with:For installation instructions, see the Installation Guide.
Initialization
- Python
- JavaScript
Parameters
Model identifier or embedding model instance
Similarity threshold for grouping sentences (0-1). Lower values create larger groups.
Maximum tokens per chunk
Number of sentences to consider for similarity calculation
Minimum number of sentences per chunk
Minimum number of characters per sentence
Number of groups to skip when looking for similar content to merge.
0(default): No skip-and-merge, uses standard semantic grouping1or higher: Enables merging of semantically similar groups within the skip window
Window length for the Savitzky-Golay filter used in boundary detection
Polynomial order for the Savitzky-Golay filter
Tolerance for the Savitzky-Golay filter boundary detection
Delimiters to split sentences on
Include delimiters in the chunk text. Specify whether to include with the previous or next sentence.
Basic Usage
- Python
- JavaScript
Examples
Basic Semantic Chunking
Basic Semantic Chunking
Skip-Window Merging
Skip-Window Merging
Fine-tuned Similarity Control
Fine-tuned Similarity Control
Batch Document Processing
Batch Document Processing
Custom Embeddings Integration
Custom Embeddings Integration
Advanced Filtering Options
Advanced Filtering Options
Sentence Configuration
Sentence Configuration
RAG Pipeline Integration
RAG Pipeline Integration
Advanced Features
Savitzky-Golay Filtering
The SemanticChunker uses Savitzky-Golay filtering for smoother boundary detection in similarity curves. This reduces noise in the semantic similarity signal and provides more stable chunk boundaries.Skip-Window Merging
Whenskip_window > 0, the chunker can merge semantically similar groups that are not consecutive. This is useful for:
- Documents with alternating topics
- Content with recurring themes
- Technical documents with distributed related sections
Supported Embeddings
SemanticChunker supports multiple embedding providers through Chonkie’s embedding system. See the Embeddings Overview for more information.Return Type
SemanticChunker returnsChunk objects:
