Skip to solution
mediumAI Engineering

What chunking strategies exist and how does chunk size affect RAG quality?

615 views
01

Understand the problem

Fixed windows, semantic splits, parent-child chunks — the retrieval decision made at index time.

chunkingragindexing
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Chunking splits documents into retrievable units: fixed-size token windows with overlap (simple baseline), structure-aware splits (headings, paragraphs, code blocks), and parent-child schemes that embed small chunks but return their larger parent for context. Small chunks give precise matching but fragment meaning; lar

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

Structure-aware chunking with context header
def chunk_doc(doc):
    for section in split_by_headings(doc.markdown):        # structure first
        path = " > ".join(section.heading_path)            # "Refunds > EU"
        for piece in window(section.text, tokens=500, overlap=60):
            yield {
                "text": path + ": " + piece,               # self-describing chunk
                "doc_id": doc.id,
                "parent": section.id,                      # return this at answer time
            }
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 36 of 80 decoded in the AI Engineering track. One more won't hurt.

Back to track