Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix: keep max pagerank for repeated n-hop edges (#15696)

Yufeng He0d836afd3495
diff --git a/rag/graphrag/search.py b/rag/graphrag/search.py
index 0cbb884f25..c342ae03cf 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())))