From bc5ccc5f1955d29a8a7c227d1f7933472aae3171 Mon Sep 17 00:00:00 2001 From: coredevorg <73153008+coredevorg@users.noreply.github.com> Date: Tue, 11 Mar 2025 10:39:55 +0000 Subject: [PATCH 1/9] Update Dockerfile and API requirements for improved build and dependencies - Add Rust installation to Dockerfile for potential performance improvements - Set explicit Docker data directories - Add graspologic library to API requirements - Optimize Docker build stages and environment setup --- Dockerfile | 16 +++++++++++++++- lightrag/api/requirements.txt | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c52f1ab3..edc6addb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,23 @@ # Build stage -FROM python:3.11-slim as builder +FROM python:3.11-slim AS builder WORKDIR /app +# Install Rust and required build dependencies +RUN apt-get update && apt-get install -y \ + curl \ + build-essential \ + pkg-config \ + && rm -rf /var/lib/apt/lists/* \ + && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ + && . $HOME/.cargo/env + # Copy only requirements files first to leverage Docker cache COPY requirements.txt . COPY lightrag/api/requirements.txt ./lightrag/api/ # Install dependencies +ENV PATH="/root/.cargo/bin:${PATH}" RUN pip install --user --no-cache-dir -r requirements.txt RUN pip install --user --no-cache-dir -r lightrag/api/requirements.txt @@ -28,6 +38,10 @@ ENV PATH=/root/.local/bin:$PATH # Create necessary directories RUN mkdir -p /app/data/rag_storage /app/data/inputs +# Docker data directories +ENV WORKING_DIR=/app/data/rag_storage +ENV INPUT_DIR=/app/data/inputs + # Expose the default port EXPOSE 9621 diff --git a/lightrag/api/requirements.txt b/lightrag/api/requirements.txt index 0e8e246b..f1662004 100644 --- a/lightrag/api/requirements.txt +++ b/lightrag/api/requirements.txt @@ -18,3 +18,4 @@ pytz tenacity tiktoken uvicorn +graspologic>=3.4.1 From 87474f7b2c72960257511dcada096718cef64a9d Mon Sep 17 00:00:00 2001 From: lvyb Date: Wed, 12 Mar 2025 16:57:51 +0800 Subject: [PATCH 2/9] fix stream --- lightrag/llm/openai.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lightrag/llm/openai.py b/lightrag/llm/openai.py index 70aa0ceb..d2174a67 100644 --- a/lightrag/llm/openai.py +++ b/lightrag/llm/openai.py @@ -123,18 +123,21 @@ async def openai_complete_if_cache( async def inner(): try: + _content = '' async for chunk in response: content = chunk.choices[0].delta.content if content is None: continue if r"\u" in content: content = safe_unicode_decode(content.encode("utf-8")) - yield content + _content += content + return _content except Exception as e: logger.error(f"Error in stream response: {str(e)}") raise - return inner() + response_content = await inner() + return response_content else: if ( From 5707aab6bda9dc7f4bc95839a1840ab9ec6a72be Mon Sep 17 00:00:00 2001 From: zrguo Date: Thu, 13 Mar 2025 22:16:56 +0800 Subject: [PATCH 3/9] fix existing justification bug --- lightrag/lightrag.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index a466e572..79d35813 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -1843,9 +1843,10 @@ class LightRAG: """ try: # 1. Get current entity information - node_data = await self.chunk_entity_relation_graph.get_node(entity_name) - if not node_data: + node_exists = await self.chunk_entity_relation_graph.has_node(entity_name) + if not node_exists: raise ValueError(f"Entity '{entity_name}' does not exist") + node_data = await self.chunk_entity_relation_graph.get_node(entity_name) # Check if entity is being renamed new_entity_name = updated_data.get("entity_name", entity_name) @@ -1858,7 +1859,7 @@ class LightRAG: "Entity renaming is not allowed. Set allow_rename=True to enable this feature" ) - existing_node = await self.chunk_entity_relation_graph.get_node( + existing_node = await self.chunk_entity_relation_graph.has_node( new_entity_name ) if existing_node: @@ -2040,14 +2041,16 @@ class LightRAG: """ try: # 1. Get current relation information - edge_data = await self.chunk_entity_relation_graph.get_edge( + edge_exists = await self.chunk_entity_relation_graph.has_edge( source_entity, target_entity ) - if not edge_data: + if not edge_exists: raise ValueError( f"Relation from '{source_entity}' to '{target_entity}' does not exist" ) - + edge_data = await self.chunk_entity_relation_graph.get_edge( + source_entity, target_entity + ) # Important: First delete the old relation record from the vector database old_relation_id = compute_mdhash_id( source_entity + target_entity, prefix="rel-" @@ -2156,7 +2159,7 @@ class LightRAG: """ try: # Check if entity already exists - existing_node = await self.chunk_entity_relation_graph.get_node(entity_name) + existing_node = await self.chunk_entity_relation_graph.has_node(entity_name) if existing_node: raise ValueError(f"Entity '{entity_name}' already exists") @@ -2250,7 +2253,7 @@ class LightRAG: raise ValueError(f"Target entity '{target_entity}' does not exist") # Check if relation already exists - existing_edge = await self.chunk_entity_relation_graph.get_edge( + existing_edge = await self.chunk_entity_relation_graph.has_edge( source_entity, target_entity ) if existing_edge: @@ -2383,9 +2386,10 @@ class LightRAG: # 1. Check if all source entities exist source_entities_data = {} for entity_name in source_entities: - node_data = await self.chunk_entity_relation_graph.get_node(entity_name) - if not node_data: + node_exists = await self.chunk_entity_relation_graph.has_node(entity_name) + if not node_exists: raise ValueError(f"Source entity '{entity_name}' does not exist") + node_data = await self.chunk_entity_relation_graph.get_node(entity_name) source_entities_data[entity_name] = node_data # 2. Check if target entity exists and get its data if it does From 78a4edeff5afd83ea9d413c79630e266783c6298 Mon Sep 17 00:00:00 2001 From: zrguo Date: Thu, 13 Mar 2025 22:20:55 +0800 Subject: [PATCH 4/9] fix linting --- lightrag/lightrag.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index 79d35813..c9dba28c 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -2386,7 +2386,9 @@ class LightRAG: # 1. Check if all source entities exist source_entities_data = {} for entity_name in source_entities: - node_exists = await self.chunk_entity_relation_graph.has_node(entity_name) + node_exists = await self.chunk_entity_relation_graph.has_node( + entity_name + ) if not node_exists: raise ValueError(f"Source entity '{entity_name}' does not exist") node_data = await self.chunk_entity_relation_graph.get_node(entity_name) From e6b55360a1aeae1fd293d5918cb810a2b62463a1 Mon Sep 17 00:00:00 2001 From: zrguo Date: Thu, 13 Mar 2025 23:12:42 +0800 Subject: [PATCH 5/9] fix merge bug --- lightrag/lightrag.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index c9dba28c..a8b11549 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -2398,10 +2398,10 @@ class LightRAG: target_exists = await self.chunk_entity_relation_graph.has_node( target_entity ) - target_entity_data = {} + existing_target_entity_data = {} if target_exists: - target_entity_data = await self.chunk_entity_relation_graph.get_node( - target_entity + existing_target_entity_data = ( + await self.chunk_entity_relation_graph.get_node(target_entity) ) logger.info( f"Target entity '{target_entity}' already exists, will merge data" @@ -2410,7 +2410,7 @@ class LightRAG: # 3. Merge entity data merged_entity_data = self._merge_entity_attributes( list(source_entities_data.values()) - + ([target_entity_data] if target_exists else []), + + ([existing_target_entity_data] if target_exists else []), merge_strategy, ) From 32f47286fde4fafe59fb571b6f74dd17a6d1962c Mon Sep 17 00:00:00 2001 From: zrguo Date: Fri, 14 Mar 2025 14:02:42 +0800 Subject: [PATCH 6/9] fix linting --- lightrag/api/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightrag/api/requirements.txt b/lightrag/api/requirements.txt index f1662004..afd76f5b 100644 --- a/lightrag/api/requirements.txt +++ b/lightrag/api/requirements.txt @@ -3,6 +3,7 @@ ascii_colors asyncpg distro fastapi +graspologic>=3.4.1 httpcore httpx jiter @@ -18,4 +19,3 @@ pytz tenacity tiktoken uvicorn -graspologic>=3.4.1 From f5ab76dc4c73798e3ed78124da02eefddf65a9a1 Mon Sep 17 00:00:00 2001 From: zrguo Date: Fri, 14 Mar 2025 14:10:59 +0800 Subject: [PATCH 7/9] fix linting --- lightrag/llm/openai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightrag/llm/openai.py b/lightrag/llm/openai.py index d2174a67..555fea90 100644 --- a/lightrag/llm/openai.py +++ b/lightrag/llm/openai.py @@ -123,7 +123,7 @@ async def openai_complete_if_cache( async def inner(): try: - _content = '' + _content = "" async for chunk in response: content = chunk.choices[0].delta.content if content is None: From 8f22c2f12bad3e903348c95593e14441f582afc8 Mon Sep 17 00:00:00 2001 From: zrguo Date: Fri, 14 Mar 2025 17:34:37 +0800 Subject: [PATCH 8/9] Create README-zh.md --- README-zh.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README-zh.md diff --git a/README-zh.md b/README-zh.md new file mode 100644 index 00000000..e69de29b From e7456c857948e5e3be92bc082b764e0f56df4f8e Mon Sep 17 00:00:00 2001 From: yangdx Date: Sun, 16 Mar 2025 14:13:26 +0800 Subject: [PATCH 9/9] Added sample environment configuration files for webui development and local setups. --- lightrag_webui/env.development.smaple | 2 ++ lightrag_webui/env.local.sample | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 lightrag_webui/env.development.smaple create mode 100644 lightrag_webui/env.local.sample diff --git a/lightrag_webui/env.development.smaple b/lightrag_webui/env.development.smaple new file mode 100644 index 00000000..080cf95f --- /dev/null +++ b/lightrag_webui/env.development.smaple @@ -0,0 +1,2 @@ +# Development environment configuration +VITE_BACKEND_URL=/api diff --git a/lightrag_webui/env.local.sample b/lightrag_webui/env.local.sample new file mode 100644 index 00000000..0f2c293c --- /dev/null +++ b/lightrag_webui/env.local.sample @@ -0,0 +1,3 @@ +VITE_BACKEND_URL=http://localhost:9621 +VITE_API_PROXY=true +VITE_API_ENDPOINTS=/api,/documents,/graphs,/graph,/health,/query,/docs,/openapi.json