MCPcopy Index your code
hub / github.com/KnowledgeXLab/LeanRAG / get_reasoning_chain

Function get_reasoning_chain

query_graph.py:52–94  ·  view source on GitHub ↗
(global_config,entities_set)

Source from the content-addressed store, hash-verified

50 return truncated_text
51
52def get_reasoning_chain(global_config,entities_set):
53 maybe_edges=list(combinations(entities_set,2))
54 reasoning_path=[]
55 reasoning_path_information=[]
56 db_name=global_config['working_dir'].split("/")[-1]
57 information_record=[]
58 for edge in maybe_edges:
59 a_path=[]
60 b_path=[]
61 node1=edge[0]
62 node2=edge[1]
63 node1_tree=find_tree_root(db_name,node1)
64 node2_tree=find_tree_root(db_name,node2)
65
66 # if node1_tree[1]!=node2_tree[1] :
67 # print("debug")
68 for index,(i,j) in enumerate(zip(node1_tree,node2_tree)):
69 if i==j:
70 a_path.append(i)
71 break
72 if i in b_path or j in a_path:
73 break
74 if i!=j :
75 a_path.append(i)
76 b_path.append(j)
77
78
79 reasoning_path.append(a_path+[b_path[len(b_path)-1-i] for i in range(len(b_path))])
80 a_path=list(set(a_path))
81 b_path=list(set(b_path))
82 for maybe_edge in list(combinations(a_path+b_path,2)):
83 if maybe_edge[0]==maybe_edge[1]:
84 continue
85 information=search_nodes_link(maybe_edge[0],maybe_edge[1],global_config['working_dir'])
86 if information==None:
87 continue
88 information_record.append(information)
89 reasoning_path_information.append([maybe_edge[0],maybe_edge[1],information[2]])
90 # columns=['src_tgt','tgt_src','path_description']
91 # reasoning_path_information_description="\t\t".join(columns)+"\n"
92 temp_relations_information=list(set([information[2] for information in reasoning_path_information]))
93 reasoning_path_information_description="\n".join(temp_relations_information)
94 return reasoning_path,reasoning_path_information_description
95
96def get_entity_description(global_config,entities_set,mode=0):
97

Callers 1

query_graphFunction · 0.85

Calls 2

find_tree_rootFunction · 0.90
search_nodes_linkFunction · 0.90

Tested by

no test coverage detected