RAG & Knowledge Systems Engineering · Module 04 of 18
Foundation

Chunking Made Understandable

Learn why chunking exists, how chunk size and overlap change retrieval, and how structure-aware chunking preserves context.

Engineering focus: Split knowledge without losing meaning

In plain English

What problem are we solving?

Learn why chunking exists, how chunk size and overlap change retrieval, and how structure-aware chunking preserves context.

You are not expected to know the engineering vocabulary before using the idea. Formal terminology comes after the mental model.

Running case · Evidence Desk

Improve the same system, module by module.

Carry one evidence-grounded knowledge assistant through all 18 modules. Preserve source IDs, retrieval evidence, evaluation cases, authority decisions and security assumptions so every improvement is measurable.

Mental model

Understand it before you optimize it.

Chunking is like cutting a manual into index cards. Cards that are too small lose meaning; cards that are too large bury the useful sentence.

01Document structure
02Chunk boundaries
03Overlap where justified
04Stable chunk IDs
05Evaluate retrieval
Remember

There is no universal chunk size; choose it from document structure and evaluation.

Learning objectives

By the end of this module, you should be able to:

  • Explain chunk size and overlap trade-offs.
  • Compare fixed, sentence-aware and structure-aware chunking.
  • Evaluate whether a chunk preserves enough context to answer a question.

Why chunk at all?

Long documents are difficult to search and expensive to place into model context. Chunking creates smaller retrieval units.

Smaller is not always better

Very small chunks can lose meaning; very large chunks can dilute relevance and waste context.

Use document structure

Headings, sections, paragraphs and tables often provide better boundaries than arbitrary character counts.

Measure chunking empirically

The best strategy depends on question style, source structure and retrieval model. Use evaluation questions rather than intuition alone.

Engineering depth

Engineering deep dive

  • Compare fixed, recursive, sentence/paragraph and structure-aware strategies.
  • Use stable chunk IDs derived from source + location so evaluation survives re-indexing.
  • Measure duplicate rate and boundary failures alongside Recall@k.
  • Handle tables, code blocks and headings as structured content when they carry meaning.
Worked examples

Mental model

Module 04: Split knowledge without losing meaning
  • Learn why chunking exists, how chunk size and overlap change retrieval, and how structure-aware chunking preserves context.

A boundary failure

BAD
[Restart only after health]
[checks fail twice on port 8080]

BETTER
# Recovery
Restart only after health checks fail twice.

# Network
The API listens on port 8080.
  • Structure-aware boundaries preserve local meaning.
  • The better chunk may improve retrieval without increasing overlap.
Diagnostic lens

If this goes wrong, where do you look first?

Symptom

The right document is found but the useful sentence is missing or split.

Likely causes

  • Chunk too small
  • Boundary ignores headings/tables
  • Overlap creates noisy duplicates

First checks

  • Print neighbouring chunks
  • Compare chunk IDs with source structure
  • Run the same eval with another chunking policy
Engineering principle

Treat chunking as an evaluated retrieval parameter.

Try it · core lab · account-free

Lab 04 — Chunking Made Understandable

Goal: Compare fixed-size and paragraph-aware chunks on the same short runbook.

Before you start

  • Core lab requires only Python 3 and local files unless otherwise stated.
  • Running case: build the same evidence-grounded knowledge assistant across the course.
  • Keep source IDs and intermediate evidence so each result is inspectable.
  • Reflection: Write one sentence describing what this step proves and one sentence describing what it does not prove.
STEP 1

Run the baseline

python3 - <<'PY2'
text='''# API\nThe API listens on 8080.\n\n# Recovery\nRestart only after health checks fail twice.'''
fixed=[text[i:i+35] for i in range(0,len(text),35)]
paras=[p for p in text.split('\n\n') if p.strip()]
print('fixed=',fixed); print('paragraph=',paras)
PY2
STEP 2

Inspect the evidence

Record the intermediate source IDs, ranks, metadata or state produced by the baseline. Explain which pipeline layer this evidence belongs to.

STEP 3

Create a bad boundary

Reduce the fixed chunk size until a key sentence is split. Compare the broken chunk to the paragraph-aware result and note which query would fail.

STEP 4

Diagnose and restore

Treat chunking as an evaluated retrieval parameter. State the failing layer, change only that layer, then repeat the verification checks.

STEP 5

Write the engineering note

Record: hypothesis → evidence → change → observed result → remaining limitation. Keep this note with the running Evidence Desk project.

Verify

  • You can see how arbitrary boundaries may split a fact from its heading.
  • You can justify a chunking choice using expected queries.
  • The baseline and the deliberately broken case produce different, explainable evidence.
  • You can name the pipeline layer that owns the failure and the control that repairs it.

Expected outcome

  • A reproducible local result plus a short evidence note.
  • A short before/after record showing the failure, diagnosis and repaired state.

Break / fix · diagnose

  • Inspect the intermediate evidence before changing the model or prompt.
  • If a command fails, preserve the error and classify which pipeline layer failed.
  • Change one pipeline variable at a time and rerun the same test case.
  • Do not accept a plausible answer as proof; verify the intermediate evidence and source identity.
Production view

Production RAG improves when every change can be traced to evidence at a specific pipeline layer. In production, retain the before/after evidence so the same failure can become a regression test.

Production checklist

What would an engineer verify before shipping this layer?

Gate 1

Chunk strategy documented

Gate 2

Stable chunk IDs present

Gate 3

Chunking compared on labelled queries

Avoid these traps

Common beginner and engineering mistakes

  • Using one universal chunk size for every corpus.
  • Adding large overlap without measuring duplication.
  • Ignoring headings and table boundaries.
Knowledge check

Can you explain the idea and diagnose the system?

1Why can tiny chunks hurt retrieval?

They may remove surrounding context needed to interpret the fact.

2Why can huge chunks hurt?

They dilute relevance and consume more context.

3What is overlap for?

To preserve continuity across chunk boundaries, but too much creates duplication.

4How should chunking be chosen?

By evaluating retrieval performance on representative questions.

My Learning

Record your progress for this module.

Progress is saved in this browser immediately. When you sign in to My Learning, it can also sync across devices.

Not started

Attempt the core lab and knowledge checks before marking the module complete.