Browse Source

Fix knowledge graph node not found (#4968) (#4970)

### What problem does this PR solve?

Fix knowledge graph node not found (#4968)

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
tags/v0.17.0
zhxlp 8 months ago
parent
commit
194e8ea696
No account linked to committer's email address
1 changed files with 4 additions and 2 deletions
  1. 4
    2
      api/apps/kb_app.py

+ 4
- 2
api/apps/kb_app.py View File

@@ -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)

Loading…
Cancel
Save