From 0d836afd349566b51cde1b9bf30581b0e38740e8 Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Thu, 11 Jun 2026 20:53:11 +0800 Subject: [PATCH] fix: keep max pagerank for repeated n-hop edges (#15696) ## Summary Fixes #15695. The Python GraphRAG path already accumulates similarity when several N-hop paths produce the same edge, but PageRank was overwritten by the last path. That makes ranking depend on path order for repeated edges. This keeps the strongest PageRank seen for a repeated edge in the Python implementation: - `rag/graphrag/search.py` The similarity score still accumulates exactly as before. ## To verify - `python -m py_compile rag\graphrag\search.py` - `git diff --check` - `git diff --stat upstream/main` -> only `rag/graphrag/search.py` I originally included the Go implementation too, but removed it after maintainer feedback because the Go version is still under development and not released yet. --- rag/graphrag/search.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rag/graphrag/search.py b/rag/graphrag/search.py index 0cbb884f2..c342ae03c 100644 --- a/rag/graphrag/search.py +++ b/rag/graphrag/search.py @@ -192,7 +192,9 @@ class KGSearch(Dealer): nhop_pathes[(f, t)]["sim"] += ent["sim"] / (2 + i) else: nhop_pathes[(f, t)]["sim"] = ent["sim"] / (2 + i) - nhop_pathes[(f, t)]["pagerank"] = wts[i] + nhop_pathes[(f, t)]["pagerank"] = max( + nhop_pathes[(f, t)].get("pagerank", 0), wts[i] + ) logging.info("Retrieved entities: {}".format(list(ents_from_query.keys()))) logging.info("Retrieved relations: {}".format(list(rels_from_txt.keys())))