Files
auto-ragas/rag_evaluation
2026-01-16 16:01:39 +08:00
..
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00
2026-01-16 16:01:39 +08:00

RAG Evaluation Framework

基于RAGAS的端到端RAG评估框架

功能特性

  • 自动测评集生成: 使用RAGAS从知识库自动生成评估问题
  • 多维度指标: 检索指标(Recall, Precision, MRR, NDCG) + 生成指标(Faithfulness, Relevancy, Correctness)
  • 智能采样: 大文件分层采样策略,控制评估成本
  • 评估报告: HTML/JSON格式,包含汇总、详细分析、改进建议、历史趋势
  • CI/CD集成: 支持自动化评估和回归检测

项目结构

rag_evaluation/
├── core/           # 核心配置和评估器
├── testset/        # 测评集生成
├── evaluation/     # 评估执行引擎
├── report/         # 报告生成
├── storage/        # 数据存储(MySQL + JSON)
├── api/            # REST API
├── utils/          # 工具函数
└── tests/          # 测试套件

快速开始

1. 安装依赖

cd rag_evaluation
pip install -r requirements.txt

或使用安装脚本:

python setup.py

2. 配置

复制并编辑配置文件:

cp config.example.yaml config.yaml
# 编辑 config.yaml 设置数据库连接和API密钥

3. 运行示例

# 方式1: 直接运行 (推荐)
python example.py          # Phase 1 - 测评集生成
python example_phase2.py   # Phase 2 - 评估执行

# 方式2: 使用run脚本
python run.py example.py
python run.py example_phase2.py

# 方式3: 运行测试
python test_framework.py

使用示例

Phase 1: 测评集生成

from rag_evaluation.core.config import Config
from rag_evaluation.testset.generator import TestsetGenerator

# 加载配置
config = Config.from_file("config.yaml")

# 创建生成器
generator = TestsetGenerator(config)

# 生成测评集
testset = generator.generate(
    knowledge_base_id="kb-001",
    file_paths=["/path/to/doc1.txt", "/path/to/doc2.md"],
    test_size=15
)

# 保存测评集
file_path = generator.save_testset(testset)
print(f"Testset saved to: {file_path}")

Phase 2: 评估执行

from rag_evaluation.evaluation import (
    MockRAGRetriever,
    MockRAGGenerator,
    RAGEvaluationAdapter,
    EvaluationExecutor
)

# 设置RAG系统
retriever = MockRAGRetriever()
generator = MockRAGGenerator()
rag_adapter = RAGEvaluationAdapter(retriever, generator)

# 执行评估
executor = EvaluationExecutor(config, rag_adapter)
evaluation_id = executor.execute_evaluation(
    testset_id=testset['id'],
    knowledge_base_id="kb-001",
    testset=testset
)

# 查看结果
summary = executor.get_evaluation_summary(evaluation_id)
print(f"Overall Score: {summary['overall_score']:.2f}/100")

开发状态

当前版本: v0.2.0 (Phase 2 完成)

已完成:

  • Phase 1: 项目结构初始化
  • Phase 1: 测评集生成
  • Phase 2: 评估执行引擎
  • Phase 3: 报告生成 (待实施)
  • Phase 4: API服务 (待实施)
  • Phase 5: CI/CD集成 (待实施)

功能统计:

  • 7个评估指标 ✅
  • 智能采样策略 ✅
  • JSON持久化 ✅
  • MySQL数据库集成 ✅
  • Mock RAG系统 ✅

文档

详细文档请查看 docs/ 目录:

使用指南

阶段总结

测试文档

设计文档

License

MIT