RAG CHUNKING

The bot quoted the right table and gave the wrong fee

L215 MINAI SYSTEMS
PREDICT

Owoleaf's support assistant splits its 'Fees and limits' help-centre page every 45 words, with 10 words of overlap, and sends the 2 chunks that best match the question's words. A customer asks: 'What is the fee to send ₦60,000 to a bank account?' What does the bot's context contain?

A RAG system answers from chunks, not pages. A chunk is the smallest thing retrieval can return, so a fact cut in two can only come back in halves. Fixed-size chunking cuts every N words or tokens wherever that falls: between a table’s header and its rows, between a rule and its “except”.

The retriever ranks each chunk by how well it matches the question. The half with the question’s words wins. The half with the answer often has none of them. The bot then answers from what it was given, and the answer cites a real chunk.

▶ SIMULATION
OWOLEAF HELP CENTRE · not chunked yet
—
✓ every fact the answer needs is in the context sent✓ context per question ≤ 120 words
SCHEDULE
01[INGEST]INGEST: split the page every CHUNK SIZE words
02[BOT]BOT: "What is the fee to send ₦60,000 to a bank account?"
03[BOT]BOT: "How long does a refund take on my foreign card?"
Start of fixed size scenario. 3 steps.
# 30 words a chunk, wherever that falls
words = page.split()
chunks = [' '.join(words[i:i+30]) for i in range(0, len(words), 30)]

Watch the first invariant. In FIXED SIZE it turns red on the first question: the context supports ₦25, and the right answer is ₦50. The second question gets the 5-day rule without its exception for cards issued outside Nigeria. FIXED SIZE, LUCKY gets both right with one setting. BIG CHUNKS gets both facts in at 178 words a question and breaks the budget. STRUCTURE-AWARE keeps the table whole under its heading path, and PARENT DOCUMENT matches single sentences and rows, then sends their whole section. Both stay green at 88 words or less.

What is simplified: the retriever counts shared words, weighted by how rare each word is, where production uses embeddings or a hybrid, often searched through an approximate index that can lose recall of its own (HNSW recall). Chunks are counted in words, not tokens; tokenisation shows why the two differ. “Context supports” reads only the chunks the bot was sent; there is no model. Embeddings do not fix this case: they do not compare amounts either. The fees, limits and refund times are illustrative.

TUNE IT NOT YET

Keep fixed-size chunking. Find a CHUNK SIZE and OVERLAP at which both answers are grounded and neither question sends more than 120 words of context. Note how many settings around yours fail.

GOAL: both answers grounded, ≤ 120 words each

BREAK IT NOT YET

This is the lucky setting: 45 words, overlap 5, both answers grounded. Insert one edit to the help-centre page so that the bot gives at least one ungrounded answer. You may not touch the chunker.

GOAL: at least one answer ungrounded

FIX IT NOT YET

Write chunkTable(path, header, rows, maxRows) for a table too big for one chunk. path is the heading path (a string), header the header line, rows an array of row lines. Return an array of chunks, each a string of lines joined with \n. Rules the grader checks: every chunk contains the path line and the header line; every row appears, unchanged, in exactly one chunk; every chunk has between 1 and maxRows rows. No rows: return [].

The trade-off on size is real. Small chunks match precisely and leave room for more of them; big chunks keep facts whole and cost context. Parent-document retrieval separates the two: match small, send big. The RAG done properly chapter builds a structural chunker with heading paths, measures recall at k next to the characters delivered, and adds hybrid search and reranking. For a page this small you could send the whole page; the long context vs retrieval chapter measures when that beats retrieval.

Mental model:

The unit of retrieval is the unit of failure. If a fact needs two lines, those lines must arrive together, or the bot gets the half with the question’s words in it and answers from that. Split on the structure the author wrote: whole paragraphs, whole tables, and when a table must be split, the header and heading path repeated in every piece. Judge any chunker by recall and the words it sends, side by side.

IN PRODUCTION

Document Q&A and support bots over help centres, policies, contracts, price lists and spec sheets: anything with tables, numbered conditions or 'except' clauses. Symptoms: confident answers with a valid citation that are off by one row or miss an exception, and a recall score that rises only when the chunks get bigger. See the RAG done properly chapter for the full pipeline.

IN INTERVIEWS

“Our RAG bot gives wrong answers with correct citations. How do you debug it?” Look at the retrieved chunks for the failing questions before touching the prompt. Name the boundary problem (tables and exceptions split), then the fixes in order: structure-aware chunking with heading paths, header rows repeated when a table is split, parent-document retrieval, then overlap as a cheap patch. Say how you would prove it: recall at k on a question set, reported with the tokens delivered so bigger chunks cannot win for free.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.

USED IN

Chapters that build on this lesson.

NEXT: HNSW RECALL →