Why Chunk Boundaries Matter
See the three jobs a chunk does in retrieval, how fixed-size, recursive and structure-aware splitters place their boundaries, and how size, overlap and a heading header decide what a chunk can answer on its own.
Contentsand lesson path
On this page
- Why it matters
- Three jobs for every chunk
- Three ways to place boundaries
- Size and overlap: the two settings
- Give each chunk its context back
- Check your understanding
- Apply it
- Review prompt
Lessons of Chunking
- Why Chunk Boundaries Matter Concept · 15 min
- Parsing Documents, Scans and Tables into Clean Text Worked example · 20 min
- Lab: Three Chunkers, One Corpus Lab · 25 min
- Stable IDs and Source Metadata Worked example · 15 min
- Measuring Chunking by Retrieval Recall Lab · 20 min
- Check: Choose a Chunking Strategy Knowledge check · 6 questions
What you will learn
- Apply fixed-size, recursive and structure-aware chunking with overlap, and attach a stable ID and source metadata to every chunk.
01. Why it matters
A retrieval system usually does not hand the model whole documents. It hands over chunks: pieces of documents that were cut, embedded and indexed in advance. The chunk is what gets matched against the question, what the model reads and what an answer cites, so the places where you cut decide what can be found at all.
Cut a fact in half and neither half may match the question. Put three topics into one chunk and its vector becomes a blend that sits close to none of them. Separate It stays there for 14 days from its heading and the model receives a number with no subject. No embedding model or prompt can repair this later: the damage was done at ingestion.
This lesson covers what a chunk has to do, the three common ways to place boundaries, the two settings you will tune, and how to give a chunk back the context that cutting removed.
02. Three jobs for every chunk
Every chunk does three jobs, and a good boundary serves all of them:
- A unit of matching. One chunk gets one vector, so the vector can only be as focused as the chunk. A chunk about one thing lands near questions about that thing; a chunk that mixes installation, pricing and troubleshooting lands somewhere in between.
- A unit of evidence. Retrieved chunks are pasted into the prompt, where every token costs money and attention. A good chunk is self-contained: someone who sees only this chunk can tell what it is about.
- A unit of citation. An answer points back at the chunks it used, so each chunk needs a stable identity and a source. Lesson 4 of this skill is about that.
There is also a hard limit. Every embedding model accepts a maximum input length, for example 512 tokens for the small open model bge-small-en-v1.5. Some libraries silently truncate longer input, so the end of an oversized chunk never reaches its vector; some APIs reject it with an error. Find out which your model does, and keep chunks under the limit as measured by the model's own tokenizer.
The simplest possible chunker cuts every N characters. Run it on three sentences from the documentation of Larkspur, the small job scheduler used throughout this skill, and ask what each piece can still say on its own:
text = (
"After the last retry, the job moves to the dead-letter queue. It stays "
"there for 14 days and is then deleted. Run larkspur dlq replay to run "
"it again."
)
for start in range(0, len(text), 60):
print(repr(text[start:start + 60]))python windows.py'After the last retry, the job moves to the dead-letter queue'
'. It stays there for 14 days and is then deleted. Run larksp'
'ur dlq replay to run it again.'The first piece is fine. The second starts with a stray full stop and says It stays there for 14 days without saying what it is or where there is. The third begins in the middle of a command name, so neither larksp nor ur dlq replay matches someone searching for larkspur dlq replay. A person reading the whole paragraph never notices the boundaries; a retriever sees nothing else.
03. Three ways to place boundaries
Most chunkers you will meet belong to one of three families, or combine them:
- Fixed-size. Cut every N tokens (or characters), usually with some overlap between neighbours. It is simple, predictable and works on any text, which makes it a common baseline. It also ignores meaning: it cuts sentences, numbers, code blocks and table rows wherever the count runs out.
- Recursive. Try the coarsest separator first and go finer only where a piece is still too long: paragraph breaks, then line breaks, then sentence ends, then spaces; then pack the pieces back together up to the size limit. LangChain's widely used
RecursiveCharacterTextSplitterworks this way. Boundaries mostly fall between paragraphs, but the splitter does not know that a heading belongs to the text below it, or that a blank line inside a code block is not a paragraph break. - Structure-aware. Parse the document first, then cut along its own structure: Markdown or HTML headings, code blocks, tables, PDF sections. Each section becomes a chunk, a section that is too long is split again between paragraphs, and code blocks and tables are kept whole. Each chunk can carry its heading path, such as Retries and failures > Dead-letter queue. The price is a parser for every format, and sections that vary a lot in size.
You will also meet semantic chunking, which embeds consecutive sentences and cuts where the meaning shifts. It costs an embedding call per sentence at ingestion, and Pinecone's guide still describes it as experimental, so measure it against a structure-aware baseline before you adopt it.
For documentation and anything else with real headings, a structure-aware splitter with a recursive fallback is a strong default. For text without structure, such as chat transcripts or OCR output, recursive splitting is the usual start. The lab in this skill builds all three.
04. Size and overlap: the two settings
Chunk size trades precision for context. Small chunks (around 100 to 250 tokens) match narrow questions precisely but carry little context, so a question that needs two facts may need several of them. Large chunks (500 to 1,000 tokens) carry more context but blend topics and spend more of the prompt on every hit. Pinecone's guide suggests testing a small setting such as 256 tokens against a large one such as 1,024 on real queries. Start with a few hundred tokens, then measure, as lesson 5 shows.
Measure size in tokens of your embedding model's tokenizer, not in characters. The model limit and your context budget are both counted in tokens, and the number of characters per token differs between English prose, other languages, code and tables.
Overlap repeats the end of each chunk at the start of the next, often 10 to 20 percent of the size. It matters most for fixed-size splitting, whose boundaries fall anywhere. It costs more chunks to embed and store, and near-duplicate neighbours that can both be retrieved and repeat the same sentences in the context. Structure-aware boundaries already fall between sections, so they need little or no overlap.
A related technique separates what you match from what you send: index small chunks for precise matching, then give the model the surrounding section (parent-document or small-to-big retrieval). It needs each chunk's document and position, which lesson 4 records.
05. Give each chunk its context back
Even a perfect boundary removes context. It stays there for 14 days and is then deleted is a well-cut sentence and still useless on its own. The cheapest fix is a contextual chunk header: before embedding, put the document title and heading path in front of the chunk, and keep the plain chunk text and its metadata for display and citation.
Embedded and indexed:
[Larkspur docs > Retries and failures > Dead-letter queue]
## Dead-letter queue
After the last retry, the job moves to the dead-letter queue. It stays there
for 14 days and is then deleted. ...
Stored with the vector:
the chunk text without the header, its document, heading path and offsetsAnthropic's contextual retrieval goes further: a language model reads the whole document and writes 50 to 100 tokens of chunk-specific context, prepended before embedding and before building the keyword (BM25) index. On Anthropic's test sets the top-20 retrieval failure rate fell from 5.7% to 3.7% with contextual embeddings, and to 2.9% with contextual BM25 added. It costs a model call per chunk at ingestion, so start with heading-path headers, which are free, and measure whether generated context pays for itself.
06. Check your understanding
07. Apply it
Start the practice project for this skill. Choose a documentation set that you are allowed to copy and process: the Markdown docs of an open-source project are ideal, but read the licence first (look for a LICENSE file in the repository or its docs folder; documentation is often under the project's code licence or CC BY 4.0). Clone it and pick three pages of different shapes, such as a tutorial, a reference page with tables and a page with long code samples. For each page:
- Count the tokens of every section with tiktoken, as in the Tokens and Context skill, and note the longest section and any code block or table over 300 tokens.
- Find two places where a fixed 300-token window would cut a sentence, a code block or a table, and one section whose text makes no sense without its heading.
- Write five questions that these pages answer, and next to each paste the exact sentence or lines that answer it, with the file path. In lesson 5 these become labelled evidence spans, and you will grow the set to fifteen.
08. Review prompt
Without looking back, answer in your own words:
- What are the three jobs of a chunk, and how does an oversized chunk fail at each of them?
- How does each splitter family decide where to cut, and what is one typical failure of each?
- What does overlap buy, what does it cost, and why do structure-aware chunks need less of it?
- What goes into a contextual chunk header, and which text do you embed and which do you store for citation?
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.