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

Function get_common_rag_res

build_graph.py:30–82  ·  view source on GitHub ↗
(WORKING_DIR)

Source from the content-addressed store, hash-verified

28TOTAL_API_CALL_COST = 0
29
30def get_common_rag_res(WORKING_DIR):
31 entity_path=f"{WORKING_DIR}/entity.jsonl"
32 relation_path=f"{WORKING_DIR}/relation.jsonl"
33 # i=0
34 e_dic={}
35 with open(entity_path,"r")as f:
36 for xline in f:
37
38 line=json.loads(xline)
39 entity_name=str(line['entity_name'])
40 description=line['description']
41 source_id=line['source_id']
42 if entity_name not in e_dic.keys():
43 e_dic[entity_name]=dict(
44 entity_name=str(entity_name),
45 description=description,
46 source_id=source_id,
47 degree=0,
48 )
49 else:
50 e_dic[entity_name]['description']+="|Here is another description : "+ description
51 if e_dic[entity_name]['source_id']!= source_id:
52 e_dic[entity_name]['source_id']+= "|"+source_id
53
54 # i+=1
55 # if i==1000:
56 # break
57 # i=0
58 r_dic={}
59 with open(relation_path,"r")as f:
60 for xline in f:
61
62 line=json.loads(xline)
63 src_tgt=str(line['src_tgt'])
64 tgt_src=str(line['tgt_src'])
65 description=line['description']
66 weight=1
67 source_id=line['source_id']
68 r_dic[(src_tgt,tgt_src)]={
69 'src_tgt':str(src_tgt),
70 'tgt_src':str(tgt_src),
71 'description':description,
72 'weight':weight,
73 'source_id':source_id
74 }
75 # e_dic[src_tgt]['degree']+=1
76 # e_dic[tgt_src]['degree']+=1
77 # i+=1
78 # if i==1000:
79 # break
80
81
82 return e_dic,r_dic
83
84
85def embedding(texts: list[str]) -> np.ndarray: #vllm serve

Callers 1

hierarchical_clusteringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected