feat: 支持所有 RAG 系统的 excel 和 text 类型分别评估
## 主要更新 ### 1. 多类型系统支持 - 所有系统(Coze、KBS、ZHT、ZHTv2)支持 excel 和 text 两种类型 - 系统名称支持后缀:`coze-excel`, `zht-text` 等 - 保持向后兼容:默认使用 excel 类型 ### 2. 数据转换器增强 - `load_validation_results()`: 支持系统名后缀解析 - `zht-excel` → `zht-excel-raw-data.json` - `zht-text` → `zht-text-raw-data.json` - 修复 KBS 系统带后缀的特殊处理 - 支持从带后缀的系统名提取基础系统名 ### 3. 评估脚本更新 - 移除系统名称的 `choices` 限制 - 更新帮助文本说明所有支持的系统名 ### 4. 测试和文档 - 新增系统类型测试脚本(`test_system_types.py`) - 新增多类型系统评估指南(`SYSTEM_TYPE_GUIDE.md`) - 新增实现总结文档(`SOLUTION_A_SUMMARY.md`) - 新增快速参考文档(`QUICK_REFERENCE.md`) ## 使用方法 # 评估单个系统的特定类型 python scripts/evaluate_single_system.py --system zht-excel # 对比同一系统的两种类型 python scripts/evaluate_all_systems.py --systems zht-excel,zht-text # 评估所有系统的所有类型 python scripts/evaluate_all_systems.py \ --systems coze-excel,coze-text,kbs-excel,kbs-text,zht-excel,zht-text,zhtv2-excel,zhtv2-text ## 测试结果 所有 12 个系统名称组合测试通过: - ✅ coze, coze-excel, coze-text - ✅ kbs, kbs-excel, kbs-text - ✅ zht, zht-excel, zht-text - ✅ zhtv2, zhtv2-excel, zhtv2-text 每个系统都能正确加载 15 条测试数据。 ## 报告格式 每个系统类型生成独立的报告: - 标识具体类型(如 `zht-excel`) - 包含完整的评估指标 - 支持多类型对比分析 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
42d5c65986
commit
9eb2e9c837
6 files changed
+822
-14
No files matched your search
@@ -0,0 +1,49 @@
|
||||
# 多类型系统评估 - 快速参考
|
||||
|
||||
## 📋 支持的系统类型
|
||||
|
||||
所有系统都支持 `excel` 和 `text` 两种数据类型的评估:
|
||||
|
||||
| 系统 | Excel 类型 | Text 类型 | 默认类型 |
|
||||
|------|-----------|----------|---------|
|
||||
| Coze | `coze-excel` | `coze-text` | excel |
|
||||
| KBS | `kbs-excel` | `kbs-text` | excel |
|
||||
| ZHT | `zht-excel` | `zht-text` | excel |
|
||||
| ZHTv2 | `zhtv2-excel` | `zhtv2-text` | excel |
|
||||
|
||||
---
|
||||
|
||||
## 🚀 快速开始
|
||||
|
||||
### 评估单个系统的特定类型
|
||||
|
||||
```bash
|
||||
# Excel 类型
|
||||
python scripts/evaluate_single_system.py --system zht-excel
|
||||
|
||||
# Text 类型
|
||||
python scripts/evaluate_single_system.py --system zht-text
|
||||
```
|
||||
|
||||
### 对比同一系统的两种类型
|
||||
|
||||
```bash
|
||||
# 生成对比报告
|
||||
python scripts/evaluate_all_systems.py --systems zht-excel,zht-text --output results/zht_comparison.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📊 报告说明
|
||||
|
||||
- 每个系统类型生成独立的报告
|
||||
- 报告中包含 `system` 字段,标明具体类型
|
||||
- 使用 `comparison` 部分查看不同类型的对比
|
||||
|
||||
---
|
||||
|
||||
## 📚 详细文档
|
||||
|
||||
- **使用指南**: [SYSTEM_TYPE_GUIDE.md](SYSTEM_TYPE_GUIDE.md)
|
||||
- **实现总结**: [SOLUTION_A_SUMMARY.md](SOLUTION_A_SUMMARY.md)
|
||||
- **日志指南**: [LOGGING_GUIDE.md](LOGGING_GUIDE.md)
|
||||
@@ -0,0 +1,257 @@
|
||||
# 多类型 RAG 系统评估 - 实现总结
|
||||
|
||||
**日期**: 2025-01-08
|
||||
**方案**: 方案 A - 分别评估
|
||||
**状态**: ✅ 已完成并测试通过
|
||||
|
||||
---
|
||||
|
||||
## 📊 实现概述
|
||||
|
||||
为所有 RAG 系统(Coze、KBS、ZHT、ZHTv2)添加了对 `excel` 和 `text` 两种数据类型的支持,用户可以分别评估这两种类型。
|
||||
|
||||
---
|
||||
|
||||
## ✅ 支持的系统名称
|
||||
|
||||
### 基础系统(向后兼容)
|
||||
- `coze` - 默认使用 excel 数据
|
||||
- `kbs` - 默认使用 excel 数据
|
||||
- `zht` - 默认使用 excel 数据
|
||||
- `zhtv2` - 默认使用 excel 数据
|
||||
|
||||
### 带类型后缀的系统(新增)
|
||||
- `coze-excel` / `coze-text`
|
||||
- `kbs-excel` / `kbs-text`
|
||||
- `zht-excel` / `zht-text`
|
||||
- `zhtv2-excel` / `zhtv2-text`
|
||||
|
||||
---
|
||||
|
||||
## 🔧 修改的文件
|
||||
|
||||
### 1. `src/transformers/data_converter.py`
|
||||
|
||||
**主要修改**:
|
||||
- `load_validation_results()`: 支持系统名后缀解析
|
||||
- `zht-excel` → 加载 `zht-excel-raw-data.json`
|
||||
- `zht-text` → 加载 `zht-text-raw-data.json`
|
||||
|
||||
- `extract_retrieved_contexts()`: KBS 特殊处理支持带后缀
|
||||
- 提取基础系统名:`kbs-excel` → `kbs`
|
||||
|
||||
- `convert_to_ragas_format()`: KBS 特殊处理支持带后缀
|
||||
- 确保 KBS 的 `excel` 和 `text` 类型都能正确处理
|
||||
|
||||
### 2. `scripts/evaluate_single_system.py`
|
||||
|
||||
**修改**:
|
||||
- 移除了 `choices` 限制,改为 `help` 说明
|
||||
- 支持任意带后缀的系统名
|
||||
|
||||
### 3. 新增文件
|
||||
|
||||
- `docs/SYSTEM_TYPE_GUIDE.md` - 详细使用指南
|
||||
- `scripts/test_system_types.py` - 系统类型测试脚本
|
||||
|
||||
---
|
||||
|
||||
## 🧪 测试结果
|
||||
|
||||
### 数据文件验证
|
||||
|
||||
所有系统的数据文件都存在:
|
||||
|
||||
```
|
||||
✅ coze-excel-raw-data.json (33.0 KB)
|
||||
✅ coze-text-raw-data.json (64.1 KB)
|
||||
✅ kbs-excel-raw-data.json (601.1 KB)
|
||||
✅ kbs-text-raw-data.json (554.0 KB)
|
||||
✅ zht-excel-raw-data.json (117.2 KB)
|
||||
✅ zht-text-raw-data.json (118.3 KB)
|
||||
✅ zhtv2-excel-raw-data.json (177.7 KB)
|
||||
✅ zhtv2-text-raw-data.json (231.8 KB)
|
||||
```
|
||||
|
||||
### 系统名称解析测试
|
||||
|
||||
所有系统名称都能正确解析并加载数据:
|
||||
|
||||
| 系统名 | 数据类型 | 数据条目数 | 状态 |
|
||||
|-------|---------|-----------|------|
|
||||
| `coze` | excel | 15 | ✅ |
|
||||
| `coze-excel` | excel | 15 | ✅ |
|
||||
| `coze-text` | text | 15 | ✅ |
|
||||
| `kbs` | excel | 15 | ✅ |
|
||||
| `kbs-excel` | excel | 15 | ✅ |
|
||||
| `kbs-text` | text | 15 | ✅ |
|
||||
| `zht` | excel | 15 | ✅ |
|
||||
| `zht-excel` | excel | 15 | ✅ |
|
||||
| `zht-text` | text | 15 | ✅ |
|
||||
| `zhtv2` | excel | 15 | ✅ |
|
||||
| `zhtv2-excel` | excel | 15 | ✅ |
|
||||
| `zhtv2-text` | text | 15 | ✅ |
|
||||
|
||||
---
|
||||
|
||||
## 📝 使用方法
|
||||
|
||||
### 1. 评估单个系统的特定类型
|
||||
|
||||
```bash
|
||||
# 评估 Coze 的 excel 类型
|
||||
python scripts/evaluate_single_system.py --system coze-excel
|
||||
|
||||
# 评估 Coze 的 text 类型
|
||||
python scripts/evaluate_single_system.py --system coze-text
|
||||
|
||||
# 评估 KBS 的 excel 类型
|
||||
python scripts/evaluate_single_system.py --system kbs-excel
|
||||
|
||||
# 评估 ZHT 的 text 类型
|
||||
python scripts/evaluate_single_system.py --system zht-text
|
||||
```
|
||||
|
||||
### 2. 对比同一系统的两种类型
|
||||
|
||||
```bash
|
||||
# 批量评估 ZHT 的两种类型
|
||||
python scripts/evaluate_all_systems.py --systems zht-excel,zht-text --output results/zht_comparison.json
|
||||
```
|
||||
|
||||
### 3. 评估所有系统的所有类型
|
||||
|
||||
```bash
|
||||
python scripts/evaluate_all_systems.py \
|
||||
--systems coze-excel,coze-text,kbs-excel,kbs-text,zht-excel,zht-text,zhtv2-excel,zhtv2-text \
|
||||
--output results/all_systems_all_types.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📊 生成的报告格式
|
||||
|
||||
### 单系统报告(如 `coze-excel`)
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"systems": ["coze-excel"]
|
||||
},
|
||||
"results": {
|
||||
"coze-excel": {
|
||||
"system": "coze-excel",
|
||||
"positive_cases": {
|
||||
"context_precision": {
|
||||
"mean": 0.85,
|
||||
"median": 0.90,
|
||||
...
|
||||
},
|
||||
...
|
||||
},
|
||||
"overall_score": 0.7250
|
||||
}
|
||||
},
|
||||
"comparison": {
|
||||
"ranking": ["coze-excel"],
|
||||
"best_performer": {
|
||||
"context_precision": "coze-excel",
|
||||
...
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 对比报告(如 `zht-excel,zht-text`)
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"systems": ["zht-excel", "zht-text"]
|
||||
},
|
||||
"results": {
|
||||
"zht-excel": {
|
||||
"overall_score": 0.7250
|
||||
},
|
||||
"zht-text": {
|
||||
"overall_score": 0.6800
|
||||
}
|
||||
},
|
||||
"comparison": {
|
||||
"ranking": ["zht-excel", "zht-text"],
|
||||
"scores": {
|
||||
"zht-excel": 0.7250,
|
||||
"zht-text": 0.6800
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎯 技术亮点
|
||||
|
||||
### 1. 系统名称解析
|
||||
```python
|
||||
# 提取基础系统名(去除后缀)
|
||||
base_system = system.split('-')[0] if '-' in system else system
|
||||
# kbs-excel → kbs
|
||||
# zht-text → zht
|
||||
```
|
||||
|
||||
### 2. 文件路径映射
|
||||
```python
|
||||
if system.endswith('-excel'):
|
||||
file_path = f'{system}-raw-data.json' # coze-excel-raw-data.json
|
||||
elif system.endswith('-text'):
|
||||
file_path = f'{system}-raw-data.json' # coze-text-raw-data.json
|
||||
else:
|
||||
file_path = f'{system}-excel-raw-data.json' # 向后兼容
|
||||
```
|
||||
|
||||
### 3. KBS 特殊处理
|
||||
- KBS 系统的数据结构特殊(包含 `sessions` 字段)
|
||||
- 带后缀的系统名也能正确处理
|
||||
- 确保从 `session_name` 正确提取 `question_id`
|
||||
|
||||
---
|
||||
|
||||
## 📚 相关文档
|
||||
|
||||
- **使用指南**: `docs/SYSTEM_TYPE_GUIDE.md` - 详细的使用说明和示例
|
||||
- **测试脚本**: `scripts/test_system_types.py` - 系统类型解析测试
|
||||
- **工作总结**: `docs/WORK_SUMMARY.md` - 整体工作总结
|
||||
|
||||
---
|
||||
|
||||
## ✅ 完成状态
|
||||
|
||||
- [x] 支持所有系统的 `excel` 和 `text` 类型
|
||||
- [x] 修改数据加载逻辑
|
||||
- [x] 修复 KBS 系统的带后缀处理
|
||||
- [x] 创建详细使用文档
|
||||
- [x] 创建测试脚本
|
||||
- [x] 测试验证通过
|
||||
|
||||
**状态**: 🟢 **已完成并可用**
|
||||
|
||||
---
|
||||
|
||||
## 🚀 后续建议
|
||||
|
||||
虽然当前实现已经完成并可用,但还有一些可选的改进方向:
|
||||
|
||||
### 可选功能(未实现)
|
||||
1. **自动对比脚本**:一键生成同一系统两种类型的对比报告
|
||||
2. **可视化报告**:生成图表对比 excel 和 text 类型的表现
|
||||
3. **统一报告**:在报告中同时展示两种类型的数据
|
||||
|
||||
### 当前后发
|
||||
- 用户可以分别评估两种类型
|
||||
- 使用批量评估脚本可以生成对比报告
|
||||
- 手动对比报告中的 `overall_score` 即可
|
||||
|
||||
---
|
||||
|
||||
**最后更新**: 2025-01-08
|
||||
**文档版本**: v1.0
|
||||
@@ -0,0 +1,367 @@
|
||||
# 多类型 RAG 系统评估指南
|
||||
|
||||
## 概述
|
||||
|
||||
所有 RAG 系统(Coze、KBS、ZHT、ZHTv2)都支持 `excel` 和 `text` 两种数据类型的评估。
|
||||
|
||||
---
|
||||
|
||||
## 支持的系统名称
|
||||
|
||||
### 基础系统(向后兼容)
|
||||
- `coze` - Coze 系统(默认使用 excel 数据)
|
||||
- `kbs` - KBS 系统(默认使用 excel 数据)
|
||||
- `zht` - ZHT 系统(默认使用 excel 数据)
|
||||
- `zhtv2` - ZHTv2 系统(默认使用 excel 数据)
|
||||
|
||||
### 带类型后缀的系统
|
||||
- `coze-excel` - Coze 系统的 excel 数据
|
||||
- `coze-text` - Coze 系统的 text 数据
|
||||
- `kbs-excel` - KBS 系统的 excel 数据
|
||||
- `kbs-text` - KBS 系统的 text 数据
|
||||
- `zht-excel` - ZHT 系统的 excel 数据
|
||||
- `zht-text` - ZHT 系统的 text 数据
|
||||
- `zhtv2-excel` - ZHTv2 系统的 excel 数据
|
||||
- `zhtv2-text` - ZHTv2 系统的 text 数据
|
||||
|
||||
---
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 1. 评估单个系统(使用默认数据类型)
|
||||
|
||||
```bash
|
||||
# ZHT 系统(默认使用 excel 数据)
|
||||
python scripts/evaluate_single_system.py --system zht
|
||||
|
||||
# ZHTv2 系统(默认使用 excel 数据)
|
||||
python scripts/evaluate_single_system.py --system zhtv2
|
||||
```
|
||||
|
||||
### 2. 评估特定数据类型
|
||||
|
||||
```bash
|
||||
# 评估 ZHT 的 excel 数据
|
||||
python scripts/evaluate_single_system.py --system zht-excel
|
||||
|
||||
# 评估 ZHT 的 text 数据
|
||||
python scripts/evaluate_single_system.py --system zht-text
|
||||
|
||||
# 评估 ZHTv2 的 excel 数据
|
||||
python scripts/evaluate_single_system.py --system zhtv2-excel
|
||||
|
||||
# 评估 ZHTv2 的 text 数据
|
||||
python scripts/evaluate_single_system.py --system zhtv2-text
|
||||
```
|
||||
|
||||
### 3. 对比评估
|
||||
|
||||
#### 方案 A:分别评估并手动对比
|
||||
```bash
|
||||
# 评估 ZHT excel 类型
|
||||
python scripts/evaluate_single_system.py --system zht-excel --output data/results/zht_excel_report.json
|
||||
|
||||
# 评估 ZHT text 类型
|
||||
python scripts/evaluate_single_system.py --system zht-text --output data/results/zht_text_report.json
|
||||
|
||||
# 然后手动对比两个报告文件
|
||||
```
|
||||
|
||||
#### 方案 B:使用批量评估脚本对比
|
||||
```bash
|
||||
# 同时评估 ZHT 的两种类型
|
||||
python scripts/evaluate_all_systems.py --systems zht-excel,zht-text
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 报告格式
|
||||
|
||||
### 单系统报告
|
||||
|
||||
当评估 `zht-excel` 或 `zht-text` 时,生成的报告结构:
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"version": "1.0",
|
||||
"evaluation_date": "2025-01-08T12:00:00",
|
||||
"test_set": "data/test_sets/ragas_test_cases_v3.1.json",
|
||||
"systems": ["zht-excel"]
|
||||
},
|
||||
"results": {
|
||||
"zht-excel": {
|
||||
"system": "zht-excel",
|
||||
"timestamp": "2025-01-08T12:00:00",
|
||||
"positive_cases": {
|
||||
"context_precision": {
|
||||
"mean": 0.8500,
|
||||
"median": 0.9000,
|
||||
"std": 0.1200,
|
||||
"min": 0.5000,
|
||||
"max": 1.0000,
|
||||
"count": 10,
|
||||
"per_question": {
|
||||
"q001": 0.95,
|
||||
"q002": 0.80,
|
||||
...
|
||||
}
|
||||
},
|
||||
"context_recall": { ... },
|
||||
"faithfulness": { ... },
|
||||
"answer_relevance": { ... },
|
||||
"answer_correctness": { ... }
|
||||
},
|
||||
"negative_cases": {
|
||||
"faithfulness": { ... },
|
||||
"rejection_rate": { ... }
|
||||
},
|
||||
"overall_score": 0.7250
|
||||
}
|
||||
},
|
||||
"comparison": {
|
||||
"best_performer": {
|
||||
"context_precision": "zht-excel",
|
||||
...
|
||||
},
|
||||
"ranking": ["zht-excel"],
|
||||
"scores": {
|
||||
"zht-excel": 0.7250
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 对比报告
|
||||
|
||||
当同时评估 `zht-excel` 和 `zht-text` 时:
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"systems": ["zht-excel", "zht-text"]
|
||||
},
|
||||
"results": {
|
||||
"zht-excel": {
|
||||
"overall_score": 0.7250,
|
||||
...
|
||||
},
|
||||
"zht-text": {
|
||||
"overall_score": 0.6800,
|
||||
...
|
||||
}
|
||||
},
|
||||
"comparison": {
|
||||
"best_performer": {
|
||||
"context_precision": "zht-excel",
|
||||
"answer_relevance": "zht-text",
|
||||
...
|
||||
},
|
||||
"ranking": ["zht-excel", "zht-text"],
|
||||
"scores": {
|
||||
"zht-excel": 0.7250,
|
||||
"zht-text": 0.6800
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 数据文件说明
|
||||
|
||||
### 所有系统的数据文件
|
||||
|
||||
```
|
||||
data/test_sets/
|
||||
├── coze-excel-raw-data.json # Coze excel 类型的验证数据
|
||||
├── coze-text-raw-data.json # Coze text 类型的验证数据
|
||||
├── kbs-excel-raw-data.json # KBS excel 类型的验证数据
|
||||
├── kbs-text-raw-data.json # KBS text 类型的验证数据
|
||||
├── zht-excel-raw-data.json # ZHT excel 类型的验证数据
|
||||
├── zht-text-raw-data.json # ZHT text 类型的验证数据
|
||||
├── zhtv2-excel-raw-data.json # ZHTv2 excel 类型的验证数据
|
||||
└── zhtv2-text-raw-data.json # ZHTv2 text 类型的验证数据
|
||||
```
|
||||
|
||||
### 数据格式差异
|
||||
|
||||
**Excel 类型**:
|
||||
- 从 Excel 文件导入的 FAQ 数据
|
||||
- 结构化程度较高
|
||||
- 适合表格形式的知识
|
||||
- 字段划分明确
|
||||
|
||||
**Text 类型**:
|
||||
- 从文本文件导入的 FAQ 数据
|
||||
- 可能包含更多上下文信息
|
||||
- 适合自然语言形式的知识
|
||||
- 保留原始文本格式
|
||||
|
||||
---
|
||||
|
||||
## 对比分析建议
|
||||
|
||||
### 1. 查看日志文件
|
||||
|
||||
```bash
|
||||
# 查看 zht-excel 的日志
|
||||
cat logs/zht-excel_evaluation_*.log | grep "overall_score"
|
||||
|
||||
# 查看 zht-text 的日志
|
||||
cat logs/zht-text_evaluation_*.log | grep "overall_score"
|
||||
```
|
||||
|
||||
### 2. 提取关键指标
|
||||
|
||||
```python
|
||||
import json
|
||||
|
||||
# 读取两个报告
|
||||
with open('data/results/zht_excel_report.json', 'r', encoding='utf-8') as f:
|
||||
excel_report = json.load(f)
|
||||
|
||||
with open('data/results/zht_text_report.json', 'r', encoding='utf-8') as f:
|
||||
text_report = json.load(f)
|
||||
|
||||
# 对比总体得分
|
||||
excel_score = excel_report['results']['zht-excel']['overall_score']
|
||||
text_score = text_report['results']['zht-text']['overall_score']
|
||||
|
||||
print(f"ZHT Excel 总分: {excel_score:.4f}")
|
||||
print(f"ZHT Text 总分: {text_score:.4f}")
|
||||
print(f"差异: {excel_score - text_score:.4f}")
|
||||
|
||||
# 对比各指标
|
||||
for metric in ['context_precision', 'context_recall', 'faithfulness', 'answer_relevance', 'answer_correctness']:
|
||||
excel_mean = excel_report['results']['zht-excel']['positive_cases'][metric]['mean']
|
||||
text_mean = text_report['results']['zht-text']['positive_cases'][metric]['mean']
|
||||
diff = excel_mean - text_mean
|
||||
print(f"{metric:20s}: Excel={excel_mean:.4f}, Text={text_mean:.4f}, 差异={diff:+.4f}")
|
||||
```
|
||||
|
||||
### 3. 生成对比表格
|
||||
|
||||
```bash
|
||||
# 使用批量评估生成对比报告
|
||||
python scripts/evaluate_all_systems.py --systems zht-excel,zht-text --output data/results/zht_comparison.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 常见问题
|
||||
|
||||
### Q1: 为什么默认使用 excel 数据?
|
||||
|
||||
**A**: 为了向后兼容。原有的评估脚本默认使用 excel 数据,现在保持这个行为。
|
||||
|
||||
### Q2: 如何知道应该评估哪种类型?
|
||||
|
||||
**A**: 根据你的需求:
|
||||
- 如果 RAG 系统主要处理 Excel 知识库,评估 `excel` 类型
|
||||
- 如果 RAG 系统主要处理文本知识库,评估 `text` 类型
|
||||
- 如果两种都用,分别评估并对比
|
||||
|
||||
### Q3: 可以同时评估两种类型吗?
|
||||
|
||||
**A**: 可以,有两种方式:
|
||||
1. 使用批量评估:`--systems zht-excel,zht-text`
|
||||
2. 分别评估后再对比
|
||||
|
||||
### Q4: 两种类型的评估结果可以合并吗?
|
||||
|
||||
**A**: 当前版本**不支持自动合并**。两种类型的数据结构和处理方式不同,建议:
|
||||
- 分别评估
|
||||
- 分别分析
|
||||
- 根据实际使用场景选择参考哪种结果
|
||||
|
||||
---
|
||||
|
||||
## 示例工作流
|
||||
|
||||
### 场景 1:只想评估一种类型
|
||||
|
||||
```bash
|
||||
# 评估 ZHT 的 excel 类型(推荐)
|
||||
python scripts/evaluate_single_system.py --system zht-excel
|
||||
```
|
||||
|
||||
### 场景 2:对比两种类型的表现
|
||||
|
||||
```bash
|
||||
# 方式 1:批量评估
|
||||
python scripts/evaluate_all_systems.py --systems zht-excel,zht-text
|
||||
|
||||
# 方式 2:分别评估
|
||||
python scripts/evaluate_single_system.py --system zht-excel --output results/zht_excel.json
|
||||
python scripts/evaluate_single_system.py --system zht-text --output results/zht_text.json
|
||||
```
|
||||
|
||||
### 场景 3:评估所有系统和类型
|
||||
|
||||
```bash
|
||||
# 评估所有系统(每种系统只评估 excel 类型)
|
||||
python scripts/evaluate_all_systems.py --systems coze,kbs,zht,zhtv2
|
||||
|
||||
# 评估所有系统的两种类型
|
||||
python scripts/evaluate_all_systems.py \
|
||||
--systems coze-excel,coze-text,kbs-excel,kbs-text,zht-excel,zht-text,zhtv2-excel,zhtv2-text \
|
||||
--output results/all_systems_comparison.json
|
||||
|
||||
# 评估所有系统的 excel 类型
|
||||
python scripts/evaluate_all_systems.py \
|
||||
--systems coze-excel,kbs-excel,zht-excel,zhtv2-excel \
|
||||
--output results/excel_types_comparison.json
|
||||
|
||||
# 评估所有系统的 text 类型
|
||||
python scripts/evaluate_all_systems.py \
|
||||
--systems coze-text,kbs-text,zht-text,zhtv2-text \
|
||||
--output results/text_types_comparison.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 技术细节
|
||||
|
||||
### 系统名称解析规则
|
||||
|
||||
1. **带后缀的系统名**:
|
||||
- `zht-excel` → 使用 `zht-excel-raw-data.json`
|
||||
- `zht-text` → 使用 `zht-text-raw-data.json`
|
||||
|
||||
2. **不带后缀的系统名**:
|
||||
- `zht` → 优先使用 `zht-excel-raw-data.json`
|
||||
- 如果 excel 不存在,则使用 `zht-text-raw-data.json`
|
||||
|
||||
3. **其他系统**:
|
||||
- `coze`, `kbs` → 使用 `coze-raw-data.json`, `kbs-raw-data.json`(如果存在)
|
||||
|
||||
### 文件查找逻辑
|
||||
|
||||
```python
|
||||
if system.endswith('-excel'):
|
||||
file_path = f'{system}-raw-data.json' # zht-excel-raw-data.json
|
||||
elif system.endswith('-text'):
|
||||
file_path = f'{system}-raw-data.json' # zht-text-raw-data.json
|
||||
else:
|
||||
file_path = f'{system}-excel-raw-data.json' # zht-excel-raw-data.json
|
||||
if not exists:
|
||||
file_path = f'{system}-text-raw-data.json' # zht-text-raw-data.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 更新日志
|
||||
|
||||
**2025-01-08**:
|
||||
- 添加对系统名后缀的支持(`-excel`, `-text`)
|
||||
- 更新数据加载逻辑
|
||||
- 更新评估脚本参数说明
|
||||
- 创建本使用指南
|
||||
|
||||
---
|
||||
|
||||
**相关文档**:
|
||||
- [日志记录指南](LOGGING_GUIDE.md)
|
||||
- [工作总结](WORK_SUMMARY.md)
|
||||
- [进度追踪](progress/TODO.md)
|
||||
@@ -28,8 +28,7 @@ def parse_args():
|
||||
'--system',
|
||||
type=str,
|
||||
required=True,
|
||||
choices=['coze', 'kbs', 'zht', 'zhtv2'],
|
||||
help='要评估的系统名称'
|
||||
help='要评估的系统名称 (coze, kbs, zht, zhtv2, zht-excel, zht-text, zhtv2-excel, zhtv2-text)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--test-set',
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试多类型系统名称解析
|
||||
|
||||
验证 zht-excel 和 zht-text 系统名称是否正确工作
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 设置 Windows 控制台编码为 UTF-8
|
||||
if sys.platform == 'win32':
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
|
||||
|
||||
# 添加项目根目录到 Python 路径
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from pathlib import Path
|
||||
from src.transformers.data_converter import DataConverter
|
||||
|
||||
|
||||
def test_system_type_resolution():
|
||||
"""测试系统类型解析"""
|
||||
print("=" * 80)
|
||||
print("测试多类型系统名称解析")
|
||||
print("=" * 80)
|
||||
|
||||
test_cases = [
|
||||
# Coze 系统
|
||||
("coze", "应该使用 excel 数据(默认)"),
|
||||
("coze-excel", "应该使用 excel 数据"),
|
||||
("coze-text", "应该使用 text 数据"),
|
||||
# KBS 系统
|
||||
("kbs", "应该使用 excel 数据(默认)"),
|
||||
("kbs-excel", "应该使用 excel 数据"),
|
||||
("kbs-text", "应该使用 text 数据"),
|
||||
# ZHT 系统
|
||||
("zht", "应该使用 excel 数据(默认)"),
|
||||
("zht-excel", "应该使用 excel 数据"),
|
||||
("zht-text", "应该使用 text 数据"),
|
||||
# ZHTv2 系统
|
||||
("zhtv2", "应该使用 excel 数据(默认)"),
|
||||
("zhtv2-excel", "应该使用 excel 数据"),
|
||||
("zhtv2-text", "应该使用 text 数据"),
|
||||
]
|
||||
|
||||
test_set_path = "data/test_sets/ragas_test_cases_v3.1.json"
|
||||
|
||||
for system_name, description in test_cases:
|
||||
print(f"\n测试: {system_name}")
|
||||
print(f"说明: {description}")
|
||||
|
||||
try:
|
||||
# 创建数据转换器
|
||||
converter = DataConverter(test_set_path)
|
||||
|
||||
# 尝试加载数据
|
||||
validation_results = converter.load_validation_results(system_name)
|
||||
|
||||
# 显示结果
|
||||
print(f"✅ 成功加载数据")
|
||||
print(f" 数据条目数: {len(validation_results)}")
|
||||
|
||||
# 显示前2条数据
|
||||
if len(validation_results) > 0:
|
||||
print(f" 示例数据:")
|
||||
for i, item in enumerate(validation_results[:2], 1):
|
||||
qid = item.get('question_id', 'unknown')
|
||||
print(f" {i}. question_id: {qid}")
|
||||
|
||||
except FileNotFoundError as e:
|
||||
print(f"❌ 错误: {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ 意外错误: {e}")
|
||||
|
||||
print("\n" + "=" * 80)
|
||||
print("测试完成")
|
||||
print("=" * 80)
|
||||
|
||||
|
||||
def test_file_paths():
|
||||
"""测试文件路径"""
|
||||
print("\n" + "=" * 80)
|
||||
print("验证数据文件存在性")
|
||||
print("=" * 80)
|
||||
|
||||
test_dir = Path("data/test_sets")
|
||||
|
||||
files_to_check = [
|
||||
"coze-excel-raw-data.json",
|
||||
"coze-text-raw-data.json",
|
||||
"kbs-excel-raw-data.json",
|
||||
"kbs-text-raw-data.json",
|
||||
"zht-excel-raw-data.json",
|
||||
"zht-text-raw-data.json",
|
||||
"zhtv2-excel-raw-data.json",
|
||||
"zhtv2-text-raw-data.json",
|
||||
]
|
||||
|
||||
for filename in files_to_check:
|
||||
file_path = test_dir / filename
|
||||
exists = file_path.exists()
|
||||
status = "✅ 存在" if exists else "❌ 不存在"
|
||||
|
||||
if exists:
|
||||
size_kb = file_path.stat().st_size / 1024
|
||||
print(f"{filename:35s} {status} ({size_kb:.1f} KB)")
|
||||
else:
|
||||
print(f"{filename:35s} {status}")
|
||||
|
||||
print("=" * 80)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_file_paths()
|
||||
print()
|
||||
test_system_type_resolution()
|
||||
@@ -29,18 +29,31 @@ class DataConverter:
|
||||
加载验证结果
|
||||
|
||||
Args:
|
||||
system: 系统名称 (coze/kbs/zht/zhtv2)
|
||||
system: 系统名称 (coze/kbs/zht/zhtv2 或 zht-excel/zht-text)
|
||||
data_dir: 数据目录
|
||||
|
||||
Returns:
|
||||
验证结果列表
|
||||
"""
|
||||
# 优先使用 excel 格式数据
|
||||
file_path = Path(data_dir) / f'{system}-excel-raw-data.json'
|
||||
|
||||
if not file_path.exists():
|
||||
# 尝试 text 格式
|
||||
file_path = Path(data_dir) / f'{system}-text-raw-data.json'
|
||||
支持的系统名称格式:
|
||||
- zht: 默认使用 excel 数据(向后兼容)
|
||||
- zht-excel: 明确使用 excel 数据
|
||||
- zht-text: 明确使用 text 数据
|
||||
"""
|
||||
# 检查是否有明确的类型后缀
|
||||
if system.endswith('-excel'):
|
||||
# 明确指定使用 excel 数据
|
||||
file_path = Path(data_dir) / f'{system}-raw-data.json'
|
||||
elif system.endswith('-text'):
|
||||
# 明确指定使用 text 数据
|
||||
file_path = Path(data_dir) / f'{system}-raw-data.json'
|
||||
else:
|
||||
# 没有后缀,优先使用 excel 格式(向后兼容)
|
||||
file_path = Path(data_dir) / f'{system}-excel-raw-data.json'
|
||||
|
||||
if not file_path.exists():
|
||||
# 尝试 text 格式
|
||||
file_path = Path(data_dir) / f'{system}-text-raw-data.json'
|
||||
|
||||
if not file_path.exists():
|
||||
raise FileNotFoundError(f"Cannot find validation data for system: {system}")
|
||||
@@ -50,7 +63,9 @@ class DataConverter:
|
||||
|
||||
# KBS 系统特殊处理:数据在 sessions 字段下
|
||||
# 结构: {metadata: {...}, sessions: [{session_name, api_response: {data: [...]}}]}
|
||||
if system == 'kbs' and isinstance(data, dict):
|
||||
# 支持带后缀的系统名(如 kbs-excel, kbs-text)
|
||||
base_system = system.split('-')[0] if '-' in system else system
|
||||
if base_system == 'kbs' and isinstance(data, dict):
|
||||
if 'sessions' in data:
|
||||
# 新格式:从 sessions 中提取数据
|
||||
results = []
|
||||
@@ -89,8 +104,9 @@ class DataConverter:
|
||||
"""
|
||||
retrieved_contexts = []
|
||||
|
||||
# KBS 系统特殊处理
|
||||
if system == 'kbs':
|
||||
# KBS 系统特殊处理(支持带后缀的系统名)
|
||||
base_system = system.split('-')[0] if '-' in system else system
|
||||
if base_system == 'kbs':
|
||||
# 新格式:从 data[0].fileSource 中提取检索上下文
|
||||
data_list = validation_result.get('data', [])
|
||||
|
||||
@@ -154,8 +170,9 @@ class DataConverter:
|
||||
Returns:
|
||||
RAGAs 格式的数据
|
||||
"""
|
||||
# KBS 系统特殊处理
|
||||
if system == 'kbs':
|
||||
# KBS 系统特殊处理(支持带后缀的系统名)
|
||||
base_system = system.split('-')[0] if '-' in system else system
|
||||
if base_system == 'kbs':
|
||||
# 新格式:data 字段直接包含问题数据数组
|
||||
data_list = validation_result.get('data', [])
|
||||
|
||||
|
||||
Reference in new issue
Block a user