What is chunking?
Chunking is splitting documents into meaningful, suitably sized pieces before indexing, balancing retrieval accuracy against keeping context intact.
It differs from semantic chunking in scope: semantic chunking splits by similarity of meaning, while chunking is the general term that also covers fixed-size splits and splits by heading or paragraph. Chunks that are too large hurt retrieval accuracy; chunks that are too small lose context.
- Topic
- Embeddings, document processing and RAG
- Also known as
- Document chunking, text splitting
How chunking works
- The document is parsed and structural boundaries such as headings, paragraphs, tables and lists are found.
- A splitting rule is chosen: fixed token count, structural boundaries, recursive splitting or semantic similarity.
- Overlap can be kept between consecutive chunks to preserve sentences split at a boundary; each chunk gets source, heading and permission metadata.
- Each chunk is embedded separately and written to the search index.
In more detail
Parent-child (hierarchical) chunking
Modern RAG pipelines often decouple the unit used for search from the unit sent to the language model. Small child chunks (e.g., 150 to 250 tokens) yield sharper vector matches, while retrieving their larger parent section or surrounding window supplies the LLM with coherent reasoning context.
Context-preserving approaches: contextual retrieval and late chunking
Embedding chunks in isolation strips away document-level context such as pronouns, product names or effective dates. Contextual retrieval prepends a brief section summary before indexing, whereas late chunking encodes the entire document with a long-context embedding model before pooling token embeddings per chunk.
Embedding model token limits and silent truncation
Every embedding model enforces a strict maximum input token limit (commonly 512 to 8,192 tokens). If a chunk exceeds that limit, the service may reject the input or truncate it, depending on the implementation, potentially leaving trailing text unindexed; chunk sizes must stay safely below the embedding model's ceiling.
Layout-aware chunking for tables and code
Corporate documents rarely consist of plain prose; multi-column PDFs, nested tables, diagrams and source code break under naive character or token splitting. Layout-aware parsing keeps tables intact (often as Markdown or HTML with repeated headers) and indexes figure captions alongside surrounding text.
Commonly confused terms
| Term | How it differs |
|---|---|
| Document parsing | Document parsing extracts raw text, reading order, tables, headings and layout elements from file formats (PDF, DOCX, HTML) before chunking. Chunking then segments that parsed representation into retrieval units. |
| Tokenisation | Tokenisation converts text into subword/word units (tokens) used by embedding models and LLMs to measure length and process input. Chunking groups hundreds of tokens into coherent retrieval passages; token count is merely one way to measure chunk size. |
Why chunking matters for on-premises AI
Chunk size sets both retrieval accuracy and the cost of context sent to the language model; large chunks carry more tokens per request. Splitting tables, clause numbers or headings loses meaning, so structure-aware chunking often works better for organisational documents. Each chunk carrying its source document and permissions is needed for citation and permission-aware retrieval. Changing the chunking rule means rebuilding the index; settings are chosen by measuring on the organisation's question set.
A hospital splits clinical guidelines by heading before adding them to its in-house search index; each chunk covers one clinical topic and carries the guideline name and version.
Common questions
What is the ideal chunk size?
There is no single right value. It depends on document type, questions and the embedding model's limit; several sizes are tested on the organisation's own questions.
Why keep overlap between chunks?
A sentence or idea split across a boundary can lose meaning. Overlap preserves that context but increases index size and duplicated content.
Related terms
- Semantic chunking
- Chunk size
- Chunk overlap
- Recursive chunking
- Document ingestion
- Fixed-size chunking
- Embedding
- Retrieval-Augmented Generation
Sources
- Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, NeurIPS 2020
- Gao et al., Retrieval-Augmented Generation for Large Language Models: A Survey, 2023
Related page on this site: Related FAQ · In the glossary: Glossary, A to C