173 lines
4.6 KiB
Markdown
173 lines
4.6 KiB
Markdown
# 催收 RAG 评估系统 - 进度追踪
|
||||
|
|
|
|||
|
|
> 更新时间: 2026-01-07
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 📋 项目概览
|
|||
|
|
|
|||
|
|
**项目名称**: 催收 RAG 评估系统
|
|||
|
|
**项目目标**: 使用 RAGAs 框架评估和对比 4 个 RAG 系统(Coze、KBS、ZHT、ZHTv2)在催收 FAQ 场景下的检索质量
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## ✅ 已完成
|
|||
|
|
|
|||
|
|
### 1. 数据验证与结构分析
|
|||
|
|
|
|||
|
|
- ✅ 确认所有测试集和验证结果数据完整
|
|||
|
|
- ✅ 发现 **KBS 数据结构特殊性**:
|
|||
|
|
- Coze/ZHT/ZHTv2: 直接列表 `[{question_id, answer, knowledge_retrieval, ...}]`
|
|||
|
|
- KBS: 嵌套结构 `{metadata: {...}, sessions: [{session_name, api_response: {data: [...]}}]}`
|
|||
|
|
|
|||
|
|
### 2. 评估指标方案设计
|
|||
|
|
|
|||
|
|
| 指标 | 用途 | 输入字段 |
|
|||
|
|
|------|------|---------|
|
|||
|
|
| **Context Precision** | 检索排序质量 | user_input, reference, retrieved_contexts |
|
|||
|
|
| **Context Recall** | 检索覆盖率 | user_input, reference, retrieved_contexts |
|
|||
|
|
| **Faithfulness** | 答案忠实度(无幻觉) | response, retrieved_contexts |
|
|||
|
|
| **Answer Relevance** | 答案相关性 | user_input, response, embeddings |
|
|||
|
|
| **Answer Correctness** | 端到端正确性 | response, reference, embeddings |
|
|||
|
|
|
|||
|
|
**预估成本**: ~$0.17(4系统 × 15用例 × 5指标)
|
|||
|
|
|
|||
|
|
### 3. 核心代码实现
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
src/
|
|||
|
|
├── transformers/
|
|||
|
|
│ └── data_converter.py ✅ 数据转换器(支持KBS特殊结构)
|
|||
|
|
├── evaluators/
|
|||
|
|
│ ├── ragas_evaluator.py ✅ RAGAs评估器(5个核心指标)
|
|||
|
|
│ └── batch_evaluator.py ✅ 批量评估管理器
|
|||
|
|
├── reporters/
|
|||
|
|
│ └── json_reporter.py ✅ JSON报告生成器
|
|||
|
|
└── utils/
|
|||
|
|
└── llm_config.py ✅ LLM配置模块
|
|||
|
|
|
|||
|
|
scripts/
|
|||
|
|
├── evaluate_all_systems.py ✅ 全系统评估脚本
|
|||
|
|
└── evaluate_single_system.py ✅ 单系统评估脚本
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 4. 数据转换验证
|
|||
|
|
|
|||
|
|
- ✅ 所有 4 个系统数据加载成功(各 15 条记录)
|
|||
|
|
- ✅ 正负向用例分离正确(10 正向 + 5 负向)
|
|||
|
|
- ✅ KBS 特殊数据结构处理完成
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 🚧 进行中
|
|||
|
|
|
|||
|
|
### 实际评估测试
|
|||
|
|
|
|||
|
|
- ⏳ 配置 OpenAI API 密钥
|
|||
|
|
- ⏳ 运行小批量测试验证完整流程
|
|||
|
|
- ⏳ 检查 API 成本是否符合预期
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 📅 待办事项
|
|||
|
|
|
|||
|
|
### Phase 4: 测试和优化
|
|||
|
|
|
|||
|
|
- [x] 创建 `scripts/evaluate_all_systems.py`
|
|||
|
|
- [x] 创建 `scripts/evaluate_single_system.py`
|
|||
|
|
- [ ] 配置 .env 文件(OPENAI_API_KEY)
|
|||
|
|
- [ ] 使用 1-2 个测试用例验证完整流程
|
|||
|
|
- [ ] 检查 API 成本是否符合预期
|
|||
|
|
- [ ] 单元测试
|
|||
|
|
- [ ] 文档完善
|
|||
|
|
|
|||
|
|
### Phase 5: 后续扩展
|
|||
|
|
|
|||
|
|
- [ ] 可视化图表(matplotlib/plotly)
|
|||
|
|
- [ ] 错误案例分析
|
|||
|
|
- [ ] Web 界面(可选)
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 📁 数据文件
|
|||
|
|
|
|||
|
|
| 文件 | 状态 | 说明 |
|
|||
|
|
|------|------|------|
|
|||
|
|
| `data/test_sets/ragas_test_cases_v3.1.json` | ✅ | 15个测试用例(推荐使用) |
|
|||
|
|
| `data/test_sets/coze-excel-raw-data.json` | ✅ | Coze 验证结果 |
|
|||
|
|
| `data/test_sets/kbs-excel-raw-data.json` | ✅ | KBS 验证结果(特殊结构) |
|
|||
|
|
| `data/test_sets/zht-excel-raw-data.json` | ✅ | ZHT 验证结果 |
|
|||
|
|
| `data/test_sets/zhtv2-excel-raw-data.json` | ✅ | ZHTv2 验证结果 |
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 🔑 关键技术点
|
|||
|
|
|
|||
|
|
### KBS 数据处理
|
|||
|
|
|
|||
|
|
```python
|
|||
|
|
# KBS 数据在 sessions 字段下,需要特殊处理
|
|||
|
|
# 结构: {metadata: {...}, sessions: [{session_name, api_response: {data: [...]}}]}
|
|||
|
|
if system == 'kbs' and 'sessions' in data:
|
|||
|
|
results = []
|
|||
|
|
for session in data['sessions']:
|
|||
|
|
session_name = session.get('session_name', '')
|
|||
|
|
question_id = session_name.replace('excel-', '').replace('text-', '')
|
|||
|
|
api_response = session.get('api_response', {})
|
|||
|
|
api_data = api_response.get('data', [])
|
|||
|
|
results.append({
|
|||
|
|
'question_id': question_id,
|
|||
|
|
'data': api_data
|
|||
|
|
})
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### RAGAs 指标初始化
|
|||
|
|
|
|||
|
|
```python
|
|||
|
|
from ragas.metrics import (
|
|||
|
|
LLMContextPrecisionWithReference,
|
|||
|
|
LLMContextRecall,
|
|||
|
|
Faithfulness,
|
|||
|
|
ResponseRelevancy,
|
|||
|
|
AnswerCorrectness
|
|||
|
|
)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 📝 使用说明
|
|||
|
|
|
|||
|
|
### 运行全系统评估
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# 配置环境变量
|
|||
|
|
cp .env.example .env
|
|||
|
|
# 编辑 .env 文件,填入 OPENAI_API_KEY
|
|||
|
|
|
|||
|
|
# 运行评估
|
|||
|
|
python scripts/evaluate_all_systems.py
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 运行单系统评估
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
python scripts/evaluate_single_system.py --system coze
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 命令行参数
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
--systems 要评估的系统列表,用逗号分隔 (默认: coze,kbs,zht,zhtv2)
|
|||
|
|
--test-set 测试集路径 (默认: data/test_sets/ragas_test_cases_v3.1.json)
|
|||
|
|
--output 输出报告路径 (默认: data/results/evaluation_report_YYYYMMDD_HHMMSS.json)
|
|||
|
|
--model 评估使用的 LLM 模型 (默认: gpt-4o-mini)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
## 📝 下次工作
|
|||
|
|
|
|||
|
|
1. 配置 OpenAI API 密钥
|
|||
|
|
2. 运行小批量测试验证流程
|
|||
|
|
3. 生成第一批评估报告
|
|||
|
|
4. 分析评估结果
|