The docs have the answer, but RAG misses it. Check the chunks?
Question
A shop's support bot says an opened laptop can be returned within 30 days. The returns page says 15:
"Most items can be returned within 30 days of delivery. Opened electronics, such as laptops and phones, can be returned within 15 days only. Sale items cannot be returned."
The page has 29 words. It is indexed in chunks of 16 words with no overlap. For the question "Can I return an opened laptop?", search returns chunk 1 and not chunk 2.
- Why does the bot say 30 days?
- Name two ways to change the chunking, and what each one costs.
Show hints (3)
- "WRITE THE CHUNKS"
Count 16 words from the start. Where does chunk 1 end? What does each chunk say on its own?
- "READ ONE CHUNK ALONE"
Chunk 1 talks about laptops. Which number of days does it contain? Chunk 2 has the 15 days. Does it say what they apply to?
- "TWO FIXES"
Cut at sentence ends instead of every 16 words. Or let each chunk repeat the last 8 words of the one before.
Show checked explanation
The rule is cut in half. Chunk 1 ends at "laptops and", so it holds "laptops" next to "30 days". The "15 days" is in chunk 2, which never says it is about electronics. Split at sentence or section ends, or overlap the chunks, which means more chunks to store.
policy = ("Most items can be returned within 30 days of delivery. " "Opened electronics, such as laptops and phones, can be " "returned within 15 days only. Sale items cannot be returned.") words = policy.split() def chunk(words, size, overlap): step = size - overlap starts = range(0, max(len(words) - overlap, 1), step) return [(i, words[i:i + size]) for i in starts] for overlap in (0, 8): chunks = chunk(words, size=16, overlap=overlap) print(f"size 16, overlap {overlap}: {len(chunks)} chunks") for start, piece in chunks: text = " ".join(piece) whole = "laptops" in text and "15 days" in text print(f" words {start + 1}-{start + len(piece)}:", "whole rule" if whole else "-")
size 16, overlap 0: 2 chunks words 1-16: - words 17-29: - size 16, overlap 8: 3 chunks words 1-16: - words 9-24: whole rule words 17-29: -
Code run on CPython 3.12 against the example above. Checked by an editor other than the author.
Walkthrough
The two chunks with no overlap:
| chunk | text |
|---|---|
| 1 (words 1–16) | Most items can be returned within 30 days of delivery. Opened electronics, such as laptops and |
| 2 (words 17–29) | phones, can be returned within 15 days only. Sale items cannot be returned. |
Chunk 1 contains "opened", "laptops" and "returned", so search ranks it first. The only number of days in it is 30. Chunk 2 holds the real answer, but it starts at "phones," and never says "electronics". Alone, it doesn't say what the 15 days apply to. The model answered correctly from what it got. The bug is in the index.
Fix 1: cut along the text. Split at headings and paragraphs, then pack whole sentences up to the size limit. The electronics sentence has 14 words, so it fits in one chunk. You need a parser for each format: HTML, PDF, tables.
Fix 2: overlap. Each chunk repeats the last 8 words of the one before, so a new chunk starts every 8 words. Chunk words 9–24 now holds the whole rule. The cost is more chunks: 3 instead of 2 here. On a long page, overlap 8 on size 16 doubles the chunks to embed and store. Near-copies of the same text can also fill several of the top-k places.
Also add context. Put the page title and heading at the top of each chunk, like "Returns policy > Electronics". Then a chunk that starts mid-sentence still says what it is about.
Common mistakes
- Changing the prompt to "read the sources carefully". The model never saw "15 days" next to "laptops", so no instruction can fix it.
- Making each chunk a whole page. One vector then mixes many topics, matches every question a little, and fills the context faster.
- Trusting overlap to keep every rule whole. Overlap 8 only guarantees passages of up to 9 words. The 14-word rule fit here because of where it starts.
- Splitting a table into rows without its header row. A row like
Laptops | 15no longer says that 15 means days.
Follow-up questions
- "How do you find split answers across thousands of pages?" Mark the sentence that answers each test question. If no single chunk holds it, chunking is the bug. If a chunk holds it but is not in the top k, search is the bug.
- "What chunk size would you start with?" Start from the document's structure: a section or a few paragraphs, often a few hundred tokens. Test two or three sizes on real questions and keep the one with the best recall at k.
What a strong answer covers
Reads the chunks the model got and finds the rule cut in half. Splits along sentences and sections, or overlaps, and names the cost. Adds the heading to each chunk and tests chunking on real questions.
Open in interactive practice deck →