Merge branch 'main' into handle-stream-cancel-error

This commit is contained in:
yangdx
2025-02-05 12:27:05 +08:00
21 changed files with 489 additions and 139 deletions

View File

@@ -36,6 +36,7 @@ This repository hosts the code of LightRAG. The structure of this code is based
</div> </div>
## 🎉 News ## 🎉 News
- [x] [2025.02.05]🎯📢Our team has released [VideoRAG](https://github.com/HKUDS/VideoRAG) for processing and understanding extremely long-context videos.
- [x] [2025.01.13]🎯📢Our team has released [MiniRAG](https://github.com/HKUDS/MiniRAG) making RAG simpler with small models. - [x] [2025.01.13]🎯📢Our team has released [MiniRAG](https://github.com/HKUDS/MiniRAG) making RAG simpler with small models.
- [x] [2025.01.06]🎯📢You can now [use PostgreSQL for Storage](#using-postgresql-for-storage). - [x] [2025.01.06]🎯📢You can now [use PostgreSQL for Storage](#using-postgresql-for-storage).
- [x] [2024.12.31]🎯📢LightRAG now supports [deletion by document ID](https://github.com/HKUDS/LightRAG?tab=readme-ov-file#delete). - [x] [2024.12.31]🎯📢LightRAG now supports [deletion by document ID](https://github.com/HKUDS/LightRAG?tab=readme-ov-file#delete).
@@ -1058,6 +1059,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) The documentation can be found [here](lightrag/api/README.md)
## Graph viewer
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)
## Star History ## Star History
<a href="https://star-history.com/#HKUDS/LightRAG&Date"> <a href="https://star-history.com/#HKUDS/LightRAG&Date">

View File

@@ -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

View File

@@ -1,5 +1,5 @@
from .lightrag import LightRAG as LightRAG, QueryParam as QueryParam from .lightrag import LightRAG as LightRAG, QueryParam as QueryParam
__version__ = "1.1.4" __version__ = "1.1.5"
__author__ = "Zirui Guo" __author__ = "Zirui Guo"
__url__ = "https://github.com/HKUDS/LightRAG" __url__ = "https://github.com/HKUDS/LightRAG"

View File

@@ -1 +1 @@
__api_version__ = "1.0.3" __api_version__ = "1.0.4"

View File

@@ -557,7 +557,14 @@ class DocumentManager:
def __init__( def __init__(
self, self,
input_dir: str, 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.input_dir = Path(input_dir)
self.supported_extensions = supported_extensions self.supported_extensions = supported_extensions

View File

@@ -2,11 +2,14 @@ import os
from tqdm.asyncio import tqdm as tqdm_async from tqdm.asyncio import tqdm as tqdm_async
from dataclasses import dataclass from dataclasses import dataclass
import pipmaster as pm import pipmaster as pm
import np import numpy as np
if not pm.is_installed("pymongo"): if not pm.is_installed("pymongo"):
pm.install("pymongo") pm.install("pymongo")
if not pm.is_installed("motor"):
pm.install("motor")
from pymongo import MongoClient from pymongo import MongoClient
from motor.motor_asyncio import AsyncIOMotorClient from motor.motor_asyncio import AsyncIOMotorClient
from typing import Union, List, Tuple from typing import Union, List, Tuple

View File

@@ -447,7 +447,7 @@ class PGDocStatusStorage(DocStatusStorage):
sql = "select * from LIGHTRAG_DOC_STATUS where workspace=$1 and id=$2" sql = "select * from LIGHTRAG_DOC_STATUS where workspace=$1 and id=$2"
params = {"workspace": self.db.workspace, "id": id} params = {"workspace": self.db.workspace, "id": id}
result = await self.db.query(sql, params, True) result = await self.db.query(sql, params, True)
if result is None: if result is None or result == []:
return None return None
else: else:
return DocProcessingStatus( return DocProcessingStatus(

View File

@@ -372,12 +372,23 @@ class LightRAG:
# 3. Filter out already processed documents # 3. Filter out already processed documents
# _add_doc_keys = await self.doc_status.filter_keys(list(new_docs.keys())) # _add_doc_keys = await self.doc_status.filter_keys(list(new_docs.keys()))
_add_doc_keys = { _add_doc_keys = set()
doc_id for doc_id in new_docs.keys():
for doc_id in new_docs.keys() current_doc = await self.doc_status.get_by_id(doc_id)
if (current_doc := await self.doc_status.get_by_id(doc_id)) is None
or current_doc.status == DocStatus.FAILED if current_doc is None:
} _add_doc_keys.add(doc_id)
continue # skip to the next doc_id
status = None
if isinstance(current_doc, dict):
status = current_doc["status"]
else:
status = current_doc.status
if status == DocStatus.FAILED:
_add_doc_keys.add(doc_id)
new_docs = {k: v for k, v in new_docs.items() if k in _add_doc_keys} new_docs = {k: v for k, v in new_docs.items() if k in _add_doc_keys}
if not new_docs: if not new_docs:

View File

@@ -38,8 +38,8 @@
1. **启动程序**: 1. **启动程序**:
```bash ```bash
python -m pip install -r requirements.txt pip install lightrag-hku[tools]
python graph_visualizer.py lightrag-viewer
``` ```
2. **加载字体**: 2. **加载字体**:

View File

@@ -0,0 +1,136 @@
# 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.
![image](https://github.com/user-attachments/assets/b0d86184-99fc-468c-96ed-c611f14292bf)
## 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/HKUDS/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.

View File

@@ -0,0 +1,92 @@
Copyright (c) 2023 Vercel, in collaboration with basement.studio
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION AND CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

View File

@@ -0,0 +1,93 @@
Copyright (c) 2022--2024, atelierAnchor <https://atelier-anchor.com>,
with Reserved Font Name <Smiley> and <得意黑>.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

View File

@@ -1,6 +1,6 @@
""" """
3D GraphML Viewer using Dear ImGui and ModernGL 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 Description: An interactive 3D GraphML viewer using imgui_bundle and ModernGL
Version: 2.0 Version: 2.0
""" """
@@ -8,6 +8,18 @@ Version: 2.0
from typing import Optional, Tuple, Dict, List from typing import Optional, Tuple, Dict, List
import numpy as np import numpy as np
import networkx as nx 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")
if not pm.is_installed("python-louvain"):
pm.install("python-louvain")
import moderngl import moderngl
from imgui_bundle import imgui, immapp, hello_imgui from imgui_bundle import imgui, immapp, hello_imgui
import community import community
@@ -20,6 +32,9 @@ import os
CUSTOM_FONT = "font.ttf" CUSTOM_FONT = "font.ttf"
DEFAULT_FONT_ENG = "Geist-Regular.ttf"
DEFAULT_FONT_CHI = "SmileySans-Oblique.ttf"
class Node3D: class Node3D:
"""Class representing a 3D node in the graph""" """Class representing a 3D node in the graph"""
@@ -172,6 +187,10 @@ class GraphViewer:
np.sin(np.radians(self.pitch)), np.sin(np.radians(self.pitch)),
) )
) )
if not imgui.is_window_hovered():
return
if io.mouse_wheel != 0: if io.mouse_wheel != 0:
self.move_speed += io.mouse_wheel * 0.05 self.move_speed += io.mouse_wheel * 0.05
self.move_speed = np.max([self.move_speed, 0.01]) self.move_speed = np.max([self.move_speed, 0.01])
@@ -502,6 +521,14 @@ class GraphViewer:
def load_file(self, filepath: str): def load_file(self, filepath: str):
"""Load a GraphML file with error handling""" """Load a GraphML file with error handling"""
try: try:
# Clear existing data
self.id_node_map.clear()
self.nodes.clear()
self.selected_node = None
self.highlighted_node = None
self.setup_buffers()
# Load new graph
self.graph = nx.read_graphml(filepath) self.graph = nx.read_graphml(filepath)
self.calculate_layout() self.calculate_layout()
self.update_buffers() self.update_buffers()
@@ -672,10 +699,6 @@ class GraphViewer:
self.position, self.position + self.front, self.up self.position, self.position + self.front, self.up
) )
io = imgui.get_io()
self.window_width = int(io.display_size.x)
self.window_height = int(io.display_size.y)
aspect_ratio = self.window_width / self.window_height aspect_ratio = self.window_width / self.window_height
self.proj_matrix = glm.perspective( self.proj_matrix = glm.perspective(
glm.radians(60.0), # FOV glm.radians(60.0), # FOV
@@ -839,7 +862,7 @@ class GraphViewer:
def render(self): def render(self):
"""Render the graph""" """Render the graph"""
# Clear screen # Clear screen
self.glctx.clear(*self.background_color) self.glctx.clear(*self.background_color, depth=1)
if not self.graph: if not self.graph:
return return
@@ -886,11 +909,15 @@ class GraphViewer:
# Render id map # Render id map
self.render_id_map(mvp) self.render_id_map(mvp)
def render_labels(self):
# Render labels if enabled # Render labels if enabled
if self.show_labels: if self.show_labels and self.nodes:
# Save current font scale # Save current font scale
original_scale = imgui.get_font_size() original_scale = imgui.get_font_size()
self.update_view_proj_matrix()
mvp = self.proj_matrix * self.view_matrix
for node in self.nodes: for node in self.nodes:
# Project node position to screen space # Project node position to screen space
pos = mvp * glm.vec4( pos = mvp * glm.vec4(
@@ -1013,13 +1040,39 @@ def create_sphere(sectors: int = 32, rings: int = 16) -> Tuple:
return (vbo_vertices, vbo_elements) return (vbo_vertices, vbo_elements)
def draw_text_with_bg(
text: str,
text_pos: imgui.ImVec2Like,
text_size: imgui.ImVec2Like,
bg_color: int,
):
imgui.get_window_draw_list().add_rect_filled(
(text_pos[0] - 5, text_pos[1] - 5),
(text_pos[0] + text_size[0] + 5, text_pos[1] + text_size[1] + 5),
bg_color,
3.0,
)
imgui.set_cursor_pos(text_pos)
imgui.text(text)
def main(): def main():
"""Main application entry point""" """Main application entry point"""
viewer = GraphViewer() viewer = GraphViewer()
show_fps = True
text_bg_color = imgui.IM_COL32(0, 0, 0, 100)
def gui(): def gui():
if not viewer.initialized: if not viewer.initialized:
viewer.setup() viewer.setup()
# # Change the theme
# tweaked_theme = hello_imgui.get_runner_params().imgui_window_params.tweaked_theme
# tweaked_theme.theme = hello_imgui.ImGuiTheme_.darcula_darker
# hello_imgui.apply_tweaked_theme(tweaked_theme)
viewer.window_width = int(imgui.get_window_width())
viewer.window_height = int(imgui.get_window_height())
# Handle keyboard and mouse input # Handle keyboard and mouse input
viewer.handle_keyboard_input() viewer.handle_keyboard_input()
@@ -1089,11 +1142,34 @@ def main():
# Render graph settings window # Render graph settings window
viewer.render_settings() viewer.render_settings()
window_bg_color.w = 0.0 # Render FPS
if show_fps:
imgui.set_window_font_scale(1)
fps_text = f"FPS: {hello_imgui.frame_rate():.1f}"
text_size = imgui.calc_text_size(fps_text)
cursor_pos = (10, viewer.window_height - text_size.y - 10)
draw_text_with_bg(fps_text, cursor_pos, text_size, text_bg_color)
# Render highlighted node ID
if viewer.highlighted_node:
imgui.set_window_font_scale(1)
node_text = f"Node ID: {viewer.highlighted_node.label}"
text_size = imgui.calc_text_size(node_text)
cursor_pos = (
viewer.window_width - text_size.x - 10,
viewer.window_height - text_size.y - 10,
)
draw_text_with_bg(node_text, cursor_pos, text_size, text_bg_color)
window_bg_color.w = 0
style.set_color_(imgui.Col_.window_bg.value, window_bg_color) style.set_color_(imgui.Col_.window_bg.value, window_bg_color)
# Render the graph # Render labels
viewer.render() viewer.render_labels()
def custom_background():
if viewer.initialized:
viewer.render()
runner_params = hello_imgui.RunnerParams() runner_params = hello_imgui.RunnerParams()
runner_params.app_window_params.window_geometry.size = ( runner_params.app_window_params.window_geometry.size = (
@@ -1102,47 +1178,48 @@ def main():
) )
runner_params.app_window_params.window_title = "3D GraphML Viewer" runner_params.app_window_params.window_title = "3D GraphML Viewer"
runner_params.callbacks.show_gui = gui runner_params.callbacks.show_gui = gui
addons = immapp.AddOnsParams() runner_params.callbacks.custom_background = custom_background
addons.with_markdown = True
def load_font(): def load_font():
io = imgui.get_io()
io.fonts.add_font_default()
# Load font for Chinese character support
# You will need to provide it yourself, or use another font. # You will need to provide it yourself, or use another font.
font_filename = CUSTOM_FONT font_filename = CUSTOM_FONT
if not os.path.exists("assets/" + font_filename): io = imgui.get_io()
io.fonts.tex_desired_width = 4096 # Larger texture for better CJK font quality
font_size_pixels = 14
asset_dir = os.path.join(os.path.dirname(__file__), "assets")
# Try to load custom font
if not os.path.isfile(font_filename):
font_filename = os.path.join(asset_dir, font_filename)
if os.path.isfile(font_filename):
custom_font = io.fonts.add_font_from_file_ttf(
filename=font_filename,
size_pixels=font_size_pixels,
glyph_ranges_as_int_list=io.fonts.get_glyph_ranges_chinese_full(),
)
io.font_default = custom_font
return return
# Get the full Chinese character range for ImGui # Load default fonts
# This includes all Chinese characters supported by ImGui io.fonts.add_font_from_file_ttf(
cn_glyph_ranges_imgui = imgui.get_io().fonts.get_glyph_ranges_chinese_full() filename=os.path.join(asset_dir, DEFAULT_FONT_ENG),
size_pixels=font_size_pixels,
# Set up font loading parameters with Chinese character support
font_loading_params = hello_imgui.FontLoadingParams()
font_loading_params.glyph_ranges = hello_imgui.translate_common_glyph_ranges(
cn_glyph_ranges_imgui
) )
custom_font = hello_imgui.load_font(font_filename, 16.0, font_loading_params)
# # Merge with default font font_config = imgui.ImFontConfig()
# font_config = imgui.ImFontConfig() font_config.merge_mode = True
# font_config.merge_mode = True
# custom_font = io.fonts.add_font_from_file_ttf(
# filename= "assets/" + font_filename,
# size_pixels=16.0,
# font_cfg=font_config,
# glyph_ranges_as_int_list=cn_glyph_ranges_imgui,
# )
io.fonts.tex_desired_width = 4096 # Larger texture for better CJK font quality io.font_default = io.fonts.add_font_from_file_ttf(
io.font_default = custom_font filename=os.path.join(asset_dir, DEFAULT_FONT_CHI),
size_pixels=font_size_pixels,
font_cfg=font_config,
glyph_ranges_as_int_list=io.fonts.get_glyph_ranges_chinese_full(),
)
runner_params.callbacks.load_additional_fonts = load_font runner_params.callbacks.load_additional_fonts = load_font
immapp.run(runner_params, addons) immapp.run(runner_params)
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -62,6 +62,16 @@ def read_api_requirements():
return api_deps return api_deps
def read_extra_requirements():
api_deps = []
try:
with open("./lightrag/tools/lightrag_visualizer/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() metadata = retrieve_metadata()
long_description = read_long_description() long_description = read_long_description()
requirements = read_requirements() requirements = read_requirements()
@@ -97,10 +107,12 @@ setuptools.setup(
}, },
extras_require={ extras_require={
"api": read_api_requirements(), # API requirements as optional "api": read_api_requirements(), # API requirements as optional
"tools": read_extra_requirements(), # API requirements as optional
}, },
entry_points={ entry_points={
"console_scripts": [ "console_scripts": [
"lightrag-server=lightrag.api.lightrag_server:main [api]", "lightrag-server=lightrag.api.lightrag_server:main [api]",
"lightrag-viewer=lightrag.tools.lightrag_visualizer.graph_visualizer:main [tools]",
], ],
}, },
) )