Overview
| Property | Detail |
|---|
| Pattern | RAPTOR — Hierarchical Tree Retrieval |
| Level | Advanced |
| Key Innovation | Recursive clustering + summarization into a tree |
| Best For | Long documents, questions at different abstraction levels |
| Notebook | 21_Recursive_RAG.ipynb |
Architecture
flowchart BT
subgraph LEAVES["Leaf Level — Original Chunks"]
C1[C1]
C2[C2]
C3[C3]
C4[C4]
C5[C5]
C6[C6]
C7[C7]
C8[C8]
C9[C9]
end
subgraph CLUSTERS["Cluster Level — Section Summaries"]
S1["Cluster 1 Summary"]
S2["Cluster 2 Summary"]
S3["Cluster 3 Summary"]
end
subgraph ROOT["Root Level — Full Document Summary"]
R["ROOT SUMMARY"]
end
C1 --> S1
C2 --> S1
C3 --> S1
C4 --> S2
C5 --> S2
C6 --> S2
C7 --> S3
C8 --> S3
C9 --> S3
S1 --> R
S2 --> R
S3 --> R
At query time: Search ALL tree levels simultaneously. Overview questions match the root, section-level questions match clusters, detail questions match leaf chunks.
How It Works
| Step | Action | Output |
|---|
| 1 | Chunk document into leaves | N leaf chunks |
| 2 | Embed leaves, cluster by similarity (k-means) | Groups of related chunks |
| 3 | Summarize each cluster with Claude | Parent nodes (Level 1) |
| 4 | Cluster + summarize parents | Higher levels (Level 2, 3...) |
| 5 | Repeat until single root summary | Complete tree |
| 6 | At query time: search all levels | Match at appropriate abstraction |
Multi-Level Querying
| Question Type | Tree Level | Example |
|---|
| High-level overview | Root | "What is this paper about?" |
| Section summary | Level 1-2 | "What methodology was used?" |
| Specific detail | Leaf | "What was the p-value?" |
| Cross-level | Multiple | "How does methodology support conclusions?" |
When to Use
| Scenario | Use RAPTOR? |
|---|
| Very long documents (books, contracts, papers) | Yes |
| Questions at different abstraction levels | Yes |
| Users ask both "overview" and "specific detail" | Yes |
| Short documents (<5 pages) | No — tree overhead not justified |
| Real-time indexing needed | No — tree building is expensive |
| Single abstraction level queries | No — simpler methods suffice |
Tech Stack
| Component | Technology |
|---|
| Embeddings | AWS Bedrock — Amazon Titan Embed Text v2 (1024 dims) |
| LLM | AWS Bedrock — Claude Sonnet |
| Vector DB | Qdrant Cloud |
| Clustering | k-means on embeddings |
| Framework | LangChain |
Source