MCPcopy Create free account
hub / github.com/KnowledgeXLab/LeanRAG / find_tree_root

Function find_tree_root

database_utils.py:221–247  ·  view source on GitHub ↗
(working_dir,entity)

Source from the content-addressed store, hash-verified

219 print(e)
220 print("insert communities error")
221def find_tree_root(working_dir,entity):
222 db = pymysql.connect(host='localhost',port=4321, user='root',
223 passwd='123', charset='utf8mb4')
224 dbname=os.path.basename(working_dir)
225 res=[entity]
226 cursor = db.cursor()
227 db_name=os.path.basename(working_dir)
228 depth_sql=f"select max(level) from {db_name}.entities"
229 cursor.execute(depth_sql)
230 depth=cursor.fetchall()[0][0]
231 i=0
232
233 while i< depth:
234 sql=f"select parent from {db_name}.entities where entity_name=%s "
235
236 cursor.execute(sql,(entity))
237 ret=cursor.fetchall()
238 # print(ret)
239 i+=1
240 if len(ret)==0:
241 break
242 entity=ret[0][0]
243 res.append(entity)
244 # res=list(set(res))
245 # res = list(dict.fromkeys(res))
246
247 return res
248
249def find_path(entity1,entity2,working_dir,level,depth=5):
250 db = pymysql.connect(host='localhost',port=4321, user='root',

Callers 1

get_reasoning_chainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected