semantica.split breaks documents into chunks that preserve semantic context:
  • Six chunking strategies: recursive, semantic, entity-aware, relation-aware, sliding window, structural
  • SemanticChunker uses embedding-based topic-shift detection to split only when content changes
  • EntityAwareChunker keeps entity mentions intact across chunk boundaries
  • RelationAwareChunker keeps 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
Semantica’s chunking methods are designed to avoid these failure modes.

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), then entity_aware for 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?paragraph or sentence
  • Fast splitting with no NLP overhead?recursive or character

TextSplitter Constructor

chunk_overlap too small. Without overlap, a fact that spans a chunk boundary is invisible in both chunks. A 10–20% overlap relative to chunk_size is a safe minimum: for chunk_size=1000, set chunk_overlap=100 to 200.

Splitting Method Details

Tries paragraph breaks first, then sentence boundaries, then word boundaries: falling back only when the chunk exceeds chunk_size:
Key behaviours:
  • 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

Metadata keys vary by method. Only keys that are actually set by the implementation are listed.

Tokenizer Options

The token 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.
Wrong tokenizer. The token method passes the tokenizer= value to tiktoken.encoding_for_model(). If the model name is not recognised by tiktoken it silently falls back to cl100k_base. Pass a valid tiktoken model name (e.g. "gpt-4", "gpt-3.5-turbo") to get deterministic behaviour.

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:
For the full pipeline orchestration API, see the Pipeline reference.
  • 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.