Skip to content

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.

SIZE 6 · OVERLAP 2
Words shared with the neighbouring chunk (the overlap)Tiles: words of the document; cards: the chunks that get embeddedWindow: one chunk, 6 words wide, moved 4 at a timeRetrieval never sees the whole document, only chunks. Cut too small and a chunk loses its context; cut too large and the one sentence that matters is diluted. A little overlap means an idea split at a boundary still appears whole in one chunk. Sizes here are illustrative: real chunks run 200–1,000 tokens, ideally split on headings and paragraphs first.

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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).

  5. 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.

  6. 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.

  7. 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.

Chunking tools compared
ToolRatingOur verdictBest forPrice
Doclingrepo4.5/5Docling 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.
LlamaIndexrepo4.3/5Still 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.
LangChainrepo4.2/5Still 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.
Haystackrepo4.2/5A 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.
Unstructuredrepo3.8/5Still 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.
Chonkierepo3.7/5A 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.

Chunking: specifications side by side
ToolStrategiesToken-aware sizingStructure-awareLanguageLicence
DoclingHierarchical, hybrid, line-basedYes (Hugging Face or tiktoken)Full layout; repeats table headersPythonMIT
LlamaIndexSentence, token, semantic, hierarchicalYes (TokenTextSplitter)Markdown, HTML, JSON, codePythonMIT
LangChainRecursive, character, token, codeYes (tiktoken and others)Markdown, HTML, JSON headersPythonMIT
HaystackRecursive, hierarchical, embeddingVia Chonkie token splitterMarkdown headers, Python AST, CSVPythonApache 2.0
Unstructuredbasic, by_titleNo (character limits)Element types, sections, pagesPythonApache 2.0
ChonkieToken, recursive, semantic, late, LLMYesMarkdown recipe, code, tablesPython; REST serverMIT

Where this stage fits

Sources for this guide