Course contentsShow
← AI Engineering
Lesson 346 of 1,8869. Retrieval-Augmented Generation (RAG) - BasicsFree lesson

Parent-Child Chunk Relationships

Creating hierarchical chunks where small chunks retrieve but larger parent chunks provide context.

Parent-Child Chunk Relationships

What you'll learn: How to retrieve small, precise chunks while providing the LLM with larger, more contextual parent chunks for better answers.

The Core Idea

Imagine searching a cookbook for "caramelizing onions." You want to find the exact step (the child chunk), but when you cook, you need the full recipe context (the parent chunk) — ingredients, prior steps, cooking temperature.

Parent-child chunk relationships work the same way: you store and search small, focused chunks because they're precise for retrieval, but when you send context to the LLM, you provide the larger parent chunk they came from.

How It Works

When chunking your documents, you create two layers:

  1. Child chunks: Small, specific segments (maybe 100-200 tokens) that get embedded and indexed in your vector database
  2. Parent chunks: Larger sections (500-1000+ tokens) that contain one or more child chunks

During retrieval:

  • The user's query searches against child chunk embeddings
  • When a child chunk matches, you retrieve its parent chunk instead
  • The parent chunk goes into the LLM's context window

This gives you the best of both worlds: precise semantic search from small chunks, but rich context from larger chunks.

Why This Matters

Small chunks might say "the capital is Paris" without mentioning which country. The parent chunk contains "France's geography and government... the capital is Paris" — much more useful context for the LLM to generate accurate answers.

You store the parent-child relationship as metadata during chunking (like parent_id or parent_text fields).

Key Takeaway: Parent-child chunk relationships let you search with precision using small chunks, but provide context with completeness using their larger parent chunks — solving the chunk size dilemma in RAG systems.