Skip to content

AYON-ARYAN/graph-rag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔮 GraphRAG — Knowledge Graph-Powered RAG

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.


✨ Features

  • 📄 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

🏗️ Architecture

┌─────────────┐     ┌──────────────────────────────────────────┐
│  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        │
                    └──────────────────────────────────────────┘

🚀 Getting Started

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/<your-username>/graph-rag.git
    cd graph-rag
  2. Create a virtual environment

    python -m venv venv
    source venv/bin/activate  # macOS/Linux
    # or
    venv\Scripts\activate     # Windows
  3. Install dependencies

    pip install -r requirements.txt
  4. Configure environment variables

    cp .env.example .env

    Edit .env and add your Groq API key:

    GROQ_API_KEY=your_groq_api_key_here
    
  5. Run the application

    python app.py
  6. Open in browser

    http://localhost:5001
    

📡 API Endpoints

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

🛠️ Tech Stack

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

📁 Project Structure

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

⚠️ Rate Limits

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.


📝 License

MIT

About

Graph RAG system combining Knowledge Graphs (NetworkX) + Vector Search (FAISS) + LLM (Groq) for enhanced Retrieval Augmented Generation. Features interactive D3.js graph visualization, document upload (PDF/TXT), and a glassmorphism UI.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages