A powerful Retrieval-Augmented Generation (RAG) system utilizing the RAPTOR (Recursive Abstractive Processing for Tree-Organized Retrieval) approach. This system builds a hierarchical tree of document summaries for multiscale retrieval, enabling better answers to both specific and broad/thematic queries.
- Hierarchical Tree Retrieval: Uses RAPTOR to build and traverse a tree of summaries.
- Persistent Storage: Automatically saves and re-loads trees from disk on startup.
- Smart Deduplication: Content-based hashing ensures identical files aren't processed or stored twice.
- Dynamic Frontend: Modern React + TypeScript UI with real-time tree visualization and retrieval details.
- Hybrid Querying: Automatically routes queries between "Broad" (collapsed tree) and "Specific" (tree traversal) strategies.
The easiest way to run the system is using Docker Compose. This handles all dependencies, including the spaCy language models and environment configurations.
- Docker & Docker Desktop installed.
- Ollama running on your host machine (Mac/Windows).
# Navigate to project root
cd TreeBasedRAG_IE
# Build and start in detached mode
docker compose up --build -d- Frontend: http://localhost:5173
- Backend API Docs: http://localhost:8000/docs
Tip
The system automatically bridges to your host machine's Ollama instance via host.docker.internal. Ensure Ollama is running and accessible.
If you prefer to run the services locally without Docker:
- Python 3.9+ is required.
- Install Dependencies:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt # Download the required spaCy model python -m spacy download en_core_web_sm
- Run Server:
export PYTHONPATH=$PYTHONPATH:. python3 -m uvicorn backend.main:app --reload
- Node.js v18+ is required.
- Install & Run:
Available at
cd frontend npm install npm run devhttp://localhost:5173.
To speed up the RAPTOR tree-building process, set the OLLAMA_NUM_PARALLEL environment variable before starting your Ollama server. This allows concurrent summarization of document clusters.
- 8GB - 12GB RAM:
OLLAMA_NUM_PARALLEL=2 - 16GB - 24GB RAM:
OLLAMA_NUM_PARALLEL=4 - 32GB+ RAM:
OLLAMA_NUM_PARALLEL=6
Mac Users:
Run launchctl setenv OLLAMA_NUM_PARALLEL 2 and restart the Ollama app.
backend/: FastAPI application, routers, and services.frontend/: React + TypeScript source code.tree/: Core RAPTOR tree construction and serialization logic.retrieval/: Multi-strategy retrieval and query classification.data/: Processed document storage (deduplicated by hash).my_tree/: Serialized tree structures (persisted across restarts).
- Upload: Use the sidebar to upload a PDF. Its content is hashed and saved to
data/. - Build: The system automatically builds a RAPTOR tree. This is saved to
my_tree/and reloaded on future restarts. - Query: Ask questions! The system will classify your query and retrieve context from the appropriate layers of the tree.
- Visualize: Check the "Tree Structure" and "Retrieved Nodes" panels to see exactly how the RAG engine picked its context.