Skip to content

Commit b0dd036

Browse files
committed
feat: optimize graph visualize
1 parent 45798c5 commit b0dd036

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

aperag/graph/lightrag/lightrag.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,23 @@ async def get_knowledge_graph(
375375
KnowledgeGraph: Knowledge graph containing nodes and edges
376376
"""
377377

378-
return await self.chunk_entity_relation_graph.get_knowledge_graph(node_label, max_depth, max_nodes)
378+
kg = await self.chunk_entity_relation_graph.get_knowledge_graph(node_label, max_depth, max_nodes)
379+
380+
# Clean up descriptions in nodes by replacing GRAPH_FIELD_SEP with double newlines
381+
if kg.nodes and len(kg.nodes) > 0:
382+
for node in kg.nodes:
383+
if node.properties.get("description"):
384+
# Replace <SEP> with double newlines for better readability
385+
node.properties["description"] = node.properties["description"].replace(GRAPH_FIELD_SEP, "\n\n")
386+
387+
# Clean up descriptions in edges by replacing GRAPH_FIELD_SEP with double newlines
388+
if kg.edges and len(kg.edges) > 0:
389+
for edge in kg.edges:
390+
if edge.properties.get("description"):
391+
# Replace <SEP> with double newlines for better readability
392+
edge.properties["description"] = edge.properties["description"].replace(GRAPH_FIELD_SEP, "\n\n")
393+
394+
return kg
379395

380396
def _get_storage_class(self, storage_name: str) -> Callable[..., Any]:
381397
# Direct class lookup from registry instead of dynamic import

aperag/service/graph_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from aperag.db.ops import async_db_ops
2121
from aperag.exceptions import CollectionNotFoundException
2222
from aperag.graph import lightrag_manager
23+
from aperag.graph.lightrag.types import KnowledgeGraph
2324
from aperag.schema import view_models
2425
from aperag.utils.utils import utc_now
2526

@@ -92,7 +93,7 @@ async def get_knowledge_graph(
9293
mode_description = f"subgraph from '{label}'"
9394

9495
# Get knowledge graph
95-
kg = await rag.get_knowledge_graph(
96+
kg: KnowledgeGraph = await rag.get_knowledge_graph(
9697
node_label=node_label,
9798
max_depth=max_depth,
9899
max_nodes=query_max_nodes,

0 commit comments

Comments
 (0)