hierarchical-chunking
Skill8 starsChanged 7 months agoMITView on GitHub
Chunk nested documents into parent-child levels so retrieval can move from broad sections to fine-grained passages.
In this repository39 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rag-skillsSkill
- choosing-a-chunking-frameworkSkill
- contextual-chunk-headersSkill
- semantic-chunkingSkill
- chunkingSkill
- sliding-window-chunkingSkill
- rag-for-code-documentationSkill
- rag-for-multimodal-contentSkill
- data-type-handlingSkill
- index-versioning-and-reindexingSkill
- production-rag-deploymentSkill
- deploymentSkill
- generation-evaluation-metricsSkill
- rag-evaluation-frameworksSkill
- retrieval-evaluation-metricsSkill
- evaluation-metricsSkill
- optimize-retrieval-latencySkill
- performance-optimizationSkill
- agentic-rag-routingSkill
- multi-agent-rag-orchestrationSkill
- rag-agentsSkill
- adaptive-retrievalSkill
- context-enrichment-windowSkill
- crag-corrective-ragSkill
- explainable-retrievalSkill
- graph-ragSkill
- hybrid-search-bm25-denseSkill
- hyde-hypothetical-document-embeddingsSkill
- hype-hypothetical-prompt-embeddingsSkill
- multi-pass-retrieval-with-rerankingSkill
- query-transformation-strategiesSkill
- raptor-hierarchical-retrievalSkill
- self-ragSkill
- retrieval-strategiesSkill
- choosing-vector-db-by-datatypeSkill
- qdrant-for-production-ragSkill
- qdrant-setup-ragSkill
- vector-databasesSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 20
No way to retrieve "context for context" - when a detail is retrieved, its containing section is lost
- Distinctive: line 57
When you need both summary and detailed retrieval
- Distinctive: line 59
When building document browsing/search interfaces
- Distinctive: line 64
When storage complexity outweighs retrieval benefits
- Distinctive: line 66
When retrieval latency is critical (hierarchical retrieval adds overhead)
- Distinctive: line 74
Coverage: All document content preserved across hierarchy levels
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Overview
Hierarchical chunking creates multi-level chunk structures that preserve document hierarchies (chapters, sections, subsections). This enables both broad-overview retrieval (high-level chunks) and detailed retrieval (low-level chunks) with parent-child relationships for context propagation.
Problem Statement
Flat chunking strategies lose the structural relationships within documents:
- Questions about broad topics retrieve detailed fragments instead of summaries
- No way to retrieve "context for context" - when a detail is retrieved, its containing section is lost
- Navigation through document hierarchies becomes impossible
- Retrieval results can't be organized by document structure
Key Concepts
- Parent-Child Relationships: Links between summary chunks and their detailed sub-chunks
- Multi-Level Granularity: Chunks at different abstraction levels (document → chapter → section → paragraph)
- Context Propagation: Ability to include parent context when retrieving child chunks
- Metadata Enrichment: Storing hierarchy information for filtering and navigation
- Recursive Chunking: Applying chunking rules recursively through document structure
Implementation Guide
Step 1: Parse Document Structure
Extract the hierarchical structure of your documents.
Why: Proper parsing is foundational - you can't create a hierarchy without understanding the structure.
Step 2: Create Multi-Level Chunks
Generate chunks at multiple levels from the parsed hierarchy.
Why: Multiple chunk levels allow different retrieval strategies - summary chunks for broad questions, detailed chunks for specifics.
Step 3: Store Hierarchy Metadata
Persist hierarchy information for retrieval-time context propagation.
Why: Metadata enables filtering and hierarchical queries (e.g., "retrieve from level 2 or deeper").
Step 4: Implement Hierarchical Retrieval
Retrieve chunks with optional parent context.
Why: Hierarchical retrieval allows users to "zoom in" from broad topics to specific details, just like browsing a table of contents.
For implementation details, see the LlamaIndex HierarchicalNodeParser, LangChain RecursiveCharacterTextSplitter, Haystack HierarchicalDocumentSplitter, and LlamaIndex Recursive Retriever + Node References.
When to Use This Skill
- Long-form documents with clear structure (books, technical documentation, research papers)
- When you need both summary and detailed retrieval
- For applications that support "drill-down" navigation
- When building document browsing/search interfaces
- For Q&A systems that benefit from hierarchical context
When NOT to Use This Skill
- Flat content without structure (blog posts, single-page articles)
- When storage complexity outweighs retrieval benefits
- For small document collections where simple chunking suffices
- When retrieval latency is critical (hierarchical retrieval adds overhead)
Related Skills
- Semantic Chunking - For content-aware chunking
- Sliding Window Chunking - For context overlap
- Multi-Pass Retrieval with Reranking - For refining hierarchical results
Metrics & Success Criteria
- Coverage: All document content preserved across hierarchy levels
- Retrieval Flexibility: Can retrieve at any abstraction level
- Context Relevance: Parent context improves answer quality for detailed questions
- Storage Efficiency: Metadata overhead doesn't exceed 30% of storage
- Query Latency: Hierarchical retrieval within 2x of flat retrieval
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

