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

Function query_graph

query_graph.py:125–162  ·  view source on GitHub ↗
(global_config,db,query)

Source from the content-addressed store, hash-verified

123 aggregation_descriptions+="\n".join([information[0]+"\t\t"+str(information[1]) for information in aggregation_results])
124 return aggregation_descriptions,communities
125def query_graph(global_config,db,query):
126 use_llm_func: callable = global_config["use_llm_func"]
127 embedding: callable=global_config["embeddings_func"]
128 b=time.time()
129 level_mode=global_config['level_mode']
130 topk=global_config['topk']
131 chunks_file=global_config["chunks_file"]
132 entity_results=search_vector_search(global_config['working_dir'],embedding(query),topk=topk,level_mode=level_mode)
133 v=time.time()
134 res_entity=[i[0]for i in entity_results]
135 chunks=[i[-1]for i in entity_results]
136 entity_descriptions=get_entity_description(global_config,entity_results)
137 reasoning_path,reasoning_path_information_description=get_reasoning_chain(global_config,res_entity)
138 # reasoning_path,reasoning_path_information_description=get_path_chain(global_config,res_entity)
139 aggregation_descriptions,aggregation=get_aggregation_description(global_config,reasoning_path)
140 # chunks=search_chunks(global_config['working_dir'],aggregation)
141 text_units=get_text_units(global_config['working_dir'],chunks,chunks_file,k=5)
142 describe=f"""
143 entity_information:
144 {entity_descriptions}
145 aggregation_entity_information:
146 {aggregation_descriptions}
147 reasoning_path_information:
148 {reasoning_path_information_description}
149 text_units:
150 {text_units}
151 """
152 e=time.time()
153
154 # print(describe)
155 sys_prompt =PROMPTS["rag_response"].format(context_data=describe)
156 response=use_llm_func(query,system_prompt=sys_prompt)
157 g=time.time()
158 print(f"embedding time: {v-b:.2f}s")
159 print(f"query time: {e-v:.2f}s")
160
161 print(f"response time: {g-e:.2f}s")
162 return describe,response
163if __name__=="__main__":
164 db = pymysql.connect(host='localhost', user='root',port=4321,
165 passwd='123', charset='utf8mb4')

Callers 1

query_graph.pyFile · 0.85

Calls 7

search_vector_searchFunction · 0.90
get_text_unitsFunction · 0.90
get_entity_descriptionFunction · 0.85
get_reasoning_chainFunction · 0.85
formatMethod · 0.80
embeddingFunction · 0.70

Tested by

no test coverage detected