Semantic and Hierarchical Chunking
Fixed and recursive chunking split by size and structure. Semantic and hierarchical chunking go one level deeper: they try to preserve topic meaning and document relationships so retrieval can find small evidence while still recovering the larger context around it.
How to read this chapter
- Read it as context engineering: semantic chunking asks where the topic naturally changes; hierarchical chunking asks how a small chunk relates to its parent section.
- Do not overbuild: simple recursive chunking is often enough. Use semantic or hierarchical strategies when evaluation shows boundary or context failures.
- Track relationships: parent document, section, child chunk, sibling chunks, and heading path all matter in production retrieval.
- Design for retrieval: the goal is not elegant slicing; the goal is better evidence selection, citations, and answer faithfulness.
Why Advanced Chunking Matters
- Semantic chunking helps when paragraphs shift topics unevenly.
- Hierarchical chunking helps when small evidence needs a larger parent context.
- Parent-child retrieval can retrieve small chunks but send parent context to the model.
- These strategies add complexity, so they should be justified by failures or product needs.
Chapter 9 taught fixed and recursive chunking. Those are strong baselines. But some documents are more complex: long policies with exceptions, tutorials with code blocks, research reports with layered sections, and runbooks where a step only makes sense inside the procedure.
Do not force one chunk to do every job. Child chunks can find evidence; parent chunks can explain it.
Consider semantic chunking when paragraphs or sections contain multiple topic shifts that simple size rules miss.
Consider hierarchical chunking when a retrieved paragraph needs the surrounding section for faithful answers.
Keep recursive or fixed chunking if golden questions already retrieve complete, citeable evidence.
Track parent ids, child ids, source positions, retrieval expansion rules, and evaluation by hierarchy level.
Real-Life Analogy: A Book With Chapters, Sections, and Paragraphs
If someone asks a precise question, you may point them to one paragraph. But if they need to understand the rule properly, you may also tell them the chapter and section it belongs to.
Hierarchical chunking works like that. The paragraph is the child chunk. The section is the parent chunk. The whole document is the grandparent. Retrieval can start precise and then expand context responsibly.
- Semantic chunking follows topic changes.
- Hierarchical chunking preserves document relationships.
- Parent-child retrieval balances precision and context.
Semantic Chunking
Semantic chunking groups text by meaning rather than only size or separators. It tries to keep related ideas together and split where topics change.
Semantic boundary idea
Paragraphs about refund eligibility
-> stay together
Paragraphs shift to cancellation workflow
-> new chunk
Paragraphs shift to enterprise exception
-> new chunk or child chunk linked to parent policy sectionBest fit
Reports, policies, tutorials, FAQs, and research documents where topic changes do not follow neat size boundaries.
Advantages
Better topic purity, less noisy context, stronger citations, and better answer faithfulness for concept-heavy content.
Watch-outs
More expensive to build, harder to debug, and sensitive to topic-detection quality. It still needs size limits.
Hierarchical Chunking
Hierarchical chunking stores multiple levels of context: document, section, subsection, paragraph, and sometimes sentence or row. Each child chunk knows its parent.
Hierarchy example
Document: Refund Policy 2026
Section: EU annual plans
Child chunk: eligibility rule
Child chunk: 14-day window
Child chunk: enterprise exception
Child chunk: approval workflowRetrieve child chunks
Small chunks help the retriever find the exact evidence that matches the question.
Expand to parent sections
Parent chunks provide definitions, constraints, and exceptions around the retrieved evidence.
Cite exact child evidence
Use the child chunk for exact citation, while using parent context to avoid misunderstanding.
Maintain relationships
Every child needs parent id, heading path, section, source position, and index version.
Parent-Child Retrieval
Parent-child retrieval usually searches child chunks first. Once the best child chunks are found, the system can fetch their parent sections for context.
Security runbook answer
A user asks: "What do I do if the customer-log export job fails during Sev1?"
- Child retrieval: finds the exact failure step.
- Parent expansion: includes the Sev1 incident workflow section around that step.
- Safety: access metadata filters restricted runbook content.
- Citation: cites the exact child step, not the entire runbook.
The lesson: precise retrieval and safe context can be separate stages.
Production failure mode
The child chunk retrieves correctly, but parent expansion pulls a huge unrelated section and distracts the model.
Engineering checklist
- Limit parent expansion size.
- Preserve parent-child ids.
- Deduplicate sibling chunks.
- Evaluate child recall and parent usefulness separately.
Metrics to watch
child Recall@k, parent expansion precision, context utilization, citation support, and sibling duplicate rate.
When Simple Chunking Is Enough
Advanced chunking is not automatically better. It adds storage, logic, evaluation complexity, and operational burden.
Clean FAQ or short docs
If each question-answer pair or short section already retrieves cleanly, fixed or recursive chunking is enough.
Topic shifts inside long sections
If size-based chunks mix unrelated concepts, semantic boundaries can improve precision.
Small evidence needs larger context
If precise chunks retrieve but answers lack surrounding definitions or exceptions, parent-child retrieval helps.
Let failures justify complexity
Upgrade only when golden queries show lost context, mixed topics, weak citations, or parent-context dependency.
Architecture View
Parent-child retrieval flow
user question
-> retrieve child chunks
-> select best child evidence
-> fetch parent section
-> assemble child citation + parent context
-> answer with grounded citationProduction Controls
- Hierarchy schema: document id, parent id, child id, heading path, source position, and chunker version.
- Expansion rules: decide when to fetch parent, sibling, or neighboring chunks.
- Context budget: parent expansion must respect token budget and avoid flooding the prompt.
- Access filters: parent and child chunks must both pass permission checks.
- Evaluation: measure child retrieval and parent expansion separately.
- Fallback: if parent context is missing, answer from child only with caution or ask for review.
Common Mistakes
Losing parent-child ids
Expanding too much parent context
Citing parent when child is the evidence
Ignoring access on parent expansion
Overusing hierarchy for simple FAQs
Evaluating only final answers
Not versioning hierarchy rules
Mini Assignment
Pick one corpus: security runbooks, HR policies, developer docs, or product tutorials. Decide whether fixed, recursive, semantic, or hierarchical chunking is justified. Define child chunks, parent sections, metadata, expansion rules, and two golden questions.
Points To Remember
- Semantic chunking follows meaning and topic boundaries.
- Hierarchical chunking preserves parent-child document relationships.
- Parent-child retrieval can retrieve precise evidence and expand context responsibly.
- Simple chunking is enough when it passes retrieval and citation evals.
- Advanced chunking must be evaluated and operated, not just admired.
Next, test advanced chunking judgment in the quiz, then build a hierarchy planner in exercises and project.