Chunking Strategies
When you add documents to a Knowledge Base, Tensoras splits them into chunks before generating embeddings and indexing. The chunking strategy determines how text is divided, which directly affects retrieval quality. Tensoras supports four chunking strategies.
Strategies at a Glance
| Strategy | Best For | How It Splits |
|---|---|---|
| Semantic (default) | Most use cases | Topic boundaries detected by embedding similarity |
| Fixed size | Uniform chunk lengths | Character count with configurable overlap |
| Recursive character | Structured documents | Hierarchical separators (\n\n, \n, ., space) |
| Hierarchical | Multi-level retrieval | Parent-child chunks at different granularities |
Semantic Chunking (Default)
Semantic chunking splits text at natural topic boundaries by analyzing embedding similarity between consecutive sentences. When the similarity drops below a threshold, a new chunk starts. This produces chunks that are topically coherent, which improves retrieval relevance.
This is the default and recommended strategy for most use cases.
from tensoras import Tensoras
client = Tensoras(api_key="tns_your_key_here")
kb = client.knowledge_bases.create(
name="Research Papers",
embedding_model="bge-large-en-v1.5",
chunking_strategy={
"type": "semantic",
},
)Semantic chunking produces variable-length chunks. Typical chunks range from 200 to 1,500 tokens depending on the document structure.
Fixed Size Chunking
Fixed size chunking splits text into chunks of a specified character count with an optional overlap between consecutive chunks. Overlap helps preserve context at chunk boundaries.
kb = client.knowledge_bases.create(
name="Legal Contracts",
embedding_model="bge-large-en-v1.5",
chunking_strategy={
"type": "fixed_size",
"chunk_size": 1000, # characters per chunk
"chunk_overlap": 200, # overlap between consecutive chunks
},
)When to use: When you need predictable, uniform chunk sizes — for example, when working with highly uniform documents like legal contracts or log files.
Recursive Character Chunking
Recursive character chunking splits text using a hierarchy of separators, trying the most meaningful separator first and falling back to less meaningful ones:
\n\n— paragraph breaks\n— line breaks.— sentence boundaries— word boundaries
This preserves document structure (paragraphs, sentences) while keeping chunks under the size limit.
kb = client.knowledge_bases.create(
name="Technical Docs",
embedding_model="bge-large-en-v1.5",
chunking_strategy={
"type": "recursive",
"chunk_size": 1000,
"chunk_overlap": 200,
},
)When to use: When documents have clear structural markers (paragraphs, sections) and you want chunks that respect those boundaries while staying under a size limit.
Hierarchical Chunking
Hierarchical chunking creates parent-child chunk relationships at multiple levels of granularity. Small child chunks are used for precise retrieval, while their larger parent chunks provide broader context when needed.
kb = client.knowledge_bases.create(
name="Knowledge Base",
embedding_model="bge-large-en-v1.5",
chunking_strategy={
"type": "hierarchical",
"parent_chunk_size": 2000,
"child_chunk_size": 500,
"child_chunk_overlap": 100,
},
)During retrieval, Tensoras searches over child chunks for precision, then optionally expands to the parent chunk to provide the model with more surrounding context.
When to use: When your documents contain information at different levels of detail, or when you find that small chunks retrieve well but lack sufficient context for the model to answer accurately.
Configuration Reference
The chunking_strategy object is passed when creating a Knowledge Base:
{
"chunking_strategy": {
"type": "semantic | fixed_size | recursive | hierarchical",
"chunk_size": 1000,
"chunk_overlap": 200,
"parent_chunk_size": 2000,
"child_chunk_size": 500,
"child_chunk_overlap": 100
}
}| Parameter | Applies To | Default | Description |
|---|---|---|---|
type | All | "semantic" | Chunking strategy type |
chunk_size | fixed_size, recursive | 1000 | Maximum chunk size in characters |
chunk_overlap | fixed_size, recursive | 200 | Overlap between consecutive chunks in characters |
parent_chunk_size | hierarchical | 2000 | Size of parent chunks in characters |
child_chunk_size | hierarchical | 500 | Size of child chunks in characters |
child_chunk_overlap | hierarchical | 100 | Overlap between child chunks in characters |
Choosing a Strategy
- Start with semantic chunking. It works well for most document types without tuning.
- Use fixed size when you need uniform chunks and your documents lack clear structural markers.
- Use recursive when documents have well-defined paragraph and section structure.
- Use hierarchical when retrieval precision matters and you need the model to have broader context around the matched passage.
Related
- RAG Overview — end-to-end RAG pipeline
- Hybrid Search — how chunks are searched and ranked
- Knowledge Bases API — create and configure Knowledge Bases