# tencentcloudadp/youtu-graphrag architecture

> Architecture diagram of the GitHub repository tencentcloudadp/youtu-graphrag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tencentcloudadp/youtu-graphrag
- Repository: https://github.com/tencentcloudadp/youtu-graphrag

## Overview

##### Project type and purpose
- This is a full-stack Python application (“Youtu-GraphRAG”) that exposes a web UI for Graph-RAG (Retrieval-Augmented Generation) workflows.
- Its goal is to ingest large schemas and corpora, build hierarchical knowledge graphs, perform schema-aware multi-hop retrieval (via FAISS + LLMs), apply community detection, decompose complex queries, and render answers + graph visualizations in a browser.

##### File structure
- Top-level “frontend/” + “assets/” ⇒ browser UI (index.html, JavaScript, images).
- “main.py” and “backend.py” ⇒ web server (likely Flask/FastAPI) implementing REST endpoints.
- “config/” ⇒ YAML-driven centralized configuration + loader.
- “models/constructor/” ⇒ KTBuilder (knowledge-tree constructor), “models/retriever/” ⇒ KTRetriever, AgenticDecomposer, FAISS filter.
- “utils/” ⇒ LLM API calls, graph processing, community detection, evaluation & logging.
- “retriever/faiss_cache_new/” ⇒ on-disk FAISS indices (node, community, triple, chunk caches).
- “schemas/” ⇒ JSON schema definitions for various benchmarks/domains.
- “data/” and “output/” ⇒ seed/demo data and generated graphs/chunks.
- Dockerfile, setup_env.sh, start.sh ⇒ container + shell scripts for deployment.

##### README for additional insights
- Key capabilities:
– Schema-guided, four-level knowledge tree construction
– Dually-perceived hierarchical community detection
– Agentic retrieval and iterative reflection (IRCoT)
– Parallel sub-question processing and LLM integration
– Unified YAML configuration and multi-domain transfer

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Browser UI"]:::frontend
        IndexHTML["index.html"]:::frontend
        Assets["assets/"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        MainHandler["main.py"]:::core
        BackendModule["backend.py"]:::core
    end

    %% Configuration Manager
    subgraph "Configuration Manager"
        ConfigLoader["config_loader.py"]:::utils
        BaseConfig["base_config.yaml"]:::utils
    end

    %% Orchestrator / Pipeline
    Orchestrator["Orchestrator"]:::core

    %% Pipeline Stages
    subgraph "Agentic Pipeline"
        Decomposer["Query Decomposer"]:::core
        DualRetriever["DualFAISSRetriever"]:::core
        KTRetriever["EnhancedKTRetriever"]:::core
        Constructor["Graph Constructor (KTBuilder)"]:::core
        GraphProcessor["Graph Processor"]:::utils
        Detector["Community Detector"]:::utils
        Generator["Answer Generator"]:::core
    end

    %% Data Stores
    subgraph "Data Stores"
        SchemaStore["schemas/"]:::datastore
        DemoData["data/demo/"]:::datastore
        FAISSCaches["retriever/faiss_cache_new/"]:::datastore
        OutputGraphs["output/graphs/"]:::datastore
        OutputChunks["output/chunks/"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        LLMProvider["LLM Service"]:::external
        Neo4j["Neo4j"]:::external
    end

    %% Connections
    UI -->|"query JSON"| MainHandler
    IndexHTML --> UI
    Assets --> UI

    MainHandler -->|"load config"| ConfigLoader
    MainHandler -->|"route request"| Orchestrator
    ConfigLoader --> BaseConfig
    BaseConfig --> Orchestrator

    Orchestrator -->|"decompose query"| Decomposer
    Decomposer -->|"sub-queries"| LLMProvider
    LLMProvider -->|"answers"| Decomposer
    Decomposer --> Orchestrator

    Orchestrator -->|"retrieve chunks"| DualRetriever
    DualRetriever -->|"use indices"| FAISSCaches
    Orchestrator -->|"retrieve chunks"| KTRetriever
    KTRetriever -->|"use schema"| SchemaStore
    KTRetriever --> DemoData

    DualRetriever -->|"text chunks"| Constructor
    KTRetriever -->|"text chunks"| Constructor

    Constructor -->|"raw graph"| GraphProcessor
    GraphProcessor -->|"tree structure"| Detector
    Detector -->|"communities"| LLMProvider
    LLMProvider -->|"summaries"| Detector

    Detector -->|"annotated graph"| Generator
    Generator -->|"answer JSON"| MainHandler

    Constructor --> OutputGraphs
    Constructor --> OutputChunks

    MainHandler -->|"response JSON"| UI
    Generator --> Neo4j

    %% Click Events
    click IndexHTML "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/frontend/index.html"
    click Assets "https://github.com/tencentcloudadp/youtu-graphrag/tree/main/assets/"
    click MainHandler "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/main.py"
    click BackendModule "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/backend.py"
    click ConfigLoader "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/config/config_loader.py"
    click BaseConfig "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/config/base_config.yaml"
    click Orchestrator "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/main.py"
    click Decomposer "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/models/retriever/agentic_decomposer.py"
    click DualRetriever "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/models/retriever/faiss_filter.py"
    click FAISSCaches "https://github.com/tencentcloudadp/youtu-graphrag/tree/main/retriever/faiss_cache_new/"
    click KTRetriever "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/models/retriever/enhanced_kt_retriever.py"
    click Constructor "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/models/constructor/kt_gen.py"
    click GraphProcessor "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/utils/graph_processor.py"
    click Detector "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/utils/tree_comm.py"
    click Generator "https://github.com/tencentcloudadp/youtu-graphrag/blob/main/utils/call_llm_api.py"
    click SchemaStore "https://github.com/tencentcloudadp/youtu-graphrag/tree/main/schemas/"
    click DemoData "https://github.com/tencentcloudadp/youtu-graphrag/tree/main/data/demo/"
    click OutputGraphs "https://github.com/tencentcloudadp/youtu-graphrag/tree/main/output/graphs/"
    click OutputChunks "https://github.com/tencentcloudadp/youtu-graphrag/tree/main/output/chunks/"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000
    classDef core fill:#98FB98,stroke:#000
    classDef datastore fill:#FFD700,stroke:#000
    classDef utils fill:#D3D3D3,stroke:#000
    classDef external fill:#F0F8FF,stroke:#000,stroke-dasharray: 5 5
```
