From eb3306f34c2886772f6045b1ab4bbaa85f541e3f Mon Sep 17 00:00:00 2001 From: Yannick Stephan Date: Wed, 19 Feb 2025 22:52:49 +0100 Subject: [PATCH] cleanup --- lightrag/api/lightrag_server.py | 5 ---- lightrag/base.py | 4 --- lightrag/kg/age_impl.py | 7 ------ lightrag/kg/gremlin_impl.py | 3 --- lightrag/kg/mongo_impl.py | 18 ------------- lightrag/kg/neo4j_impl.py | 25 ------------------- lightrag/kg/networkx_impl.py | 3 --- lightrag/kg/oracle_impl.py | 3 --- lightrag/kg/postgres_impl.py | 11 +++----- lightrag/kg/tidb_impl.py | 3 --- lightrag/lightrag.py | 4 --- .../lightrag_visualizer/graph_visualizer.py | 5 +++- 12 files changed, 7 insertions(+), 84 deletions(-) diff --git a/lightrag/api/lightrag_server.py b/lightrag/api/lightrag_server.py index 0cf1d01e..96315b82 100644 --- a/lightrag/api/lightrag_server.py +++ b/lightrag/api/lightrag_server.py @@ -1682,11 +1682,6 @@ def create_app(args): trace_exception(e) raise HTTPException(status_code=500, detail=str(e)) - # query all graph labels - @app.get("/graph/label/list") - async def get_graph_labels(): - return await rag.get_graph_labels() - # query all graph @app.get("/graphs") async def get_knowledge_graph(label: str): diff --git a/lightrag/base.py b/lightrag/base.py index 5f6a1bf1..af060435 100644 --- a/lightrag/base.py +++ b/lightrag/base.py @@ -198,10 +198,6 @@ class BaseGraphStorage(StorageNameSpace, ABC): ) -> tuple[np.ndarray[Any, Any], list[str]]: """Get all labels in the graph.""" - @abstractmethod - async def get_all_labels(self) -> list[str]: - """Get a knowledge graph of a node.""" - @abstractmethod async def get_knowledge_graph( self, node_label: str, max_depth: int = 5 diff --git a/lightrag/kg/age_impl.py b/lightrag/kg/age_impl.py index 243a110b..225b350b 100644 --- a/lightrag/kg/age_impl.py +++ b/lightrag/kg/age_impl.py @@ -65,10 +65,6 @@ class AGEQueryException(Exception): @final @dataclass class AGEStorage(BaseGraphStorage): - @staticmethod - def load_nx_graph(file_name): - print("no preloading of graph with AGE in production") - def __init__(self, namespace, global_config, embedding_func): super().__init__( namespace=namespace, @@ -625,9 +621,6 @@ class AGEStorage(BaseGraphStorage): ) -> tuple[np.ndarray[Any, Any], list[str]]: raise NotImplementedError - async def get_all_labels(self) -> list[str]: - raise NotImplementedError - async def get_knowledge_graph( self, node_label: str, max_depth: int = 5 ) -> KnowledgeGraph: diff --git a/lightrag/kg/gremlin_impl.py b/lightrag/kg/gremlin_impl.py index 40a9f007..de12bbd9 100644 --- a/lightrag/kg/gremlin_impl.py +++ b/lightrag/kg/gremlin_impl.py @@ -404,9 +404,6 @@ class GremlinStorage(BaseGraphStorage): ) -> tuple[np.ndarray[Any, Any], list[str]]: raise NotImplementedError - async def get_all_labels(self) -> list[str]: - raise NotImplementedError - async def get_knowledge_graph( self, node_label: str, max_depth: int = 5 ) -> KnowledgeGraph: diff --git a/lightrag/kg/mongo_impl.py b/lightrag/kg/mongo_impl.py index f6a25ba6..b3479b2f 100644 --- a/lightrag/kg/mongo_impl.py +++ b/lightrag/kg/mongo_impl.py @@ -606,24 +606,6 @@ class MongoGraphStorage(BaseGraphStorage): # ------------------------------------------------------------------------- # - async def get_all_labels(self) -> list[str]: - """ - Get all existing node _id in the database - Returns: - [id1, id2, ...] # Alphabetically sorted id list - """ - # Use MongoDB's distinct and aggregation to get all unique labels - pipeline = [ - {"$group": {"_id": "$_id"}}, # Group by _id - {"$sort": {"_id": 1}}, # Sort alphabetically - ] - - cursor = self.collection.aggregate(pipeline) - labels = [] - async for doc in cursor: - labels.append(doc["_id"]) - return labels - async def get_knowledge_graph( self, node_label: str, max_depth: int = 5 ) -> KnowledgeGraph: diff --git a/lightrag/kg/neo4j_impl.py b/lightrag/kg/neo4j_impl.py index 82631cf8..296f4295 100644 --- a/lightrag/kg/neo4j_impl.py +++ b/lightrag/kg/neo4j_impl.py @@ -633,31 +633,6 @@ class Neo4JStorage(BaseGraphStorage): await traverse(label, 0) return result - async def get_all_labels(self) -> list[str]: - """ - Get all existing node labels in the database - Returns: - ["Person", "Company", ...] # Alphabetically sorted label list - """ - async with self._driver.session(database=self._DATABASE) as session: - # Method 1: Direct metadata query (Available for Neo4j 4.3+) - # query = "CALL db.labels() YIELD label RETURN label" - - # Method 2: Query compatible with older versions - query = """ - MATCH (n) - WITH DISTINCT labels(n) AS node_labels - UNWIND node_labels AS label - RETURN DISTINCT label - ORDER BY label - """ - - result = await session.run(query) - labels = [] - async for record in result: - labels.append(record["label"]) - return labels - async def delete_node(self, node_id: str) -> None: raise NotImplementedError diff --git a/lightrag/kg/networkx_impl.py b/lightrag/kg/networkx_impl.py index 313d9f8d..9b0d7474 100644 --- a/lightrag/kg/networkx_impl.py +++ b/lightrag/kg/networkx_impl.py @@ -172,9 +172,6 @@ class NetworkXStorage(BaseGraphStorage): if self._graph.has_edge(source, target): self._graph.remove_edge(source, target) - async def get_all_labels(self) -> list[str]: - raise NotImplementedError - async def get_knowledge_graph( self, node_label: str, max_depth: int = 5 ) -> KnowledgeGraph: diff --git a/lightrag/kg/oracle_impl.py b/lightrag/kg/oracle_impl.py index 014726fb..958425fc 100644 --- a/lightrag/kg/oracle_impl.py +++ b/lightrag/kg/oracle_impl.py @@ -676,9 +676,6 @@ class OracleGraphStorage(BaseGraphStorage): async def delete_node(self, node_id: str) -> None: raise NotImplementedError - async def get_all_labels(self) -> list[str]: - raise NotImplementedError - async def get_knowledge_graph( self, node_label: str, max_depth: int = 5 ) -> KnowledgeGraph: diff --git a/lightrag/kg/postgres_impl.py b/lightrag/kg/postgres_impl.py index ad7c4b5e..5f0a51a0 100644 --- a/lightrag/kg/postgres_impl.py +++ b/lightrag/kg/postgres_impl.py @@ -186,12 +186,10 @@ class PostgreSQLDB: asyncpg.exceptions.UniqueViolationError, asyncpg.exceptions.DuplicateTableError, ) as e: - if upsert: - print("Key value duplicate, but upsert succeeded.") - else: - logger.error(f"Upsert error: {e}") + if not upsert: + logger.error(f"PostgreSQL, upsert error: {e}") except Exception as e: - logger.error(f"PostgreSQL database,\nsql:{sql},\ndata:{data},\nerror:{e}") + logger.error(f"PostgreSQL database, sql:{sql}, data:{data}, error:{e}") raise @@ -1095,9 +1093,6 @@ class PGGraphStorage(BaseGraphStorage): ) -> tuple[np.ndarray[Any, Any], list[str]]: raise NotImplementedError - async def get_all_labels(self) -> list[str]: - raise NotImplementedError - async def get_knowledge_graph( self, node_label: str, max_depth: int = 5 ) -> KnowledgeGraph: diff --git a/lightrag/kg/tidb_impl.py b/lightrag/kg/tidb_impl.py index 4266d07c..730fe4d2 100644 --- a/lightrag/kg/tidb_impl.py +++ b/lightrag/kg/tidb_impl.py @@ -566,9 +566,6 @@ class TiDBGraphStorage(BaseGraphStorage): async def delete_node(self, node_id: str) -> None: raise NotImplementedError - async def get_all_labels(self) -> list[str]: - raise NotImplementedError - async def get_knowledge_graph( self, node_label: str, max_depth: int = 5 ) -> KnowledgeGraph: diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index efcded4c..2f3e1800 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -614,10 +614,6 @@ class LightRAG: self.storages_status = StoragesStatus.FINALIZED logger.debug("Finalized Storages") - async def get_graph_labels(self): - text = await self.chunk_entity_relation_graph.get_all_labels() - return text - async def get_knowledge_graph( self, nodel_label: str, max_depth: int ) -> KnowledgeGraph: diff --git a/lightrag/tools/lightrag_visualizer/graph_visualizer.py b/lightrag/tools/lightrag_visualizer/graph_visualizer.py index 8a6f0976..9950041f 100644 --- a/lightrag/tools/lightrag_visualizer/graph_visualizer.py +++ b/lightrag/tools/lightrag_visualizer/graph_visualizer.py @@ -1,6 +1,6 @@ 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 @@ -12,7 +12,10 @@ if not pm.is_installed("pyglm"): pm.install("pyglm") if not pm.is_installed("python-louvain"): pm.install("python-louvain") +if not pm.is_installed("networkx"): + pm.install("networkx") +import networkx as nx import moderngl from imgui_bundle import imgui, immapp, hello_imgui import community