Chunkers API
This module provides tools for splitting documents into segments.
Base Chunker
maticlib.core.text.chunkers.base.BaseChunker
Bases: ABC
Abstract base class for all text chunkers.
Initializes the BaseChunker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_size
|
int
|
Maximum character length of a single chunk. |
1000
|
overlap_size
|
int
|
Number of characters from the previous chunk to overlap. |
200
|
Source code in maticlib/core/text/chunkers/base.py
chunk_documents
Accepts a list of document dictionaries and chunks each one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
List[Dict[str, Any]]
|
List of dicts with |
required |
Returns:
| Type | Description |
|---|---|
List[TextSegment]
|
A flat list of TextSegments from all documents. |
Source code in maticlib/core/text/chunkers/base.py
chunk_text
abstractmethod
Split a single text string into multiple TextSegments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The raw text content to split. |
required |
base_metadata
|
Optional[Dict[str, Any]]
|
Optional metadata dict to attach to each segment. |
None
|
parent_id
|
Optional[str]
|
Optional parent segment ID for hierarchical chunking. |
None
|
Returns:
| Type | Description |
|---|---|
List[TextSegment]
|
A list of TextSegment objects. |
Source code in maticlib/core/text/chunkers/base.py
Separator Chunker
maticlib.core.text.chunkers.separator.SeparatorChunker
Bases: BaseChunker
Initializes the SeparatorChunker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
separator
|
str
|
The string used to split the text (default |
'\n\n'
|
target_size
|
int
|
Maximum character length of a single chunk. |
1000
|
overlap_size
|
int
|
Number of characters from the previous chunk to overlap. |
200
|
Source code in maticlib/core/text/chunkers/separator.py
chunk_text
Splits text by the separator and groups splits into chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The raw text content to split. |
required |
base_metadata
|
Optional[Dict[str, Any]]
|
Optional metadata to attach to each segment. |
None
|
parent_id
|
Optional[str]
|
Optional parent segment ID. |
None
|
Returns:
| Type | Description |
|---|---|
List[TextSegment]
|
A list of TextSegment objects. |
Source code in maticlib/core/text/chunkers/separator.py
Token Budget Chunker
maticlib.core.text.chunkers.token_budget.TokenBudgetChunker
Bases: BaseChunker
Source code in maticlib/core/text/chunkers/token_budget.py
Semantic Difference Chunker
maticlib.core.text.chunkers.semantic_difference.SemanticDifferenceChunker
SemanticDifferenceChunker(
embedding_model,
similarity_threshold=0.75,
min_chunk_size=100,
buffer_sentences=1,
)
Bases: BaseChunker
Source code in maticlib/core/text/chunkers/semantic_difference.py
Hierarchical Chunker
maticlib.core.text.chunkers.hierarchical.HierarchicalChunker
Bases: BaseChunker