|
|
@@ -159,19 +159,33 @@ def convert_pipeline_output_to_api_response(
|
|
|
if 0 <= note_index < len(notes_data):
|
|
|
note = notes_data[note_index]
|
|
|
note_id = note.get('id', '')
|
|
|
-
|
|
|
+
|
|
|
# 获取最高相似度(从相似度分析结果中获取)
|
|
|
max_similarity = similarity_map.get(note_id, 0)
|
|
|
-
|
|
|
+
|
|
|
# 计算贡献
|
|
|
contribution = evaluation_score * max_similarity if max_similarity > 0 else evaluation_score
|
|
|
-
|
|
|
+
|
|
|
+ # 获取该帖子的解构特征匹配详情
|
|
|
+ matched_features = extract_matched_features_from_results(
|
|
|
+ similarity_results,
|
|
|
+ note_id
|
|
|
+ )
|
|
|
+
|
|
|
matched_note = {
|
|
|
'note_id': note_id,
|
|
|
'note_title': note.get('note_card', {}).get('display_title', ''),
|
|
|
'evaluation_score': round(evaluation_score, 3),
|
|
|
'max_similarity': round(max_similarity, 3),
|
|
|
'contribution': round(contribution, 3),
|
|
|
+
|
|
|
+ # 评估详情
|
|
|
+ 'evaluation_reasoning': note_eval.get('评分说明', ''),
|
|
|
+ 'key_matching_points': note_eval.get('关键匹配点', []),
|
|
|
+ 'query_relevance': note_eval.get('Query相关性', ''),
|
|
|
+ 'query_relevance_explanation': note_eval.get('Query相关性说明', ''),
|
|
|
+ 'matched_features': matched_features,
|
|
|
+
|
|
|
'note_data': note # 包含完整的搜索结果信息
|
|
|
}
|
|
|
matched_notes.append(matched_note)
|
|
|
@@ -206,26 +220,65 @@ def extract_similarity_map_from_results(
|
|
|
) -> Dict[str, float]:
|
|
|
"""
|
|
|
从相似度分析结果中提取note_id到max_similarity的映射
|
|
|
-
|
|
|
+
|
|
|
Args:
|
|
|
similarity_results: 相似度分析结果
|
|
|
-
|
|
|
+
|
|
|
Returns:
|
|
|
note_id -> max_similarity 的映射
|
|
|
"""
|
|
|
similarity_map = {}
|
|
|
-
|
|
|
+
|
|
|
if not similarity_results:
|
|
|
return similarity_map
|
|
|
-
|
|
|
+
|
|
|
results_list = similarity_results.get('results', [])
|
|
|
for result in results_list:
|
|
|
note_id = result.get('note_id', '')
|
|
|
statistics = result.get('similarity_statistics', {})
|
|
|
max_similarity = statistics.get('max_similarity', 0)
|
|
|
-
|
|
|
+
|
|
|
if note_id:
|
|
|
similarity_map[note_id] = max_similarity
|
|
|
-
|
|
|
+
|
|
|
return similarity_map
|
|
|
|
|
|
+
|
|
|
+def extract_matched_features_from_results(
|
|
|
+ similarity_results: Optional[Dict[str, Any]],
|
|
|
+ note_id: str
|
|
|
+) -> List[Dict[str, Any]]:
|
|
|
+ """
|
|
|
+ 从相似度分析结果中提取指定帖子的解构特征匹配详情
|
|
|
+
|
|
|
+ Args:
|
|
|
+ similarity_results: 相似度分析结果
|
|
|
+ note_id: 帖子ID
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ 匹配的特征列表,每个特征包含名称、维度、相似度等信息
|
|
|
+ """
|
|
|
+ if not similarity_results or not note_id:
|
|
|
+ return []
|
|
|
+
|
|
|
+ results_list = similarity_results.get('results', [])
|
|
|
+ for result in results_list:
|
|
|
+ if result.get('note_id', '') == note_id:
|
|
|
+ # 提取解构特征列表(字段名为deconstructed_features)
|
|
|
+ deconstructed_features = result.get('deconstructed_features', [])
|
|
|
+ matched_features = []
|
|
|
+
|
|
|
+ for feature in deconstructed_features:
|
|
|
+ matched_feature = {
|
|
|
+ 'feature_name': feature.get('feature_name', ''),
|
|
|
+ 'dimension': feature.get('dimension', ''),
|
|
|
+ 'dimension_detail': feature.get('dimension_detail', ''),
|
|
|
+ 'weight': feature.get('weight', 0),
|
|
|
+ 'similarity_score': round(feature.get('similarity_score', 0), 3)
|
|
|
+ }
|
|
|
+ matched_features.append(matched_feature)
|
|
|
+
|
|
|
+ return matched_features
|
|
|
+
|
|
|
+ return []
|
|
|
+
|