semantica.split breaks documents into chunks that preserve semantic context:
- Six chunking strategies: recursive, semantic, entity-aware, relation-aware, sliding window, structural
SemanticChunkeruses embedding-based topic-shift detection to split only when content changesEntityAwareChunkerkeeps entity mentions intact across chunk boundariesRelationAwareChunkerkeeps subject-predicate-object triplets within a single chunk- Chunking quality directly determines downstream embedding accuracy and entity extraction quality
Why Chunking Matters
Most LLMs and embedding models have fixed context windows. Documents larger than that window must be split. But naive splitting (every 500 characters, regardless of structure) destroys semantic context:- An entity mention like “Apple Inc.” split across two chunks loses its context in both
- A relation triplet like “Steve Jobs founded Apple” split at “Steve Jobs” leaves a dangling subject
- Embedding a chunk that mixes two unrelated topics produces a centroid vector that matches neither
Exported Classes
Available
method= values for TextSplitter:
What You Get
- TextSplitter — Unified interface for 11 chunking strategies: swap methods without changing downstream code.
- Semantic Chunking — Embedding-based topic shift detection: splits only when the topic actually changes.
- Entity-Aware Chunking — Entity spans never cross chunk boundaries: guaranteed by boundary adjustment.
- Relation-Aware Chunking — Subject–predicate–object triplets kept within a single chunk for KG pipelines.
- Chunk Object — Output dataclass with text, character offsets, optional id, and method-specific metadata.
Quick Start
1
Choose a splitting method
2
Split raw text
3
Or split a document object
4
Batch-split a list of documents
Splitting Methods
Choosing a Strategy
Use this decision tree before picking a method:- Building a KG? →
relation_aware(keeps triplets intact), thenentity_awarefor pure NER - RAG system where retrieval quality matters most? →
semantic_transformer - Dense overlap for bi-encoder retrieval (ColBERT, DPR)? →
sliding_window - Preparing prompts for a fixed-window LLM? →
token - Structured text with headings? →
structural - Paragraph-level coherence? →
paragraphorsentence - Fast splitting with no NLP overhead? →
recursiveorcharacter
TextSplitter Constructor
Splitting Method Details
- Recursive (default)
- Semantic
- Entity-Aware
- Relation-Aware
- Structural
Tries paragraph breaks first, then sentence boundaries, then word boundaries: falling back only when the chunk exceeds Key behaviours:
chunk_size:- Preserves paragraph and sentence structure wherever possible
- Falls back gracefully: never produces chunks larger than
chunk_size - Overlap ensures context continuity across chunk boundaries
- Good starting point when you’re unsure which method to use
Chunk Schema
Chunk dataclass
Chunk dataclass
Chunk metadata fields
Chunk metadata fields
Metadata keys vary by method. Only keys that are actually set by the implementation are listed.
Tokenizer Options
Thetoken method accepts a tokenizer= kwarg that is passed to tiktoken.encoding_for_model(). The value should be a tiktoken model name. Unrecognised names fall back to cl100k_base automatically.
If
tiktoken is not installed, the token method falls back to splitting by whitespace-separated words.
Pipeline Integration
TextSplitter can be used standalone or composed manually with other Semantica modules. The example below shows a sequential pattern: parse a file, split the text, then extract entities from each chunk:
- Parse — Parse documents before chunking: produces sections and metadata.
- Embeddings — Embed chunks for vector search and semantic chunking.
- Semantic Extract — Extract entities and relations from individual chunks.
- Pipeline — Integrate splitting as a named pipeline step.
