Skip to content

Commit

Permalink
Fix knowledge graph node not found (infiniflow#4968)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxlp committed Feb 14, 2025
1 parent 754d5ea commit 3fb9bf3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions api/apps/kb_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ def knowledge_graph(kb_id):

if "nodes" in obj["graph"]:
obj["graph"]["nodes"] = sorted(obj["graph"]["nodes"], key=lambda x: x.get("pagerank", 0), reverse=True)[:256]
if "edges" in obj["graph"]:
obj["graph"]["edges"] = sorted(obj["graph"]["edges"], key=lambda x: x.get("weight", 0), reverse=True)[:128]
if "edges" in obj["graph"]:
node_id_set = { o["id"] for o in obj["graph"]["nodes"] }
filtered_edges = [o for o in obj["graph"]["edges"] if o["source"] != o["target"] and o["source"] in node_id_set and o["target"] in node_id_set]
obj["graph"]["edges"] = sorted(filtered_edges, key=lambda x: x.get("weight", 0), reverse=True)[:128]
return get_json_result(data=obj)

0 comments on commit 3fb9bf3

Please sign in to comment.