File size: 10,914 Bytes
a29b2f1
e67921d
 
a29b2f1
 
 
e67921d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a29b2f1
e67921d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
---
title: test
app_file: app.py
sdk: gradio
sdk_version: 5.1.0
---
#  πŸ•ΈοΈ GraphRAG Local

Welcome to **GraphRAG Local with Index/Prompt-Tuning and Querying/Chat UIs**! This project is an adaptation of Microsoft's [GraphRAG](https://github.com/microsoft/graphrag), tailored to support local models and featuring a comprehensive interactive user interface ecosystem. 

## πŸ“„ Research Paper

For more details on the original GraphRAG implementation, please refer to the [GraphRAG paper](https://arxiv.org/pdf/2404.16130).

## 🌟 Features

- **API-Centric Architecture:** A robust FastAPI-based server (`api.py`) serving as the core of the GraphRAG operations.
- **Dedicated Indexing and Prompt Tuning UI:** A separate Gradio-based interface (`index_app.py`) for managing indexing and prompt tuning processes.
- **Local Model Support:** Leverage local models for LLM and embeddings, including compatibility with Ollama and OpenAI-compatible APIs.
- **Cost-Effective:** Eliminate dependency on costly cloud-based models by using your own local models.
- **Interactive UI:** User-friendly interface for managing data, running queries, and visualizing results (main app).
- **Real-time Graph Visualization:** Visualize your knowledge graph in 2D or 3D using Plotly (main app).
- **File Management:** Upload, view, edit, and delete input files directly from the UI.
- **Settings Management:** Easily update and manage your GraphRAG settings through the UI.
- **Output Exploration:** Browse and view indexing outputs and artifacts.
- **Logging:** Real-time logging for better debugging and monitoring.
- **Flexible Querying:** Support for global, local, and direct chat queries with customizable parameters (main app).
- **Customizable Visualization:** Adjust graph layout, node sizes, colors, and more to suit your preferences (main app).

![GraphRAG UI](uiv3.png)

## πŸ—ΊοΈ Roadmap

### **Important Note:** *Updates have been slow due to the day job and lack of immediate time, but I promise I am working on errors/issues in the background when able to. Please feel free to contribute/create a PR if you want to help out and find a great solution to an issue presented.* 
**The GraphRAG Local UI ecosystem is currently undergoing a major transition. While the main app remains functional, I am actively developing separate applications for Indexing/Prompt Tuning and Querying/Chat, all built around a robust central API. Users should expect some changes and potential instability during this transition period.**

*While it is currently functional, it has only been primarily tested on a Mac Studio M2.*

My vision for the GraphRAG Local UI ecosystem is to become the ultimate set of tools for working with GraphRAG and local LLMs, incorporating as many cool features and knowledge graph tools as possible. I am continuously working on improvements and new features.

### Recent Updates
- [x] New API-centric architecture (`api.py`)
- [x] Dedicated Indexing and Prompt Tuning UI (`index_app.py`)
- [x] Improved file management and output exploration
- [x] Background task handling for long-running operations
- [x] Enhanced configuration options through environment variables and YAML files

### Upcoming Features
- [ ] Dedicated Querying/Chat UI that interacts with the API
- [ ] Dockerfile for easier deployment
- [ ] Launch your own GraphRAG API server for use in external applications
- [ ] Experimental: Mixture of Agents for Indexing/Query of knowledge graph
- [ ] Support for more file formats (CSV, PDF, etc.)
- [ ] Web search/Scraping capabilities
- [ ] Advanced graph analysis tools
- [ ] Integration with popular knowledge management tools
- [ ] Collaborative features for team-based knowledge graph building

I am committed to making the GraphRAG Local UI ecosystem the most comprehensive and user-friendly toolset for working with knowledge graphs and LLMs. Your feedback and suggestions are much needed in shaping the future of this project.

Feel free to open an Issue if you run into an error, and I will try to address it as soon as possible to minimize any downtime you might experience.

---

## πŸ“¦ Installation and Setup

Follow these steps to set up and run the GraphRAG Local UI ecosystem:

1. **Create and activate a new conda environment:**
    ```bash
    conda create -n graphrag-local -y
    conda activate graphrag-local
    ```

2. **Install the required packages:**

    First install the GraphRAG dir from this repo (has changes not present in the Microsoft repo):

    ```bash
    pip install -e ./graphrag
    ```

    Then install the rest of the dependencies:

    ```bash
    pip install -r requirements.txt
    ```

3. **Launch the API server:**
    ```bash
    python api.py --host 0.0.0.0 --port 8012 --reload
    ```

4. **If using Ollama for embeddings, launch the embedding proxy:**
    ```bash
    python embedding_proxy.py --port 11435 --host http://localhost:11434
    ```
    Note: For detailed instructions on using Ollama embeddings with GraphRAG, refer to the EMBEDDING_PROXY_README.md file.

5. **Launch the Indexing and Prompt Tuning UI:**
    ```bash
    gradio index_app.py
    ```

6. **Launch the main interactive UI (legacy app):**
    ```bash
    gradio app.py
    ```
    or
    ```bash
    python app.py
    ```

7. **Access the UIs:**
    - Indexing and Prompt Tuning UI: Open your web browser and navigate to `http://localhost:7861`
    - Main UI (legacy): Open your web browser and navigate to `http://localhost:7860`

---

## πŸš€ Getting Started with GraphRAG Local

GraphRAG is designed for flexibility, allowing you to quickly create and initialize your own indexing directory. Follow these steps to set up your environment:

### 1. Create the Indexing Directory

This repo comes with a pre-made Indexing folder but you may want to make your own, so here are the steps. First, create the required directory structure for your input data and indexing results:

```bash
mkdir -p ./indexing/input
```

This directory will store:
- Input .txt files for indexing
- Output results
- Prompts for Prompt Tuning

### 2. Add Sample Data (Optional)

If you want to start with sample data, copy it to your new input directory:

```bash
cp input/* ./indexing/input
```

You can also add your own .txt files to this directory for indexing.

### 3. Initialize the Indexing Folder

Run the following command to initialize the ./indexing folder with the required files:

```bash
python -m graphrag.index --init --root ./indexing
```

### 4. Configure Settings

Move the pre-configured `settings.yaml` file to your indexing directory:

```bash
mv settings.yaml ./indexing
```

This file contains the main configuration, pre-set for use with local models.

### 5. Customization

You can customize your setup by modifying the following environment variables:
- `ROOT_DIR`: Points to your main indexing directory
- `INPUT_DIR`: Specifies the location of your input files

### πŸ“š Additional Resources

For more detailed information and advanced usage, refer to the [official GraphRAG documentation](https://microsoft.github.io/graphrag/posts/get_started/).

---

## πŸ–₯️ GraphRAG Application Ecosystem

The GraphRAG Local UI ecosystem consists of three main components, each serving a specific purpose in the knowledge graph creation and querying process:

### 1. Core API (`api.py`)

The `api.py` file serves as the backbone of the GraphRAG system, providing a robust FastAPI-based server that handles all core operations.

Key features:
- Manages indexing and prompt tuning processes
- Handles various query types (local, global, and direct chat)
- Integrates with local LLM and embedding models
- Provides endpoints for file management and system configuration

Usage:
```bash
python api.py --host 0.0.0.0 --port 8012 --reload
```

Note: If using Ollama for embeddings, make sure to run the embedding proxy (`embedding_proxy.py`) alongside `api.py`. Refer to the EMBEDDING_PROXY_README.md for detailed instructions.

### 2. Indexing and Prompt Tuning UI (`index_app.py`)

#### Workflow Integration

1. Start the Core API (`api.py`) to enable backend functionality.
2. If using Ollama for embeddings, start the embedding proxy (`embedding_proxy.py`).
3. Use the Indexing and Prompt Tuning UI (`index_app.py`) to prepare your data and fine-tune the system.
4. (Optional) Use the Main Interactive UI (`app.py`) for visualization and legacy features.

This modular approach allows for greater flexibility and easier maintenance of the GraphRAG system. As development continues, the functionality of `app.py` will be gradually integrated into new, specialized interfaces that interact with the core API.

### 2. Indexing and Prompt Tuning UI (`index_app.py`)

The `index_app.py` file provides a user-friendly Gradio interface for managing the indexing and prompt tuning processes.

Key features:
- Configure and run indexing tasks
- Set up and execute prompt tuning
- Manage input files and explore output data
- Adjust LLM and embedding settings

Usage:
```bash
python index_app.py
```
Access the UI at `http://localhost:7861`

### 3. Main Interactive UI (Legacy App) (`app.py`)

The `app.py` file is the pre-existing main application, which is being phased out but still provides useful functionality.

Key features:
- Visualize knowledge graphs in 2D or 3D
- Run queries and view results
- Manage GraphRAG settings
- Explore indexed data

Usage:
```bash
python app.py
```
or
```bash
gradio app.py
```
Access the UI at `http://localhost:7860`

### Workflow Integration

1. Start the Core API (`api.py`) to enable backend functionality.
2. Use the Indexing and Prompt Tuning UI (`index_app.py`) to prepare your data and fine-tune the system.
3. (Optional) Use the Main Interactive UI (`app.py`) for visualization and legacy features.

This modular approach allows for greater flexibility and easier maintenance of the GraphRAG system. As development continues, the functionality of `app.py` will be gradually integrated into new, specialized interfaces that interact with the core API.

---

## πŸ“š Citations

- Original GraphRAG repository by Microsoft: [GraphRAG](https://github.com/microsoft/graphrag)
- This project took inspiration and used the GraphRAG4OpenWebUI repository by win4r (https://github.com/win4r/GraphRAG4OpenWebUI) as a starting point for the API implementation.

---

## Troubleshooting

- If you encounter any issues with the new API or Indexing UI, please check the console logs for detailed error messages.
- For the main app, if you can't run `gradio app.py`, try running `pip install --upgrade gradio` and then exit out and start a new terminal. It should then load and launch properly as a Gradio app.
- On Windows, if you run into an encoding/UTF error, you can change it to the correct format in the YAML Settings menu.

For any issues or feature requests, please open an issue on the GitHub repository. Happy knowledge graphing!