graph-rag-agent

repository·master·Indexed 25 days ago

https://github.com/1517005260/graph-rag-agent

An evaluation framework and system for various RAG Agent architectures, including Naive, Graph, Hybrid, and Deep Research agents. It features a Streamlit-based frontend for knowledge graph visualization, performance monitoring, and agent selection. The project includes a CacheManager for storing and retrieving responses with support for exact and semantic similarity matching, multiple key strategies (Simple, Context-Aware, Context and Keyword, Global), and various storage backends (Memory, Disk, and Hybrid).

Tokens
28.3K
Snippets
58
Records
139
Agent score
81%

What's inside graph-rag-agent

  1. Overview of GraphRAG + DeepSearch Agent System

    master

    This project implements an intelligent question-answering system that combines GraphRAG (Graph Retrieval-Augmented Generation) with Deep Search capabilities. It focuses on creating interpretable and reasoning-capable agents through multi-agent collaboration and knowledge graph enhancement.

    Key Capabilities:

    • GraphRAG Implementation: Full reproduction of GraphRAG core features, representing knowledge as a graph structure.
    • DeepSearch Integration: Combines vector-based deep search with knowledge graphs for enhanced reasoning.
    • Multi-Agent Collaboration: Uses a Plan-Execute-Report architecture to handle complex tasks.
    • Incremental Updates: Supports dynamic knowledge graph construction and intelligent deduplication.
    • Entity Quality Management: Includes entity disambiguation and alignment to resolve ambiguities and duplicates.
    • Comprehensive Evaluation: Provides 20+ metrics to measure answer quality, retrieval performance, and graph integrity.
  2. Overview of the Community Detection and Summarization Module

    master

    The graphrag_agent/community/ module provides core functionality for identifying clusters in a Neo4j knowledge graph and generating semantic summaries for them. This is essential for Global Search (providing high-level semantic entry points), Knowledge Graph Analysis (revealing implicit relationships), and Topic Discovery.

    Core Capabilities

    1. Community Detection: Uses graph algorithms to identify clusters of entities.
    2. Community Summarization: Uses LLMs to generate semantic descriptions for each community, which are then stored back in the graph.

    Module Structure

    • detector/: Contains implementations for community detection algorithms (Leiden, SLLPA).
    • summary/: Contains implementations for generating and storing community summaries.
  3. Overview of the Knowledge Graph QA System Frontend

    master

    The frontend is a Streamlit-based interface for a Knowledge Graph-based intelligent Q&A system. It provides a user-friendly way to interact with various Agent types, visualize knowledge graphs, and monitor system performance.

    Key features include:

    • Multi-mode UI: Switch between a standard chat interface and a debug mode that shows execution traces and source content.
    • Agent Selection: Choose from different reasoning strategies including graph_agent, hybrid_agent, naive_rag_agent, deep_research_agent, and fusion_agent.
    • Streaming Responses: Real-time display of AI answers and thought processes (for deep_research_agent) using Server-Sent Events (SSE).
    • Interactive Visualization: Neo4j-style graph interaction using pyvis, supporting node focusing and community detection.
    • Performance Monitoring: Tools to track API latency and system statistics.
  4. Overview of the Knowledge Graph QA System Server

    master

    The server module is a backend API implementation for an intelligent question-answering system based on knowledge graphs. It uses Neo4j for managing graph data and FastAPI to provide web services. Key capabilities include:

    • Chat QA: Interactive question-answering.
    • Knowledge Reasoning: Querying and reasoning over graph data.
    • Graph Visualization: Tools to visualize graph structures.
    • Streaming Responses: Support for Server-Sent Events (SSE) to provide real-time text updates and execution traces.
  5. Overview of the Model Training Module

    master

    The Model Training Module provides two distinct training workflows to optimize the GraphRAG agent for specific tasks:

    1. GRPO Training for Entity Extraction: Uses Group Relative Policy Optimization (GRPO) to train the Qwen2-3B model. This process adapts the model specifically to the entity extraction requirements of this project.
    2. Embedding Model Fine-tuning: Fine-tunes embedding models to learn domain-specific characteristics based on the content located in the files/ directory.
  6. Overview of GraphRAG Agent core features

    master

    The GraphRAG Agent core package provides a comprehensive suite of tools for GraphRAG workflows, including:

    • Agents (agents/): Intelligent agent systems for reasoning and task execution.
    • Cache Management (cache_manager/): Multi-layer caching to reduce redundant computations.
    • Community Detection (community/): Algorithms for identifying clusters within the graph.
    • Graph Construction (graph/): Tools for building and managing the knowledge graph.
    • Evaluation System (evaluation/): Frameworks to assess agent performance and retrieval quality.
    • Search Tools (search/): Specialized tools for querying the graph.
    • Data Pipelines (pipelines/): Workflows for processing raw data into graph structures.
  7. Overview of the Graph Construction Module

    master
    The graphrag_agent/graph module is a complete graph construction and query system built on top of Neo4j. It handles the full lifecycle of knowledge graph creation, including document parsing, entity and relationship extraction, embedding vector index creation, and entity deduplication (similarity detection and merging). The module is designed to be highly modular to support large-scale data processing and optimized query performance.
  8. Overview of the GraphRAG Evaluation System

    master

    The GraphRAG Evaluation System is a comprehensive framework designed to evaluate various types of RAG (Retrieval-Augmented Generation) Agents. It supports testing for:

    • Naive RAG: Traditional vector retrieval.
    • Graph RAG: Graph-based retrieval.
    • Hybrid RAG: Combined vector and graph retrieval.
    • Fusion RAG: Fusion-based retrieval.
    • Deep Research: Advanced research-oriented agents.

    The system uses a compositional design with a hierarchical architecture of base classes and derived classes, allowing for flexible configuration and extensible metrics.

  9. Overview of the Search Module

    master

    The Search module is a core component of the project providing multiple search strategies to enable efficient knowledge retrieval and Q&A. It combines Knowledge Graphs (KG), vector retrieval, and Large Language Models (LLMs).

    Key search strategies include:

    • Local Search: Precise queries within specific communities using vector retrieval.
    • Global Search: Broad, cross-community queries using a Map-Reduce pattern.
    • Hybrid Search: Combines low-level entity details with high-level thematic concepts.
    • Deep Research: Multi-step 'think-search-reason' processes for complex problems.
    • Chain of Exploration: Graph-path exploration encapsulated as LangChain tools.
  10. Initialize models with the Model module

    master
    The Model module manages the initialization and lifecycle of language models using the LangChain framework. It provides specialized functions to retrieve different types of models (Embeddings and LLMs) configured via environment variables. It supports both standard synchronous/asynchronous calls and simulated streaming outputs.
  11. Choose a Cache Key Strategy

    master

    The system provides four strategies for generating cache keys, allowing you to control how queries are matched.

    1. Simple Strategy (SimpleCacheKeyStrategy)

    Uses an MD5 hash of the query text. Best for stateless, independent queries where context doesn't matter.

    2. Context-Aware Strategy (ContextAwareCacheKeyStrategy)

    Considers session history. The cache key includes the thread_id and the last N turns of conversation (defined by context_window). Ideal for chatbots and multi-turn dialogues.

    cache = CacheManager(key_strategy=ContextAwareCacheKeyStrategy(context_window=3))
    
    # Use thread_id to distinguish sessions
    cache.set("继续", "继续前面的讨论...", thread_id="user_123")
    result = cache.get("继续", thread_id="user_123")

    3. Context and Keyword Strategy (ContextAndKeywordAwareCacheKeyStrategy)

    Combines session history with specific keywords for high-precision matching. Useful for technical documentation or domain-specific assistants.

    cache = CacheManager(key_strategy=ContextAndKeywordAwareCacheKeyStrategy(context_window=3))
    
    # Use keywords to enhance the cache key
    cache.set(
        "分析数据",
        "数据分析结果...",
        thread_id="user_123",
        low_level_keywords=["pandas", "numpy"],
        high_level_keywords=["数据科学", "机器学习"]
    )
    
    # Query must provide the same keywords to hit the cache
    result = cache.get(
        "分析数据",
        thread_id="user_123",
        low_level_keywords=["pandas", "numpy"],
        high_level_keywords=["数据科学", "机器学习"]
    )

    4. Global Strategy (GlobalCacheKeyStrategy)

    Ignores context and session IDs. All users share the same cache. Best for general knowledge or static content.