返回值更完善
This commit is contained in:
parent
613e8ef5ee
commit
c15cbcf9ce
Binary file not shown.
|
|
@ -94,13 +94,28 @@ def search_error(query: ErrorQuery):
|
||||||
for idx, score in zip(indices[0], sim[0]):
|
for idx, score in zip(indices[0], sim[0]):
|
||||||
db_id = index_to_id[idx]
|
db_id = index_to_id[idx]
|
||||||
db_entry = error_memory[db_id]
|
db_entry = error_memory[db_id]
|
||||||
|
|
||||||
|
# 分层匹配得分
|
||||||
layer_score = compute_layered_similarity_sco(user_vectors, db_entry["layer_vectors"])
|
layer_score = compute_layered_similarity_sco(user_vectors, db_entry["layer_vectors"])
|
||||||
|
|
||||||
|
# 逐层匹配,提取每一层的关键字
|
||||||
|
matched_keywords = []
|
||||||
|
for user_layer, db_layer in zip(user_layers, db_entry["layers"]):
|
||||||
|
# 这里简单取两个文本的公共单词作为关键字(你可以换成更复杂的匹配方法)
|
||||||
|
user_tokens = set(user_layer.split())
|
||||||
|
db_tokens = set(db_layer.split())
|
||||||
|
common_tokens = user_tokens & db_tokens
|
||||||
|
matched_keywords.append(list(common_tokens))
|
||||||
|
|
||||||
results.append({
|
results.append({
|
||||||
"db_id": db_id,
|
"db_id": db_id,
|
||||||
"similarity": round(layer_score, 4),
|
"aggregate_similarity": round(float(score), 4), # 聚合索引匹配得分
|
||||||
"matched_layers": db_entry["layers"]
|
"layer_similarity": round(layer_score, 4), # 分层匹配得分
|
||||||
|
"matched_layers": db_entry["layers"], # 匹配到的 traceback 每一层
|
||||||
|
"matched_keywords": matched_keywords # 每一层匹配到的关键字列表
|
||||||
})
|
})
|
||||||
|
|
||||||
# 还需要根据相似度排序
|
# 先按分层得分排,再按聚合得分排
|
||||||
results.sort(key=lambda x: x["similarity"], reverse=True)
|
results.sort(key=lambda x: (x["layer_similarity"], x["aggregate_similarity"]), reverse=True)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue