raptor-hierarchical-retrieval
Skill8 starsChanged 7 months agoMITView on GitHub
Use hierarchical clustering and summarization to create multi-level document trees for improved retrieval.
In this repository39 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rag-skillsSkill
- choosing-a-chunking-frameworkSkill
- contextual-chunk-headersSkill
- hierarchical-chunkingSkill
- 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
- 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 39
Use your preferred embedding model to create vector representations, then apply clustering algorithms (e.g., Gaussian Mixture Models, …
- Distinctive: line 74
Use an LLM or compression technique to extract the most relevant portions of retrieved content for the specific query.
- Distinctive: line 85
When queries vary from broad overviews to specific details
- Distinctive: line 87
When you need to maintain both specificity and breadth in retrieval
- Distinctive: line 92
When document updates are frequent (tree rebuilding is expensive)
- Distinctive: line 94
When latency must be minimized (multi-level retrieval adds overhead)
≈ “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
RAPTOR (Recursive Abstractive Processing and Tree-Organized Retrieval) creates a hierarchical tree of document summaries, allowing retrieval at multiple levels of abstraction. This approach balances broad overviews with specific details, enabling more nuanced information retrieval from large document collections.
Problem Statement
Large document collections present retrieval challenges:
- Granularity Mismatch: Queries may need broad context or specific details, but single-level retrieval can't adapt
- Information Overload: Retrieving from all documents returns too much content
- Coherence Loss: Retrieved fragments lack connection to broader themes
- Scalability Issues: Linear search becomes inefficient with growing collections
- Context Gaps: Missing connections between related concepts across documents
Key Concepts
- Tree Building: Creating hierarchical summaries through clustering and abstraction
- Level-wise Abstraction: Each level represents increasingly condensed information
- Cluster Summarization: Grouping similar documents and creating summaries
- Multi-level Retrieval: Querying across multiple abstraction levels
- Parent-Child Links: Maintaining connections between summaries and source documents
Implementation Guide
Step 1: Document Embedding and Clustering
Embed all documents and cluster them by semantic similarity.
Why: Clustering groups related documents together, enabling summary creation that captures themes across multiple documents rather than individual pieces.
Use your preferred embedding model to create vector representations, then apply clustering algorithms (e.g., Gaussian Mixture Models, k-means).
Step 2: Cluster Summarization
Generate summaries for each cluster of documents.
Why: Summaries capture the key information from multiple documents, creating a higher-level abstraction that preserves important themes while reducing volume.
For each cluster, concatenate the documents and use an LLM to generate a concise summary.
Step 3: Build Tree Hierarchically
Recursively apply embedding, clustering, and summarization to build multiple levels.
Why: Multiple levels of abstraction allow the system to retrieve at appropriate granularity - broad context from high levels, specific details from low levels.
Apply the same process to the summaries created in the previous level, building up the tree until reaching a single root summary or maximum levels.
Step 4: Build Multi-Level Vector Index
Index all documents and summaries at all levels.
Why: A unified vector index allows efficient similarity search across all abstraction levels, enabling the retriever to select the most appropriate level for each query.
Embed and index all content from all tree levels with metadata indicating the level and origin.
Step 5: Implement Multi-Level Retrieval
Query across all levels and combine results intelligently.
Why: Multi-level retrieval ensures both broad context and specific details are considered. Combining results from different levels provides comprehensive information.
Retrieve from multiple levels and balance the results to ensure both breadth and depth in the retrieved information.
Step 6: Implement Contextual Compression
Extract only relevant parts from retrieved content.
Why: High-level summaries may contain more information than needed for a specific query. Contextual compression focuses on the most relevant portions.
Use an LLM or compression technique to extract the most relevant portions of retrieved content for the specific query.
Step 7: Build Complete RAPTOR Pipeline
Combine all components into a cohesive system.
Why: A complete pipeline with timing and explanation allows optimization, debugging, and production deployment.
For implementation patterns, see the RAPTOR paper, LlamaIndex RAPTOR pack, and scikit-learn clustering documentation.
When to Use This Skill
- Building RAG systems with large document collections (100+ documents)
- When queries vary from broad overviews to specific details
- For domains where thematic organization is important (academic papers, research)
- When you need to maintain both specificity and breadth in retrieval
- For applications requiring traceability from summaries to source documents
When NOT to Use This Skill
- For small document collections where single-level search is sufficient
- When document updates are frequent (tree rebuilding is expensive)
- For applications requiring only specific factual answers
- When latency must be minimized (multi-level retrieval adds overhead)
- For real-time document ingestion scenarios
Related Skills
- Hierarchical Chunking - Document-level hierarchy
- Multi-Pass Retrieval with Reranking - Result refinement
- Graph RAG - Relationship-based retrieval
Metrics & Success Criteria
- Scalability: Efficient handling of growing document collections
- Retrieval Quality: Improved NDCG through balanced level selection
- Query Coverage: Better results across both broad and specific queries
- Index Build Time: Acceptable time for tree construction
- Traceability: Reliable parent-child linking for source verification
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.

