From c65dcff9918c831d040f4b2135c877d747952196 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Sun, 2 Feb 2025 09:47:05 +0100 Subject: [PATCH 1/7] Fixed a typo --- lightrag/api/lightrag_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightrag/api/lightrag_server.py b/lightrag/api/lightrag_server.py index 5e3c9585..f7770c57 100644 --- a/lightrag/api/lightrag_server.py +++ b/lightrag/api/lightrag_server.py @@ -556,7 +556,7 @@ class DocumentManager: def __init__( self, input_dir: str, - supported_extensions: tuple = (".txt", ".md", ".pdf", ".docx", ".pptx", "xlsx"), + supported_extensions: tuple = (".txt", ".md", ".pdf", ".docx", ".pptx", ".xlsx"), ): self.input_dir = Path(input_dir) self.supported_extensions = supported_extensions From 9a30dc7b04d5af5b57fe44f6bc22e7480307e145 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Mon, 3 Feb 2025 22:51:46 +0100 Subject: [PATCH 2/7] Integrated the graphml visualizer as part of lightrag and made it a component that can be installed using [tools] option --- README.md | 6 + .../OpenWebuiTool/openwebui_tool.py | 0 extra/VisualizationTool/README.md | 88 ------------ lightrag/__init__.py | 2 +- lightrag/api/__init__.py | 2 +- lightrag/api/lightrag_server.py | 9 +- .../tools/__init__.py | 0 .../tools/lightrag_visualizer}/README-zh.md | 0 lightrag/tools/lightrag_visualizer/README.md | 135 ++++++++++++++++++ .../tools/lightrag_visualizer/__init__.py | 12 +- .../assets/place_font_here | 0 .../lightrag_visualizer}/requirements.txt | 0 setup.py | 12 ++ 13 files changed, 174 insertions(+), 92 deletions(-) rename {extra => external_bindings}/OpenWebuiTool/openwebui_tool.py (100%) delete mode 100644 extra/VisualizationTool/README.md rename extra/VisualizationTool/assets/place_font_here => lightrag/tools/__init__.py (100%) rename {extra/VisualizationTool => lightrag/tools/lightrag_visualizer}/README-zh.md (100%) create mode 100644 lightrag/tools/lightrag_visualizer/README.md rename extra/VisualizationTool/graph_visualizer.py => lightrag/tools/lightrag_visualizer/__init__.py (99%) create mode 100644 lightrag/tools/lightrag_visualizer/assets/place_font_here rename {extra/VisualizationTool => lightrag/tools/lightrag_visualizer}/requirements.txt (100%) diff --git a/README.md b/README.md index dd570608..49c092cb 100644 --- a/README.md +++ b/README.md @@ -1058,6 +1058,12 @@ LightRag can be installed with API support to serve a Fast api interface to perf The documentation can be found [here](lightrag/api/README.md) +## Graph viewer +LightRag can be installed with API support to serve a Fast api interface to perform data upload and indexing/Rag operations/Rescan of the input folder etc.. + +The documentation can be found [here](lightrag/tools/lightrag_visualizer/README.md) + + ## Star History diff --git a/extra/OpenWebuiTool/openwebui_tool.py b/external_bindings/OpenWebuiTool/openwebui_tool.py similarity index 100% rename from extra/OpenWebuiTool/openwebui_tool.py rename to external_bindings/OpenWebuiTool/openwebui_tool.py diff --git a/extra/VisualizationTool/README.md b/extra/VisualizationTool/README.md deleted file mode 100644 index a2581703..00000000 --- a/extra/VisualizationTool/README.md +++ /dev/null @@ -1,88 +0,0 @@ -# 3D GraphML Viewer - -An interactive 3D graph visualization tool based on Dear ImGui and ModernGL. - -## Features - -- **3D Interactive Visualization**: High-performance 3D graphics rendering using ModernGL -- **Multiple Layout Algorithms**: Support for various graph layouts - - Spring layout - - Circular layout - - Shell layout - - Random layout -- **Community Detection**: Automatic detection and visualization of graph community structures -- **Interactive Controls**: - - WASD + QE keys for camera movement - - Right mouse drag for view angle control - - Node selection and highlighting - - Adjustable node size and edge width - - Configurable label display - - Quick navigation between node connections - -## Tech Stack - -- **imgui_bundle**: User interface -- **ModernGL**: OpenGL graphics rendering -- **NetworkX**: Graph data structures and algorithms -- **NumPy**: Numerical computations -- **community**: Community detection - -## Usage - -1. **Launch the Program**: - ```bash - python -m pip install -r requirements.txt - python graph_visualizer.py - ``` - -2. **Load Font**: - - Place the font file `font.ttf` in the `assets` directory - - Or modify the `CUSTOM_FONT` constant to use a different font file - -3. **Load Graph File**: - - Click the "Load GraphML" button in the interface - - Select a graph file in GraphML format - -4. **Interactive Controls**: - - **Camera Movement**: - - W: Move forward - - S: Move backward - - A: Move left - - D: Move right - - Q: Move up - - E: Move down - - **View Control**: - - Hold right mouse button and drag to rotate view - - **Node Interaction**: - - Hover mouse to highlight nodes - - Click to select nodes - -5. **Visualization Settings**: - - Adjustable via UI control panel: - - Layout type - - Node size - - Edge width - - Label visibility - - Label size - - Background color - -## Customization Options - -- **Node Scaling**: Adjust node size via `node_scale` parameter -- **Edge Width**: Modify edge width using `edge_width` parameter -- **Label Display**: Toggle label visibility with `show_labels` -- **Label Size**: Adjust label size using `label_size` -- **Label Color**: Set label color through `label_color` -- **View Distance**: Control maximum label display distance with `label_culling_distance` - -## Performance Optimizations - -- Efficient graphics rendering using ModernGL -- View distance culling for label display optimization -- Community detection algorithms for optimized visualization of large-scale graphs - -## System Requirements - -- Python 3.10+ -- Graphics card with OpenGL 3.3+ support -- Supported Operating Systems: Windows/Linux/MacOS diff --git a/lightrag/__init__.py b/lightrag/__init__.py index 12bd2ea9..d68bded0 100644 --- a/lightrag/__init__.py +++ b/lightrag/__init__.py @@ -1,5 +1,5 @@ from .lightrag import LightRAG as LightRAG, QueryParam as QueryParam -__version__ = "1.1.4" +__version__ = "1.1.5" __author__ = "Zirui Guo" __url__ = "https://github.com/HKUDS/LightRAG" diff --git a/lightrag/api/__init__.py b/lightrag/api/__init__.py index 70239ed3..9f0b3540 100644 --- a/lightrag/api/__init__.py +++ b/lightrag/api/__init__.py @@ -1 +1 @@ -__api_version__ = "1.0.3" +__api_version__ = "1.0.4" diff --git a/lightrag/api/lightrag_server.py b/lightrag/api/lightrag_server.py index 2680a2ec..27ce8a8d 100644 --- a/lightrag/api/lightrag_server.py +++ b/lightrag/api/lightrag_server.py @@ -557,7 +557,14 @@ class DocumentManager: def __init__( self, input_dir: str, - supported_extensions: tuple = (".txt", ".md", ".pdf", ".docx", ".pptx", ".xlsx"), + supported_extensions: tuple = ( + ".txt", + ".md", + ".pdf", + ".docx", + ".pptx", + ".xlsx", + ), ): self.input_dir = Path(input_dir) self.supported_extensions = supported_extensions diff --git a/extra/VisualizationTool/assets/place_font_here b/lightrag/tools/__init__.py similarity index 100% rename from extra/VisualizationTool/assets/place_font_here rename to lightrag/tools/__init__.py diff --git a/extra/VisualizationTool/README-zh.md b/lightrag/tools/lightrag_visualizer/README-zh.md similarity index 100% rename from extra/VisualizationTool/README-zh.md rename to lightrag/tools/lightrag_visualizer/README-zh.md diff --git a/lightrag/tools/lightrag_visualizer/README.md b/lightrag/tools/lightrag_visualizer/README.md new file mode 100644 index 00000000..d708dc6d --- /dev/null +++ b/lightrag/tools/lightrag_visualizer/README.md @@ -0,0 +1,135 @@ +# LightRAG 3D Graph Viewer + +An interactive 3D graph visualization tool included in the LightRAG package for visualizing and analyzing RAG (Retrieval-Augmented Generation) graphs and other graph structures. + +## Installation + +### Quick Install +```bash +pip install lightrag-hku[tools] # Install with visualization tool only +# or +pip install lightrag-hku[api,tools] # Install with both API and visualization tools +``` + +## Launch the Viewer +```bash +lightrag-viewer +``` + +## Features + +- **3D Interactive Visualization**: High-performance 3D graphics rendering using ModernGL +- **Multiple Layout Algorithms**: Support for various graph layouts + - Spring layout + - Circular layout + - Shell layout + - Random layout +- **Community Detection**: Automatic detection and visualization of graph community structures +- **Interactive Controls**: + - WASD + QE keys for camera movement + - Right mouse drag for view angle control + - Node selection and highlighting + - Adjustable node size and edge width + - Configurable label display + - Quick navigation between node connections + +## Tech Stack + +- **imgui_bundle**: User interface +- **ModernGL**: OpenGL graphics rendering +- **NetworkX**: Graph data structures and algorithms +- **NumPy**: Numerical computations +- **community**: Community detection + +## Interactive Controls + +### Camera Movement +- W: Move forward +- S: Move backward +- A: Move left +- D: Move right +- Q: Move up +- E: Move down + +### View Control +- Hold right mouse button and drag to rotate view + +### Node Interaction +- Hover mouse to highlight nodes +- Click to select nodes + +## Visualization Settings + +Adjustable via UI control panel: +- Layout type +- Node size +- Edge width +- Label visibility +- Label size +- Background color + +## Customization Options + +- **Node Scaling**: Adjust node size via `node_scale` parameter +- **Edge Width**: Modify edge width using `edge_width` parameter +- **Label Display**: Toggle label visibility with `show_labels` +- **Label Size**: Adjust label size using `label_size` +- **Label Color**: Set label color through `label_color` +- **View Distance**: Control maximum label display distance with `label_culling_distance` + +## System Requirements + +- Python 3.9+ +- Graphics card with OpenGL 3.3+ support +- Supported Operating Systems: Windows/Linux/MacOS + +## Troubleshooting + +### Common Issues + +1. **Command Not Found** + ```bash + # Make sure you installed with the 'tools' option + pip install lightrag-hku[tools] + + # Verify installation + pip list | grep lightrag-hku + ``` + +2. **ModernGL Initialization Failed** + ```bash + # Check OpenGL version + glxinfo | grep "OpenGL version" + + # Update graphics drivers if needed + ``` + +3. **Font Loading Issues** + - The required fonts are included in the package + - If issues persist, check your graphics drivers + +## Usage with LightRAG + +The viewer is particularly useful for: +- Visualizing RAG knowledge graphs +- Analyzing document relationships +- Exploring semantic connections +- Debugging retrieval patterns + +## Performance Optimizations + +- Efficient graphics rendering using ModernGL +- View distance culling for label display optimization +- Community detection algorithms for optimized visualization of large-scale graphs + +## Support + +- GitHub Issues: [LightRAG Repository](https://github.com/URL-to-lightrag) +- Documentation: [LightRAG Docs](https://URL-to-docs) + +## License + +This tool is part of LightRAG and is distributed under the MIT License. See `LICENSE` for more information. + +Note: This visualization tool is an optional component of the LightRAG package. Install with the [tools] option to access the viewer functionality. + diff --git a/extra/VisualizationTool/graph_visualizer.py b/lightrag/tools/lightrag_visualizer/__init__.py similarity index 99% rename from extra/VisualizationTool/graph_visualizer.py rename to lightrag/tools/lightrag_visualizer/__init__.py index 9bbd6235..69552d8c 100644 --- a/extra/VisualizationTool/graph_visualizer.py +++ b/lightrag/tools/lightrag_visualizer/__init__.py @@ -1,6 +1,6 @@ """ 3D GraphML Viewer using Dear ImGui and ModernGL -Author: LoLLMs, ArnoChen +Author: ParisNeo, ArnoChen Description: An interactive 3D GraphML viewer using imgui_bundle and ModernGL Version: 2.0 """ @@ -8,6 +8,16 @@ Version: 2.0 from typing import Optional, Tuple, Dict, List import numpy as np import networkx as nx +import pipmaster as pm + +#Added automatic libraries install using pipmaster +if not pm.is_installed("moderngl"): + pm.install("moderngl") +if not pm.is_installed("imgui_bundle"): + pm.install("imgui_bundle") +if not pm.is_installed("pyglm"): + pm.install("pyglm") + import moderngl from imgui_bundle import imgui, immapp, hello_imgui import community diff --git a/lightrag/tools/lightrag_visualizer/assets/place_font_here b/lightrag/tools/lightrag_visualizer/assets/place_font_here new file mode 100644 index 00000000..e69de29b diff --git a/extra/VisualizationTool/requirements.txt b/lightrag/tools/lightrag_visualizer/requirements.txt similarity index 100% rename from extra/VisualizationTool/requirements.txt rename to lightrag/tools/lightrag_visualizer/requirements.txt diff --git a/setup.py b/setup.py index 38eff646..e080a1dd 100644 --- a/setup.py +++ b/setup.py @@ -62,6 +62,16 @@ def read_api_requirements(): return api_deps +def read_extra_requirements(): + api_deps = [] + try: + with open("./lightrag/extra/VisualizationTool/requirements.txt") as f: + api_deps = [line.strip() for line in f if line.strip()] + except FileNotFoundError: + print("Warning: API requirements.txt not found.") + return api_deps + + metadata = retrieve_metadata() long_description = read_long_description() requirements = read_requirements() @@ -97,10 +107,12 @@ setuptools.setup( }, extras_require={ "api": read_api_requirements(), # API requirements as optional + "tools": read_extra_requirements(), # API requirements as optional }, entry_points={ "console_scripts": [ "lightrag-server=lightrag.api.lightrag_server:main [api]", + "lightrag-viewer=lightrag.tools.lightrag_visualizer:main [tools]", ], }, ) From a55cf5d1ee9a1db42a53c6e1402e9184f0eb3c5e Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Mon, 3 Feb 2025 22:52:34 +0100 Subject: [PATCH 3/7] Update README.md --- lightrag/tools/lightrag_visualizer/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lightrag/tools/lightrag_visualizer/README.md b/lightrag/tools/lightrag_visualizer/README.md index d708dc6d..63ba95d9 100644 --- a/lightrag/tools/lightrag_visualizer/README.md +++ b/lightrag/tools/lightrag_visualizer/README.md @@ -2,6 +2,8 @@ An interactive 3D graph visualization tool included in the LightRAG package for visualizing and analyzing RAG (Retrieval-Augmented Generation) graphs and other graph structures. +![image](https://github.com/user-attachments/assets/b0d86184-99fc-468c-96ed-c611f14292bf) + ## Installation ### Quick Install From 57af1d1815406058bdab45328e0ca99a3a96ff5f Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Mon, 3 Feb 2025 22:54:26 +0100 Subject: [PATCH 4/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49c092cb..ee5519f5 100644 --- a/README.md +++ b/README.md @@ -1059,7 +1059,7 @@ LightRag can be installed with API support to serve a Fast api interface to perf The documentation can be found [here](lightrag/api/README.md) ## Graph viewer -LightRag can be installed with API support to serve a Fast api interface to perform data upload and indexing/Rag operations/Rescan of the input folder etc.. +LightRag can be installed with Tools support to add extra tools like the graphml 3d visualizer. The documentation can be found [here](lightrag/tools/lightrag_visualizer/README.md) From 61b06a3d1a97f6a5db8e0624102e9ec6cf870fed Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Mon, 3 Feb 2025 23:17:43 +0100 Subject: [PATCH 5/7] linting --- lightrag/tools/lightrag_visualizer/README.md | 5 ++--- lightrag/tools/lightrag_visualizer/__init__.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lightrag/tools/lightrag_visualizer/README.md b/lightrag/tools/lightrag_visualizer/README.md index 63ba95d9..14e9b344 100644 --- a/lightrag/tools/lightrag_visualizer/README.md +++ b/lightrag/tools/lightrag_visualizer/README.md @@ -93,7 +93,7 @@ Adjustable via UI control panel: ```bash # Make sure you installed with the 'tools' option pip install lightrag-hku[tools] - + # Verify installation pip list | grep lightrag-hku ``` @@ -102,7 +102,7 @@ Adjustable via UI control panel: ```bash # Check OpenGL version glxinfo | grep "OpenGL version" - + # Update graphics drivers if needed ``` @@ -134,4 +134,3 @@ The viewer is particularly useful for: This tool is part of LightRAG and is distributed under the MIT License. See `LICENSE` for more information. Note: This visualization tool is an optional component of the LightRAG package. Install with the [tools] option to access the viewer functionality. - diff --git a/lightrag/tools/lightrag_visualizer/__init__.py b/lightrag/tools/lightrag_visualizer/__init__.py index 69552d8c..ca6df8d7 100644 --- a/lightrag/tools/lightrag_visualizer/__init__.py +++ b/lightrag/tools/lightrag_visualizer/__init__.py @@ -10,7 +10,7 @@ import numpy as np import networkx as nx import pipmaster as pm -#Added automatic libraries install using pipmaster +# Added automatic libraries install using pipmaster if not pm.is_installed("moderngl"): pm.install("moderngl") if not pm.is_installed("imgui_bundle"): From 14b5adc15cc6ac159116aa7973450546918b915b Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Tue, 4 Feb 2025 00:26:22 +0100 Subject: [PATCH 6/7] minor fix --- lightrag/tools/lightrag_visualizer/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lightrag/tools/lightrag_visualizer/__init__.py b/lightrag/tools/lightrag_visualizer/__init__.py index ca6df8d7..b9c9e03a 100644 --- a/lightrag/tools/lightrag_visualizer/__init__.py +++ b/lightrag/tools/lightrag_visualizer/__init__.py @@ -17,6 +17,8 @@ if not pm.is_installed("imgui_bundle"): pm.install("imgui_bundle") if not pm.is_installed("pyglm"): pm.install("pyglm") +if not pm.is_installed("community"): + pm.install("community") import moderngl from imgui_bundle import imgui, immapp, hello_imgui From 6a4e1b140130ad20aeef8f0a7f6b9fab3ed60ff9 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Tue, 4 Feb 2025 00:28:33 +0100 Subject: [PATCH 7/7] fixed pipmaster install --- lightrag/tools/lightrag_visualizer/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lightrag/tools/lightrag_visualizer/__init__.py b/lightrag/tools/lightrag_visualizer/__init__.py index b9c9e03a..5cade237 100644 --- a/lightrag/tools/lightrag_visualizer/__init__.py +++ b/lightrag/tools/lightrag_visualizer/__init__.py @@ -17,8 +17,8 @@ if not pm.is_installed("imgui_bundle"): pm.install("imgui_bundle") if not pm.is_installed("pyglm"): pm.install("pyglm") -if not pm.is_installed("community"): - pm.install("community") +if not pm.is_installed("python-louvain"): + pm.install("python-louvain") import moderngl from imgui_bundle import imgui, immapp, hello_imgui