fix: 修复 kbs-text 系统数据结构兼容性问题
问题描述:
- kbs-text 系统的所有评估指标评分异常(检索上下文数量为 0)
- kbs-excel 系统工作正常
- 根本原因是数据结构差异导致检索上下文提取失败
技术细节:
- kbs-text: {question_id, response: {data: [{fileSource}]}}
- kbs-excel: {question_id, data: [{fileSource}]}
修复内容:
1. 修改 extract_retrieved_contexts 方法
- 增加对 kbs-text 数据格式的兼容处理
- 当顶层没有 data 键时,尝试从 response.data 获取
2. 修改 convert_to_ragas_format 方法
- 增加对 kbs-text 数据格式的兼容处理
- 确保能正确提取问题和答案内容
验证结果:
- kbs-text 检索上下文数量:0 -> 12 ✅
- kbs-text response 长度:0 -> 449 ✅
- kbs-excel 兼容性保持正常 ✅
影响范围:
- src/transformers/data_converter.py (94-136, 182-211)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
76c0bf1d73
commit
1f08977ca7
2 files changed
+25
No files matched your search
@@ -16,6 +16,12 @@
|
||||
|
||||
## ✅ 最近完成(2026-01-08)
|
||||
|
||||
### Bug 修复 🐛
|
||||
- [x] 修复 kbs-text 系统检索上下文提取失败的问题
|
||||
- [x] 增强数据转换器对多种数据格式的兼容性
|
||||
- [x] 修复 `extract_retrieved_contexts` 方法支持 kbs-text 结构
|
||||
- [x] 修复 `convert_to_ragas_format` 方法支持 kbs-text 结构
|
||||
|
||||
### 功能扩展 🎯
|
||||
- [x] 实现 answer_correctness 单独评估功能
|
||||
- [x] 实现评估结果合并功能
|
||||
@@ -302,6 +308,7 @@
|
||||
- [x] Embeddings 与阿里云 DashScope API 兼容性问题
|
||||
- [x] AnswerCorrectness 指标初始化问题
|
||||
- [x] Windows 控制台编码问题(通过 UTF-8 设置解决)
|
||||
- [x] kbs-text 系统数据结构兼容性问题(fileSource 字段提取失败)
|
||||
|
||||
### 当前状态
|
||||
- 🟢 无阻塞性问题
|
||||
|
||||
@@ -108,8 +108,17 @@ class DataConverter:
|
||||
base_system = system.split('-')[0] if '-' in system else system
|
||||
if base_system == 'kbs':
|
||||
# 新格式:从 data[0].fileSource 中提取检索上下文
|
||||
# 兼容两种数据结构:
|
||||
# 1. kbs-excel: {question_id, data: [{fileSource}]}
|
||||
# 2. kbs-text: {question_id, response: {data: [{fileSource}]}}
|
||||
data_list = validation_result.get('data', [])
|
||||
|
||||
# 如果没有顶层 data 键,尝试从 response.data 获取(kbs-text 格式)
|
||||
if not data_list and 'response' in validation_result:
|
||||
response = validation_result.get('response', {})
|
||||
if isinstance(response, dict):
|
||||
data_list = response.get('data', [])
|
||||
|
||||
for item in data_list:
|
||||
# 尝试从 fileSource 提取
|
||||
file_source = item.get('fileSource', '')
|
||||
@@ -174,8 +183,17 @@ class DataConverter:
|
||||
base_system = system.split('-')[0] if '-' in system else system
|
||||
if base_system == 'kbs':
|
||||
# 新格式:data 字段直接包含问题数据数组
|
||||
# 兼容两种数据结构:
|
||||
# 1. kbs-excel: {question_id, data: [{question, content, fileSource}]}
|
||||
# 2. kbs-text: {question_id, response: {data: [{question, content, fileSource}]}}
|
||||
data_list = validation_result.get('data', [])
|
||||
|
||||
# 如果没有顶层 data 键,尝试从 response.data 获取(kbs-text 格式)
|
||||
if not data_list and 'response' in validation_result:
|
||||
response = validation_result.get('response', {})
|
||||
if isinstance(response, dict):
|
||||
data_list = response.get('data', [])
|
||||
|
||||
if not data_list:
|
||||
# 如果没有 data,返回空响应
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user