# israel-adewuyi/graphrag architecture

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

- Interactive diagram: https://gitdiagram.com/israel-adewuyi/graphrag
- Repository: https://github.com/israel-adewuyi/graphrag

## Overview

##### Project Type and Purpose
- The project is an implementation of the GraphRAG paper. It processes podcast transcripts (specifically Dwarkesh Patel’s interview) and uses them as the knowledge source.
- The implementation involves transcript ingestion, document processing (chunking and analysis), indexing using FAISS (a vector similarity search tool), graph construction, and interactive querying via a web interface with Streamlit.
- The goal is to replicate the GraphRAG methodology by producing a knowledge graph and enabling chat-style query interaction and visualization.

##### File Structure
- Top-level directories include:
- document_processing – handles reading, chunking, and analyzing transcripts.
- faiss_index – holds the FAISS index files generated from processed data.
- graph – implements the graph construction aspect, presumably including the main logic (e.g., graphrag.py) and pipeline orchestration.
- prompts – includes modules for crafting various prompts (community, entity extraction, global responses, etc.) with a dedicated templates directory.
- transcripts – contains raw podcast transcript text files.
- utils – utility functions for graph drawing and token counting.
- webpages – the web component using Streamlit, which includes the main app, query interface, and visualization logic.
- Other files (e.g., requirements.txt, LICENSE, README) and configuration hints (.devcontainer for development environment, network.html for graph visualization) support build and deployment.

- Main Components:
a. Data Ingestion & Document Processing:
- Transcripts: Located in the transcripts directory.
- Document Processing Module: Processes transcripts (chunking, analysis) using scripts in document_processing.
b. Indexing:
- FAISS Index: FAISS files (index.faiss and index.pkl) are managed here to support fast similarity searches.
c. Graph Construction:
- Graph Module: Uses processed data and FAISS index to build the knowledge graph (graph/graphrag.py and pipeline.py).
d. Prompt Generation:
- Prompts and Templates: Handle various aspects of query construction and response generation (e.g., community, entity extraction).
e. Web Interface (Frontend):
f. Configuration & Utilities:
- Utils: Additional functionality such as graph rendering and token counting.
- Interactions and Data Flow:
- Transcripts are first processed in the Document Processing module.
- Processed data is then indexed using the FAISS module.
- The indexed data is fed into the Graph module to build the knowledge graph.
- The Prompt generation module refines the interactions, creating query responses or summaries.

##### Architectural Patterns and Technologies
- The design follows a modular pattern where processing, indexing, graph construction, and UI are decoupled.
- It integrates a microservice-like approach even if the modules are part of the same repository, making each responsible for a single aspect of functionality.
- Key libraries and technologies include:
- FAISS for similarity search.
- Streamlit for the web interface.
- Python libraries for text processing, graph construction, and visualization.
- The use of a container development configuration (.devcontainer) indicates a focus on reproducibility and deployment consistency.

- Every module in the file tree is represented in its appropriate layer/component.
- Integration between the document processing pipeline and the interactive web frontend.
- Iterated nature where outputs from one module (like the processed data or computed graph) are used as inputs by subsequent modules.
- Optionally, include external components such as deployment configuration (using .devcontainer) and links to the visual network HTML page provided under the network.html file.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Data Processing Layer
    subgraph "Data Processing Layer"
        A["Transcript Ingestion"]:::data
        subgraph "Document Processing Module"
            B["Document Processing Module"]:::data
            B1["chunking.py"]:::file
            B2["chunk_analysis.py"]:::file
            B3["read_transcript.py"]:::file
            B --> B1
            B1 --> B2
            B2 --> B3
        end
        subgraph "FAISS Indexing"
            C["FAISS Index"]:::data
            C1["index.faiss"]:::file
            C2["index.pkl"]:::file
            C --> C1
            C1 --> C2
        end
        A -->|"processes"| B
        B3 -->|"outputs to"| C
    end

    %% Logic/Graph Layer
    subgraph "Logic/Graph Layer"
        subgraph "Graph Construction"
            D["Graph Construction"]:::logic
            D1["graphrag.py"]:::file
            D2["pipeline.py"]:::file
            D --> D1
            D1 --> D2
        end
        subgraph "Prompt Generation"
            E["Prompt Generation"]:::logic
            E1["Prompt Modules"]:::file
            E2["Templates Directory"]:::file
            E --> E1
            E1 --> E2
        end
        C2 -->|"feeds data to"| D
        D2 -->|"provides output to"| E
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        subgraph "Web Interface (Streamlit)"
            F["Web Interface (Streamlit)"]:::presentation
            F1["app.py"]:::file
            F2["main.py"]:::file
            F3["queryllm.py"]:::file
            F4["visualize.py"]:::file
            F --> F1
            F1 --> F2
            F2 --> F3
            F3 --> F4
        end
        E2 -->|"delivers prompts to"| F
    end

    %% Configuration & Utility Layer
    subgraph "Configuration/Utility Layer"
        subgraph "Configurations & Utilities"
            G["Configuration"]:::config
            G1["color_map.py"]:::file
            G2["entities.py"]:::file
            G3["transcript_link.py"]:::file
            G --> G1
            G1 --> G2
            G2 --> G3

            H["Utility Functions"]:::config
            H1["draw_graphs.py"]:::file
            H2["token_counter.py"]:::file
            H --> H1
            H1 --> H2

            I["DevContainer"]:::config
        end
    end

    %% Support dotted arrows from Config and Utils to modules
    G ---|"configures"| A
    G ---|"configures"| B
    G ---|"configures"| D
    G ---|"configures"| E
    G ---|"configures"| F
    H ---|"supports"| B
    H ---|"supports"| D
    H ---|"supports"| F
    I ---|"defines environment for"| G

    %% Click Events
    click A "https://github.com/israel-adewuyi/graphrag/tree/master/transcripts"
    click B "https://github.com/israel-adewuyi/graphrag/tree/master/document_processing"
    click B1 "https://github.com/israel-adewuyi/graphrag/blob/master/document_processing/chunking.py"
    click B2 "https://github.com/israel-adewuyi/graphrag/blob/master/document_processing/chunk_analysis.py"
    click B3 "https://github.com/israel-adewuyi/graphrag/blob/master/document_processing/read_transcript.py"
    click C "https://github.com/israel-adewuyi/graphrag/tree/master/faiss_index"
    click C1 "https://github.com/israel-adewuyi/graphrag/blob/master/faiss_index/index.faiss"
    click C2 "https://github.com/israel-adewuyi/graphrag/blob/master/faiss_index/index.pkl"
    click D "https://github.com/israel-adewuyi/graphrag/tree/master/graph"
    click D1 "https://github.com/israel-adewuyi/graphrag/blob/master/graph/graphrag.py"
    click D2 "https://github.com/israel-adewuyi/graphrag/blob/master/graph/pipeline.py"
    click E "https://github.com/israel-adewuyi/graphrag/tree/master/prompts"
    click E1 "https://github.com/israel-adewuyi/graphrag/tree/master/prompts"
    click E2 "https://github.com/israel-adewuyi/graphrag/tree/master/prompts/templates"
    click F "https://github.com/israel-adewuyi/graphrag/tree/master/webpages"
    click F1 "https://github.com/israel-adewuyi/graphrag/blob/master/webpages/app.py"
    click F2 "https://github.com/israel-adewuyi/graphrag/blob/master/webpages/main.py"
    click F3 "https://github.com/israel-adewuyi/graphrag/blob/master/webpages/queryllm.py"
    click F4 "https://github.com/israel-adewuyi/graphrag/blob/master/webpages/visualize.py"
    click G "https://github.com/israel-adewuyi/graphrag/tree/master/config"
    click G1 "https://github.com/israel-adewuyi/graphrag/blob/master/config/color_map.py"
    click G2 "https://github.com/israel-adewuyi/graphrag/blob/master/config/entities.py"
    click G3 "https://github.com/israel-adewuyi/graphrag/blob/master/config/transcript_link.py"
    click H "https://github.com/israel-adewuyi/graphrag/tree/master/utils"
    click H1 "https://github.com/israel-adewuyi/graphrag/blob/master/utils/draw_graphs.py"
    click H2 "https://github.com/israel-adewuyi/graphrag/blob/master/utils/token_counter.py"
    click I "https://github.com/israel-adewuyi/graphrag/blob/master/.devcontainer"

    %% Styles
    classDef data fill:#FFEEAD,stroke:#333,stroke-width:2px,color:#000;
    classDef logic fill:#AEDFF7,stroke:#333,stroke-width:2px,color:#000;
    classDef presentation fill:#C1E1C1,stroke:#333,stroke-width:2px,color:#000;
    classDef config fill:#E2D1F9,stroke:#333,stroke-width:2px,color:#000;
    classDef file fill:#F5F5F5,stroke:#999,stroke-width:1px,color:#000;
```
