feat: 完成RAGAs评估系统核心功能开发
- 实现评估脚本 (evaluate_all_systems.py, evaluate_single_system.py) - 修复KBS数据结构解析 (sessions -> api_response -> data) - 支持独立的Embedding服务配置 (EMBEDDING_API_BASE, EMBEDDING_API_KEY) - LLM和Embedding配置统一从.env文件读取 - 更新进度文档 (PROGRESS.md, TODO.md) - 添加.env配置文件 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7fe9a7241e
commit
0855789120
11 files changed
+556
-64
No files matched your search
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
评估所有 RAG 系统并生成对比报告
|
||||
|
||||
使用 RAGAs 框架评估多个 RAG 系统在催收 FAQ 场景下的检索质量
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加项目根目录到 Python 路径
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import asyncio
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
from src.evaluators.batch_evaluator import BatchEvaluator
|
||||
from src.reporters.json_reporter import JSONReporter
|
||||
|
||||
|
||||
def parse_args():
|
||||
"""解析命令行参数"""
|
||||
parser = argparse.ArgumentParser(
|
||||
description='评估所有 RAG 系统并生成对比报告'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--systems',
|
||||
type=str,
|
||||
default='coze,kbs,zht,zhtv2',
|
||||
help='要评估的系统列表,用逗号分隔 (默认: coze,kbs,zht,zhtv2)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--test-set',
|
||||
type=str,
|
||||
default='data/test_sets/ragas_test_cases_v3.1.json',
|
||||
help='测试集路径 (默认: data/test_sets/ragas_test_cases_v3.1.json)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--output',
|
||||
type=str,
|
||||
default=None,
|
||||
help='输出报告路径 (默认: data/results/evaluation_report_YYYYMMDD_HHMMSS.json)'
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
async def main():
|
||||
"""主函数"""
|
||||
args = parse_args()
|
||||
|
||||
print("=" * 80)
|
||||
print("催收 RAG 评估系统 - 多系统评估")
|
||||
print("=" * 80)
|
||||
print(f"启动时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
print(f"测试集: {args.test_set}")
|
||||
print(f"评估系统: {args.systems}")
|
||||
print("LLM 和 Embedding 配置从 .env 文件读取")
|
||||
print("=" * 80)
|
||||
|
||||
# 验证测试集文件存在
|
||||
test_set_path = Path(args.test_set)
|
||||
if not test_set_path.exists():
|
||||
print(f"\n[ERROR] 测试集文件不存在: {args.test_set}")
|
||||
return
|
||||
|
||||
# 解析系统列表
|
||||
systems = [s.strip() for s in args.systems.split(',')]
|
||||
|
||||
# 验证系统对应的验证结果文件存在
|
||||
test_dir = test_set_path.parent
|
||||
for system in systems:
|
||||
# 检查 excel-raw-data.json 和 text-raw-data.json
|
||||
excel_path = test_dir / f"{system}-excel-raw-data.json"
|
||||
text_path = test_dir / f"{system}-text-raw-data.json"
|
||||
|
||||
if not excel_path.exists() and not text_path.exists():
|
||||
print(f"\n[WARNING] 系统 {system} 没有找到验证结果文件")
|
||||
print(f" 查找路径: {excel_path}, {text_path}")
|
||||
|
||||
# 创建批量评估器
|
||||
# LLM 和 Embedding 配置从 .env 文件读取
|
||||
print(f"\n初始化评估器...")
|
||||
evaluator = BatchEvaluator(systems, str(test_set_path))
|
||||
print(f"[OK] 评估器初始化完成")
|
||||
|
||||
# 执行评估
|
||||
print(f"\n开始评估...")
|
||||
start_time = datetime.now()
|
||||
|
||||
results = await evaluator.evaluate_all_systems()
|
||||
|
||||
end_time = datetime.now()
|
||||
duration = (end_time - start_time).total_seconds()
|
||||
|
||||
print(f"\n评估完成! 耗时: {duration:.2f} 秒")
|
||||
|
||||
# 生成报告
|
||||
if args.output:
|
||||
output_path = args.output
|
||||
else:
|
||||
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
|
||||
output_path = f"data/results/evaluation_report_{timestamp}.json"
|
||||
|
||||
reporter = JSONReporter()
|
||||
reporter.generate_report(results, output_path)
|
||||
|
||||
print("\n" + "=" * 80)
|
||||
print("评估完成!")
|
||||
print(f"报告已保存至: {output_path}")
|
||||
print("=" * 80)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
||||
Reference in new issue
Block a user