@@ -209,7 +209,10 @@ def calc_table_embedding(tables: list[dict], question: str, session=None, oid: i
209209
210210 # 步骤 1:用关键词计算向量相似度(批量向量化)
211211 model = EmbeddingModelCache .get_model ()
212+ t0 = time .time ()
212213 q_embedding = model .embed_query (keywords )
214+ t1 = time .time ()
215+ SQLBotLogUtil .info (f"[perf] embed_query 耗时 { t1 - t0 :.3f} s" )
213216
214217 # 预解析所有 embedding,跳过空的
215218 parsed_embeddings = []
@@ -228,6 +231,9 @@ def calc_table_embedding(tables: list[dict], question: str, session=None, oid: i
228231 for idx , sim in zip (valid_indices , similarities ):
229232 _list [idx ]['cosine_similarity' ] = float (sim )
230233
234+ t2 = time .time ()
235+ SQLBotLogUtil .info (f"[perf] 向量相似度计算耗时 { t2 - t1 :.3f} s,共 { len (parsed_embeddings )} 张表" )
236+
231237 # 步骤 2 & 3:计算关键词分数并融合
232238 alpha = settings .TABLE_EMBEDDING_ALPHA
233239 for table in _list :
@@ -241,6 +247,9 @@ def calc_table_embedding(tables: list[dict], question: str, session=None, oid: i
241247 table ['keyword_score' ] = kw_score
242248 table ['cosine_similarity' ] = alpha * vec_score + (1 - alpha ) * kw_score
243249
250+ t3 = time .time ()
251+ SQLBotLogUtil .info (f"[perf] 关键词评分耗时 { t3 - t2 :.3f} s,共 { len (_list )} 张表" )
252+
244253 # 步骤 4:排序 - 精确匹配(keyword_score=1.0)始终排最前
245254 exact_matches = [t for t in _list if t .get ('keyword_score' ) == 1.0 ]
246255 other_tables = [t for t in _list if t .get ('keyword_score' ) != 1.0 ]
@@ -252,7 +261,7 @@ def calc_table_embedding(tables: list[dict], question: str, session=None, oid: i
252261 _list = _list [:settings .TABLE_EMBEDDING_COUNT ]
253262
254263 end_time = time .time ()
255- SQLBotLogUtil .info (f"融合评分耗时 { end_time - start_time :.3f} s" )
264+ SQLBotLogUtil .info (f"[perf] 融合评分总耗时 { end_time - start_time :.3f} s" )
256265 SQLBotLogUtil .info (json .dumps ([{
257266 "id" : ele .get ('id' ),
258267 "schema_table" : ele .get ('schema_table' ),
@@ -309,7 +318,7 @@ def _calc_vector_only(tables: list[dict], question: str):
309318 _list = _list [:settings .TABLE_EMBEDDING_COUNT ]
310319
311320 end_time = time .time ()
312- SQLBotLogUtil .info (str ( end_time - start_time ) )
321+ SQLBotLogUtil .info (f"[perf] 纯向量匹配耗时 { end_time - start_time :.3f } s,共 { len ( parsed_embeddings ) } 张表" )
313322 SQLBotLogUtil .info (json .dumps ([{
314323 "id" : ele .get ('id' ),
315324 "schema_table" : ele .get ('schema_table' ),
0 commit comments