(global_config,db,query)
| 123 | aggregation_descriptions+="\n".join([information[0]+"\t\t"+str(information[1]) for information in aggregation_results]) |
| 124 | return aggregation_descriptions,communities |
| 125 | def 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 |
| 163 | if __name__=="__main__": |
| 164 | db = pymysql.connect(host='localhost', user='root',port=4321, |
| 165 | passwd='123', charset='utf8mb4') |
no test coverage detected