Retrieval Augmented Generation enhanced with Knowledge Graphs for deeper, context-aware AI answers.
GraphRAG combines vector similarity search (FAISS) with knowledge graph traversal (NetworkX) to provide richer, more connected answers than traditional RAG systems. Upload documents, watch entities and relationships emerge as an interactive graph, and query your knowledge base with graph-augmented context.
- 📄 Document Upload — Drag & drop PDF or TXT files for automatic processing
- 🧠 Entity & Relation Extraction — LLM-powered extraction of entities and their relationships
- 🕸️ Knowledge Graph — Automatic construction of a directed knowledge graph from documents
- 🔍 Hybrid Retrieval — Combines FAISS vector search with graph traversal for comprehensive context
- 📊 Interactive D3.js Visualization — Explore your knowledge graph with zoom, pan, drag, and hover tooltips
- 💬 Chat Interface — Ask questions with a real-time pipeline visualization showing each RAG step
- 🎨 Glassmorphism UI — Premium dark-themed interface with animations and particle effects
┌─────────────┐ ┌──────────────────────────────────────────┐
│ Upload PDF │────▶│ GraphRAG Pipeline │
│ or TXT │ │ │
└─────────────┘ │ 1. Chunk Text (500 words, 100 overlap) │
│ 2. Extract Entities & Relations (LLM) │
│ 3. Build Knowledge Graph (NetworkX) │
│ 4. Create Embeddings (Sentence-BERT) │
│ 5. Index in FAISS │
└──────────────────────────────────────────┘
┌─────────────┐ ┌──────────────────────────────────────────┐
│ Ask a │────▶│ Query Pipeline │
│ Question │ │ │
└─────────────┘ │ 1. Vector Search (FAISS, top-3 chunks) │
│ 2. Extract Query Entities (LLM) │
│ 3. Graph Traversal (2-hop neighbors) │
│ 4. Combined Context → LLM Answer │
└──────────────────────────────────────────┘
- Python 3.9+
- Groq API Key (free tier available)
-
Clone the repository
git clone https://github.com/<your-username>/graph-rag.git cd graph-rag
-
Create a virtual environment
python -m venv venv source venv/bin/activate # macOS/Linux # or venv\Scripts\activate # Windows
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
cp .env.example .env
Edit
.envand add your Groq API key:GROQ_API_KEY=your_groq_api_key_here -
Run the application
python app.py
-
Open in browser
http://localhost:5001
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Serve the frontend UI |
| POST | /upload |
Upload and process a document (TXT/PDF) |
| POST | /query |
Query the GraphRAG system |
| GET | /graph |
Get knowledge graph data (D3.js format) |
| GET | /stats |
Get system statistics |
| POST | /reset |
Reset the entire system |
| Component | Technology |
|---|---|
| Backend | Flask, Python |
| Knowledge Graph | NetworkX (Directed Graph) |
| Vector Search | FAISS (Facebook AI Similarity Search) |
| Embeddings | Sentence-Transformers (all-MiniLM-L6-v2) |
| LLM | Groq (llama-3.1-8b-instant) |
| Frontend | Vanilla JS, D3.js, CSS |
| PDF Parsing | PyPDF2 |
graph-rag/
├── app.py # Flask server & REST API
├── graph_rag.py # Core GraphRAG engine
├── requirements.txt # Python dependencies
├── .env # Environment variables (not committed)
├── sample_doc.txt # Sample document for testing
└── static/
├── index.html # Frontend UI
├── style.css # Glassmorphism styles & animations
└── app.js # D3.js graph viz, chat, & upload logic
The free tier of Groq has a 6,000 tokens per minute limit. The engine includes built-in retry logic with exponential backoff to handle rate limiting gracefully. For heavier usage, consider upgrading to the Groq Dev Tier.
MIT