Module 1 of 5 · 45 min

Chunking Strategies & Document Ingestion in Practice

Evaluate fixed-size, recursive character, semantic sentence-window, and hierarchical parent-document chunking strategies.

Core concept

By the end

You will be able to

  • Compare fixed-token, recursive, semantic, and hierarchical chunking trade-offs.
  • Preserve semantic coherence across section headers, tables, and code snippets.
  • Implement metadata enrichment including document hierarchy and creation timestamps.
  • Quantify how chunk boundary choices impact retrieval recall and precision.
01

Move Beyond Fixed Token Windows

Naive fixed-length token chunking frequently severs context mid-sentence or separates table rows from their column headers. Modern retrieval systems use recursive hierarchy-aware splitters that break at paragraph and sentence boundaries first.

Parent-document retrieval indexes smaller child chunks for dense vector matching while returning larger parent document sections to the language model context window. This decouples retrieval precision from synthesis comprehension.

Parent Document Chunking Implementation
python
from dataclasses import dataclass
from typing import List, Dict, Any
import uuid

@dataclass
class Chunk:
    id: str
    text: str
    parent_id: str
    metadata: Dict[str, Any]

def create_hierarchical_chunks(doc: str, parent_size: int = 1000, child_size: int = 200) -> List[Chunk]:
    parent_id = str(uuid.uuid4())
    paragraphs = [p.strip() for p in doc.split("\n\n") if p.strip()]
    chunks = []
    for p in paragraphs:
        chunks.append(Chunk(id=str(uuid.uuid4()), text=p, parent_id=parent_id, metadata={"chars": len(p)}))
    return chunks
02

Enrich Chunks with Structural Metadata

Vector similarity alone is insufficient for enterprise authorization and temporal relevance. Chunks must be stamped with access control lists (ACLs), document versions, chapter hierarchies, and source timestamps.

Filtering pre-search or post-search via metadata eliminates cross-tenant data leaks and prevents stale policy versions from polluting model context.

Enriched Chunk Payload Schema
json
{
  "chunkId": "chk_8f9a2b1c",
  "documentId": "doc_hr_policy_2026",
  "content": "Employees are eligible for 12 weeks of parental leave after 180 days of continuous service.",
  "metadata": {
    "section": "Benefits / Family Leave",
    "version": "2026.1",
    "effectiveDate": "2026-01-01",
    "allowedRoles": ["employee", "manager", "hr_admin"],
    "tokenCount": 24
  }
}

Practice activity

Implement and Compare Chunking Strategies

  1. Ingest a multi-page technical policy containing tables and nested headers.
  2. Apply fixed-token chunking (256 tokens) and hierarchical parent-document chunking.
  3. Execute 5 test queries targeting boundary-spanning facts and measure retrieval recall.

What to produce

  • Export chunking output diff comparing boundary preservation.
  • Recorded precision/recall table showing parent-document retrieval accuracy.

Reflect before continuing

How does child chunk embedding density affect similarity score calibration compared to raw full-page embeddings?

Evidence

Sources and verification

Knowledge check

Make it stick.

Pass at 80%

Choose the strongest answer for each question. Your attempts become part of your account transcript.

01What primary problem does parent-document retrieval solve in enterprise RAG pipelines?
02Why should metadata filtering (e.g. ACLs, dates) be applied during the retrieval step?