yangdx commited on
Commit
4498e2f
·
1 Parent(s): 5297a32

Fix get_all_labels for PostgreSQL

Browse files
lightrag/kg/neo4j_impl.py CHANGED
@@ -653,7 +653,7 @@ class Neo4JStorage(BaseGraphStorage):
653
  Retrieve a connected subgraph of nodes where the label includes the specified `node_label`.
654
 
655
  Args:
656
- node_label: Label of the starting node,* means all nodes
657
  max_depth: Maximum depth of the subgraph, Defaults to 3
658
  max_nodes: Maxiumu nodes to return by BFS, Defaults to 1000
659
 
 
653
  Retrieve a connected subgraph of nodes where the label includes the specified `node_label`.
654
 
655
  Args:
656
+ node_label: Label of the starting node, * means all nodes
657
  max_depth: Maximum depth of the subgraph, Defaults to 3
658
  max_nodes: Maxiumu nodes to return by BFS, Defaults to 1000
659
 
lightrag/kg/postgres_impl.py CHANGED
@@ -9,7 +9,6 @@ import configparser
9
 
10
  from lightrag.types import KnowledgeGraph, KnowledgeGraphNode, KnowledgeGraphEdge
11
 
12
- import sys
13
  from tenacity import (
14
  retry,
15
  retry_if_exception_type,
@@ -28,11 +27,6 @@ from ..base import (
28
  from ..namespace import NameSpace, is_namespace
29
  from ..utils import logger
30
 
31
- if sys.platform.startswith("win"):
32
- import asyncio.windows_events
33
-
34
- asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
35
-
36
  import pipmaster as pm
37
 
38
  if not pm.is_installed("asyncpg"):
@@ -41,6 +35,9 @@ if not pm.is_installed("asyncpg"):
41
  import asyncpg # type: ignore
42
  from asyncpg import Pool # type: ignore
43
 
 
 
 
44
 
45
  class PostgreSQLDB:
46
  def __init__(self, config: dict[str, Any], **kwargs: Any):
@@ -1535,14 +1532,13 @@ class PGGraphStorage(BaseGraphStorage):
1535
  MATCH (n:base)
1536
  WHERE n.entity_id IS NOT NULL
1537
  RETURN DISTINCT n.entity_id AS label
1538
- ORDER BY label
1539
  $$) AS (label text)"""
1540
  % self.graph_name
1541
  )
1542
 
1543
  results = await self._query(query)
1544
- labels = [self._decode_graph_label(result["label"]) for result in results]
1545
-
1546
  return labels
1547
 
1548
  async def embed_nodes(
 
9
 
10
  from lightrag.types import KnowledgeGraph, KnowledgeGraphNode, KnowledgeGraphEdge
11
 
 
12
  from tenacity import (
13
  retry,
14
  retry_if_exception_type,
 
27
  from ..namespace import NameSpace, is_namespace
28
  from ..utils import logger
29
 
 
 
 
 
 
30
  import pipmaster as pm
31
 
32
  if not pm.is_installed("asyncpg"):
 
35
  import asyncpg # type: ignore
36
  from asyncpg import Pool # type: ignore
37
 
38
+ # Get maximum number of graph nodes from environment variable, default is 1000
39
+ MAX_GRAPH_NODES = int(os.getenv("MAX_GRAPH_NODES", 1000))
40
+
41
 
42
  class PostgreSQLDB:
43
  def __init__(self, config: dict[str, Any], **kwargs: Any):
 
1532
  MATCH (n:base)
1533
  WHERE n.entity_id IS NOT NULL
1534
  RETURN DISTINCT n.entity_id AS label
1535
+ ORDER BY n.entity_id
1536
  $$) AS (label text)"""
1537
  % self.graph_name
1538
  )
1539
 
1540
  results = await self._query(query)
1541
+ labels = [result["label"] for result in results]
 
1542
  return labels
1543
 
1544
  async def embed_nodes(