This repository contains the source code for the article "GraphRAG vs. Baseline RAG: Solving Multi-Hop Reasoning in LLMs".
- Python 3.11+
- An OpenAI API key
- Create and activate a Python virtual environment:
python3 -m venv .venv
source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
- Install the required packages:
pip install -r requirements.txt
- Set up environment variables:
cp .env.example .env
- Edit
.env
file and add your API key:
OPENAI_API_KEY
: Your OpenAI API key
-
Open
main.ipynb
-
Run all cells to see the demo in action
The notebook demonstrates:
- Initial setup and utility functions for response handling
- Loading and parsing a corpus of articles
- Construction of a GraphRAG index using LlamaIndex
- Construction of a traditional Vector RAG index for comparison
- Visualization of the knowledge graph (viewable in
knowledge_graph.html
) - Comparison of both approaches through multiple test questions
- Performance analysis showing GraphRAG's superior accuracy in multi-hop reasoning tasks