Step 03 of 22
Chunking
Split documents into passages small enough to embed and retrieve. Chunks that cut a table or a definition in half return half an answer. Chunking sets the unit the model actually sees.
How to choose
- Start with structure-aware splitting (by heading or section) before anything clever.
- Keep a little overlap and attach the document title and section to every chunk.
- Measure retrieval before and after a change; chunk size is a setting to test, not a belief.
What to look for
The questions that separate the options, in order of how much they matter.
01
Structure-aware splitting first
Splitting on headings, sections and list boundaries keeps a definition or a procedure in one piece. This needs structure from the parser, so chunkers that read a parsed document (Docling's HybridChunker, Unstructured's by_title, Markdown header splitters) usually beat splitting raw text. Start here before trying anything clever.
02
Size measured in your embedding model's tokens
Embedding models truncate input beyond their token limit, often silently, so chunk limits should be counted with the same tokenizer the model uses. Character-based limits (Unstructured's max_characters, LangChain's default splitter) only approximate this. Docling's HybridChunker and the token splitters in LangChain, LlamaIndex and Chonkie take a tokenizer directly.
03
Context carried with every chunk
A chunk that says 'the limit is 30 days' is useless without knowing which policy it belongs to. Prefer chunkers that attach the document title, heading path and captions as metadata or prepend them to the text before embedding. A small overlap helps when a sentence straddles a boundary, but it is no substitute for headings.
04
Tables and code handled as units
Generic text splitters cut tables mid-row and functions mid-body. Look for table-aware options, such as Docling repeating a table's header row in each piece or Unstructured isolating tables in their own chunks, and code splitters that follow syntax (LangChain, LlamaIndex, Haystack's Python AST splitter).
05
Be sceptical of semantic chunking
Semantic chunkers split where embedding similarity between sentences drops. A 2024 study by Vectara researchers found the extra compute did not bring consistent gains over fixed-size chunks, and an August 2026 study of eight strategies found the best method changed with the embedding model, dataset and metric. Try it only after measuring a simple baseline. There is no public leaderboard for chunkers; anything you read is a single study or a vendor chart.
06
Measure retrieval, not chunk aesthetics
Build a small test set of real questions with the passages that answer them, then compare recall at k (how often the right passage is in the top k results) for each chunking setting. Chunk size is a parameter to test, not a belief. Re-run the test whenever you change the parser or embedding model.
07
Maintenance and where the code lives
Chunking code is small, so the risk is abandonment rather than bugs. LangChain archived its langchain-experimental package in May 2026, which is where its SemanticChunker lived, and a request to move it into the main splitters package was closed as not planned. Prefer chunkers inside a library you already depend on, or pin versions.
How the options differ
Most teams do not need a separate chunking library. Framework splitters (LangChain's text splitters, LlamaIndex's node parsers, Haystack's preprocessors) cover recursive, token, header-based and code splitting, and are the sensible default if you already use that framework. Parser-native chunkers (Docling's HybridChunker, Unstructured's basic and by_title strategies) have an advantage: they see the document's real structure, so they can keep sections, tables and captions together.
Dedicated libraries such as Chonkie offer the widest menu, from token and sentence splitting to semantic, late and LLM-driven chunking, in a light install, which helps if you want to test strategies without switching frameworks. Late chunking embeds the whole document first and then pools token vectors per chunk, so each chunk's vector carries surrounding context; it needs a long-context embedding model that exposes token-level outputs.
6 tools, compared
Ranked by our rating. Open any review for sources, prices and the full verdict.
| Tool | Rating | Our verdict | Best for | Price |
|---|---|---|---|---|
| Doclingrepo | 4.5/5 | Docling is the open-source parser that gets tables right, and the one whose security releases you cannot afford to skip. | Teams building self-hosted RAG over PDFs and Office documents with complex tables. | Free and open source under the MIT license. |
| LlamaIndexrepo | 4.3/5 | Still a deep toolkit for document-heavy RAG, but its maker now says plainly that the framework is no longer its priority. | Python developers building RAG or document agents over large, varied data sources. | Framework free under MIT. LlamaParse (paid cloud): Free with 10k credits, Starter $50/month (40k credits), Pro $500/month (400k credits), Enterprise custom; 1,000 credits = $1.25. |
| LangChainrepo | 4.2/5 | Still the widest integration library for LLM apps, much tidier since 1.0, and no longer the automatic default it once was. | Teams building agents that need many provider and data integrations and may grow into custom LangGraph workflows. | Free and open source under the MIT licence. LangSmith is separate: Developer free for one seat, Plus $39/seat/month, Enterprise custom. |
| Haystackrepo | 4.2/5 | A framework for people who want to read their RAG system rather than trust it, at the price of writing more of the wiring themselves. | Engineering teams building maintainable production RAG and agent pipelines in Python. | Free and open source under the Apache 2.0 licence. deepset Studio is free for one user; the Haystack Enterprise Platform is custom-priced. |
| Unstructuredrepo | 3.8/5 | Still the widest net for odd file formats, but its makers now publish the numbers showing why you would pay them instead. | Teams building ETL pipelines that ingest many document formats for RAG. | Library free under Apache 2.0. Hosted platform: 10,000 free pages, then $0.015 a page; Business plan with VPC or dedicated deployment priced on request. |
| Chonkierepo | 3.7/5 | A tidy chunking library mid-rewrite: v1.7 works today, but most of what makes it distinctive is scheduled for removal in v2. | Teams that need a light recursive or code chunking step and can accept a v2 migration soon. | Free and open source under the MIT licence. |
Side by side
The specifications that matter for this step. Checked 2026-10-19; confirm on the vendor’s site before you commit.
| Tool | Strategies | Token-aware sizing | Structure-aware | Language | Licence |
|---|---|---|---|---|---|
| Docling | Hierarchical, hybrid, line-based | Yes (Hugging Face or tiktoken) | Full layout; repeats table headers | Python | MIT |
| LlamaIndex | Sentence, token, semantic, hierarchical | Yes (TokenTextSplitter) | Markdown, HTML, JSON, code | Python | MIT |
| LangChain | Recursive, character, token, code | Yes (tiktoken and others) | Markdown, HTML, JSON headers | Python | MIT |
| Haystack | Recursive, hierarchical, embedding | Via Chonkie token splitter | Markdown headers, Python AST, CSV | Python | Apache 2.0 |
| Unstructured | basic, by_title | No (character limits) | Element types, sections, pages | Python | Apache 2.0 |
| Chonkie | Token, recursive, semantic, late, LLM | Yes | Markdown recipe, code, tables | Python; REST server | MIT |
Where this stage fits
- Chat with your documents: we would start with Chonkie.
- Customer support agent: we would start with Chonkie.
- Coding agent: we would start with LlamaIndex.
- Research & knowledge graph: we would start with Chonkie.
- Assistant with long-term memory: we would start with Chonkie.
- Voice agent: we would start with Chonkie.
- Private, on-device AI: we would start with Chonkie.
- Your own fine-tuned model: we would start with Chonkie.
Sources for this guide
- LangChain text splitters
- Sunsetting langchain-experimental (GitHub issue #87)
- LlamaIndex node parser modules
- Docling chunking concepts
- Unstructured chunking
- Haystack preprocessors
- feyninc/chonkie on GitHub
- Is Semantic Chunking Worth the Computational Cost? (arXiv)
- Chunking strategies study, August 2026 (arXiv)
- Late Chunking (Jina AI, arXiv)