Sub topic 2
Why we chunk: retrieval precision, recall, and noise
This chapter assumes you know what an embedding is, how vector similarity search ranks results, and the retrieve-then-generate idea behind RAG. It also assumes basic Python. It explains why documents are split at all, and what goes wrong when the splits are too big or too small.
One vector per unit
A vector index stores one embedding per indexed unit and returns the units closest to the query embedding. The unit is the smallest thing you can retrieve. If you index whole documents, the smallest thing you can retrieve is a whole document.
An embedding is a fixed-length summary of everything in its input. A 40-page manual about billing, shipping, and password resets produces a single vector that blends all three topics. A query about refunds then matches that blend only weakly, even though the answer is in there.
Precision, recall, and noise
Two retrieval measures explain most chunking trade-offs.
- Precision is the share of retrieved chunks that are actually relevant.
- Recall is the share of all relevant material that was retrieved.
Noise is retrieved text that does not help answer the question. Noise lowers precision. It also costs tokens and can distract the model during generation.
The two measures pull in opposite directions as chunks change size.
| Chunk size | Retrieval effect | Generation effect |
|---|---|---|
| Too large | Vector is diluted, so relevant passages rank lower. Each hit carries a lot of noise. | Context budget fills with irrelevant text. The answer can be buried. |
| Too small | Each chunk is precise, but the facts needed for one answer are spread over several chunks. Recall suffers. | The model sees fragments without the setup, such as a pronoun with no antecedent. |
| Well matched | Each chunk covers roughly one idea that a question could target. | The model gets a self-contained passage. |
Dilution, shown in code
The sketch below uses word-count vectors instead of a real embedding model, so it runs with the standard library only. Real embeddings are subtler, but the dilution effect is the same in kind.
import math
from collections import Counter
def cosine(a, b):
ca, cb = Counter(a.lower().split()), Counter(b.lower().split())
dot = sum(ca[w] * cb[w] for w in ca)
na = math.sqrt(sum(v * v for v in ca.values()))
nb = math.sqrt(sum(v * v for v in cb.values()))
return dot / (na * nb)
query = "refund window days"
small = "refund window is 30 days"
other = ("shipping uses ground carriers passwords reset by email "
"invoices arrive monthly support opens weekdays")
large = small + " " + other
print(round(cosine(query, small), 3)) # 0.775
print(round(cosine(query, large), 3)) # 0.397Both texts contain the answer. The large one scores about half as high because the unrelated words share its vector.
The cost of splitting
Splitting also creates problems.
- Lost context. A chunk that says "It expires after 30 days" does not say what "it" is. The embedding of that chunk is vague, and the model may misread it.
- Cut answers. If a boundary falls in the middle of an explanation, neither half matches the question well. Later chapters cover overlap and boundary-aware splitting as remedies.
- Scattered evidence. Some questions need two facts from different places. Smaller chunks make it more likely that one of them falls outside the top results.
The goal is not the smallest chunk. It is the smallest chunk that still stands on its own.
Noise reaches the generator
Retrieval usually returns a fixed number of results, called top-k. With oversized chunks, each result brings along unrelated text. With 5 chunks of 1,000 words each, the model must read 5,000 words to use perhaps 100 relevant ones.
This has three effects. It uses up the context budget. It adds cost and latency. It also gives the model more chances to latch onto a similar but wrong passage. Good chunking raises the share of the context that actually bears on the question.
What to take forward
- Retrieval returns whole chunks, so chunk content decides what can be found.
- Large chunks lower precision through vector dilution and noise.
- Small chunks lower recall and strip away context.
- The right size depends on the questions you expect, which is why later chapters tie size to token limits and to measured recall@k.
Exercise
A corpus of support articles is indexed with one chunk per article, each about 3,000 words. Users ask short questions, and the right article is often retrieved, but answers are vague or wrong. Name two likely causes related to chunking, and say what direction you would change chunk size to test.
Show answer
Likely causes: (1) Each article embeds as a blend of many sub-topics, so the specific passage is hard for the model to find in a long context and may rank below less relevant articles. (2) The large retrieved chunks fill the context with noise, so the model may use a nearby but wrong passage. Test smaller chunks, for example a few hundred words that each cover one idea. Compare recall@k before and after, and watch that chunks do not become so small that they lose their context.