Advanced10 min read28 of 40

RAPTOR

Recursive Abstractive Processing for Tree-Organized Retrieval — builds a hierarchical summary tree for multi-level querying.

Overview

PropertyDetail
PatternRAPTOR — Hierarchical Tree Retrieval
LevelAdvanced
Key InnovationRecursive clustering + summarization into a tree
Best ForLong documents, questions at different abstraction levels
Notebook21_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

StepActionOutput
1Chunk document into leavesN leaf chunks
2Embed leaves, cluster by similarity (k-means)Groups of related chunks
3Summarize each cluster with ClaudeParent nodes (Level 1)
4Cluster + summarize parentsHigher levels (Level 2, 3...)
5Repeat until single root summaryComplete tree
6At query time: search all levelsMatch at appropriate abstraction

Multi-Level Querying

Question TypeTree LevelExample
High-level overviewRoot"What is this paper about?"
Section summaryLevel 1-2"What methodology was used?"
Specific detailLeaf"What was the p-value?"
Cross-levelMultiple"How does methodology support conclusions?"

When to Use

ScenarioUse RAPTOR?
Very long documents (books, contracts, papers)Yes
Questions at different abstraction levelsYes
Users ask both "overview" and "specific detail"Yes
Short documents (<5 pages)No — tree overhead not justified
Real-time indexing neededNo — tree building is expensive
Single abstraction level queriesNo — simpler methods suffice

Tech Stack

ComponentTechnology
EmbeddingsAWS Bedrock — Amazon Titan Embed Text v2 (1024 dims)
LLMAWS Bedrock — Claude Sonnet
Vector DBQdrant Cloud
Clusteringk-means on embeddings
FrameworkLangChain

Source