Initial commit
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
commit
4ecf7b351d
143 files changed
+24156
No files matched your search
@@ -0,0 +1,186 @@
|
||||
# Quick Start Guide
|
||||
|
||||
## Phase 1 MVP - Testset Generation
|
||||
|
||||
This guide will help you get started with the RAG Evaluation Framework Phase 1 (MVP).
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Python 3.8+
|
||||
- MySQL 5.7+ or 8.0+
|
||||
- pip
|
||||
|
||||
### Installation
|
||||
|
||||
1. **Install dependencies**:
|
||||
```bash
|
||||
cd rag_evaluation
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
2. **Set up environment variables**:
|
||||
```bash
|
||||
cp .env.example .env
|
||||
# Edit .env and add your API keys and database password
|
||||
```
|
||||
|
||||
3. **Configure the framework**:
|
||||
```bash
|
||||
cp config.example.yaml config.yaml
|
||||
# Edit config.yaml to customize settings
|
||||
```
|
||||
|
||||
4. **Initialize database**:
|
||||
```sql
|
||||
-- Create database
|
||||
CREATE DATABASE rag_evaluation CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
|
||||
|
||||
-- Run schema initialization (will be done automatically by example.py)
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
#### Run the example
|
||||
|
||||
```bash
|
||||
python example.py
|
||||
```
|
||||
|
||||
This will:
|
||||
1. Initialize the database schema
|
||||
2. Create a sample document
|
||||
3. Generate a testset with 15 questions
|
||||
4. Save the testset to JSON file
|
||||
5. Demonstrate loading the testset
|
||||
|
||||
#### Generate testset for your knowledge base
|
||||
|
||||
```python
|
||||
from rag_evaluation.core.config import Config
|
||||
from rag_evaluation.testset.generator import TestsetGenerator
|
||||
|
||||
# Load configuration
|
||||
config = Config.from_file("config.yaml")
|
||||
|
||||
# Create generator
|
||||
generator = TestsetGenerator(config)
|
||||
|
||||
# Generate testset
|
||||
testset = generator.generate(
|
||||
knowledge_base_id="your-kb-id",
|
||||
file_paths=[
|
||||
"/path/to/doc1.txt",
|
||||
"/path/to/doc2.md",
|
||||
],
|
||||
test_size=50, # Number of questions
|
||||
name="My Testset"
|
||||
)
|
||||
|
||||
# Save testset
|
||||
file_path = generator.save_testset(testset)
|
||||
print(f"Testset saved to: {file_path}")
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
#### LLM Configuration
|
||||
|
||||
```yaml
|
||||
llm:
|
||||
generator_model: "claude-3-sonnet-20240229"
|
||||
generator_api_base: "https://api.anthropic.com"
|
||||
generator_api_key: "${ANTHROPIC_API_KEY}"
|
||||
|
||||
evaluator_model: "gpt-4"
|
||||
evaluator_api_base: "https://api.openai.com/v1"
|
||||
evaluator_api_key: "${OPENAI_API_KEY}"
|
||||
```
|
||||
|
||||
#### Testset Configuration
|
||||
|
||||
```yaml
|
||||
testset:
|
||||
default_size: 15 # Default number of questions
|
||||
question_distribution:
|
||||
simple: 0.4 # 40% simple questions
|
||||
reasoning: 0.4 # 40% reasoning questions
|
||||
multi_context: 0.2 # 20% multi-context questions
|
||||
```
|
||||
|
||||
#### Sampling Strategy
|
||||
|
||||
```yaml
|
||||
testset:
|
||||
sampling_strategy:
|
||||
small_file_threshold_mb: 1.0 # Files < 1MB
|
||||
medium_file_threshold_mb: 10.0 # Files < 10MB
|
||||
small_file_sampling_rate: 1.0 # 100% sampling
|
||||
medium_file_sampling_rate: 0.4 # 40% sampling
|
||||
large_file_sampling_rate: 0.15 # 15% sampling
|
||||
```
|
||||
|
||||
### Project Structure
|
||||
|
||||
```
|
||||
rag_evaluation/
|
||||
├── core/ # Core configuration
|
||||
│ └── config.py # Configuration management
|
||||
├── testset/ # Testset generation
|
||||
│ ├── document_loader.py # Document loading
|
||||
│ ├── sampling.py # Sampling strategy
|
||||
│ └── generator.py # Testset generator
|
||||
├── storage/ # Data storage
|
||||
│ ├── database.py # Database operations
|
||||
│ └── schema.sql # Database schema
|
||||
├── utils/ # Utilities
|
||||
│ └── helpers.py # Helper functions
|
||||
├── data/ # Data directory (created automatically)
|
||||
│ ├── testsets/ # Generated testsets
|
||||
│ ├── reports/ # Evaluation reports
|
||||
│ └── cache/ # Cache files
|
||||
├── config.example.yaml # Example configuration
|
||||
├── .env.example # Example environment variables
|
||||
├── requirements.txt # Python dependencies
|
||||
└── example.py # Usage example
|
||||
```
|
||||
|
||||
### Next Steps
|
||||
|
||||
Phase 1 (MVP) provides testset generation. The following phases will add:
|
||||
|
||||
- **Phase 2**: Evaluation execution engine (RAG integration, metrics calculation)
|
||||
- **Phase 3**: Report generation (HTML/JSON reports, insights, recommendations)
|
||||
- **Phase 4**: API service
|
||||
- **Phase 5**: CI/CD integration
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
#### Database connection error
|
||||
|
||||
Make sure MySQL is running and credentials in config.yaml are correct:
|
||||
```yaml
|
||||
database:
|
||||
host: "localhost"
|
||||
port: 3306
|
||||
user: "root"
|
||||
password: "${DB_PASSWORD}"
|
||||
```
|
||||
|
||||
#### Import errors
|
||||
|
||||
Make sure you're in the correct directory and dependencies are installed:
|
||||
```bash
|
||||
cd rag_evaluation
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
#### File not found errors
|
||||
|
||||
Check that file paths are absolute or relative to the current working directory.
|
||||
|
||||
### Support
|
||||
|
||||
For issues and questions, please refer to:
|
||||
- OpenSpec documentation: `openspec/changes/add-rag-evaluation-framework/`
|
||||
- Design document: `openspec/changes/add-rag-evaluation-framework/design.md`
|
||||
- Tasks: `openspec/changes/add-rag-evaluation-framework/tasks.md`
|
||||
@@ -0,0 +1,147 @@
|
||||
# 快速运行指南
|
||||
|
||||
## 问题已修复!
|
||||
|
||||
之前的模块导入错误已经修复。现在可以直接运行示例了。
|
||||
|
||||
## 三种运行方式
|
||||
|
||||
### 方式1: 直接运行 (推荐)
|
||||
|
||||
```bash
|
||||
cd rag_evaluation
|
||||
python example.py # Phase 1 - 测评集生成
|
||||
python example_phase2.py # Phase 2 - 评估执行
|
||||
```
|
||||
|
||||
### 方式2: 使用run脚本
|
||||
|
||||
```bash
|
||||
cd rag_evaluation
|
||||
python run.py example.py
|
||||
python run.py example_phase2.py
|
||||
```
|
||||
|
||||
### 方式3: 测试框架
|
||||
|
||||
```bash
|
||||
cd rag_evaluation
|
||||
python test_framework.py
|
||||
```
|
||||
|
||||
## 如果遇到问题
|
||||
|
||||
### 问题1: ModuleNotFoundError
|
||||
|
||||
**解决方案**: 确保你在`rag_evaluation`目录下运行,或使用`run.py`脚本。
|
||||
|
||||
### 问题2: 依赖未安装
|
||||
|
||||
**解决方案**:
|
||||
```bash
|
||||
cd rag_evaluation
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 问题3: 数据库连接失败
|
||||
|
||||
**解决方案**:
|
||||
1. 确保MySQL正在运行
|
||||
2. 创建数据库: `CREATE DATABASE rag_evaluation;`
|
||||
3. 更新`config.example.yaml`中的数据库配置
|
||||
4. 复制配置: `cp config.example.yaml config.yaml`
|
||||
|
||||
## 当前功能
|
||||
|
||||
### Phase 1: 测评集生成 ✅
|
||||
- 加载文档(TXT, Markdown)
|
||||
- 智能分块
|
||||
- 分层采样
|
||||
- 生成测评集
|
||||
- JSON持久化
|
||||
|
||||
### Phase 2: 评估执行 ✅
|
||||
- Mock RAG系统
|
||||
- 7个评估指标
|
||||
- 数据库存储
|
||||
- 结果汇总
|
||||
|
||||
## 示例输出
|
||||
|
||||
### Phase 1 输出示例:
|
||||
```
|
||||
Loading configuration...
|
||||
Initializing database...
|
||||
Database schema initialized successfully
|
||||
|
||||
Generating testset...
|
||||
Created sample file: ./data/sample_docs/sample.txt
|
||||
|
||||
Testset generated:
|
||||
ID: ts-abc123
|
||||
Name: Example Testset
|
||||
Questions: 15
|
||||
|
||||
Saving testset...
|
||||
Testset saved to: ./data/testsets/ts-abc123.json
|
||||
|
||||
✅ Example completed successfully!
|
||||
```
|
||||
|
||||
### Phase 2 输出示例:
|
||||
```
|
||||
============================================================
|
||||
RAG Evaluation Framework - Phase 2 Example
|
||||
============================================================
|
||||
|
||||
[1/6] Loading configuration...
|
||||
✓ Configuration loaded
|
||||
|
||||
[2/6] Initializing database...
|
||||
✓ Database schema initialized
|
||||
|
||||
[3/6] Generating testset...
|
||||
✓ Testset generated: ts-xyz789
|
||||
|
||||
[4/6] Setting up RAG system...
|
||||
✓ Mock RAG system initialized
|
||||
|
||||
[5/6] Executing evaluation...
|
||||
✓ Evaluation completed: eval-def456
|
||||
|
||||
[6/6] Evaluation Results
|
||||
------------------------------------------------------------
|
||||
|
||||
📊 Overall Score: 75.50/100
|
||||
|
||||
📈 Retrieval Metrics:
|
||||
- Context Recall: 0.800
|
||||
- Context Precision: 0.750
|
||||
- MRR: 0.850
|
||||
- NDCG: 0.780
|
||||
|
||||
📝 Generation Metrics:
|
||||
- Faithfulness: 0.720
|
||||
- Answer Relevancy: 0.680
|
||||
- Correctness: 0.650
|
||||
|
||||
✅ Phase 2 Example Completed Successfully!
|
||||
```
|
||||
|
||||
## 下一步
|
||||
|
||||
1. **安装依赖**: `pip install -r requirements.txt`
|
||||
2. **运行Phase 1**: `python example.py`
|
||||
3. **运行Phase 2**: `python example_phase2.py`
|
||||
4. **查看生成的文件**:
|
||||
- 测评集: `./data/testsets/*.json`
|
||||
- 数据库: `rag_evaluation` 数据库
|
||||
|
||||
## 需要帮助?
|
||||
|
||||
查看详细文档:
|
||||
- `README.md` - 项目概述
|
||||
- `QUICKSTART.md` - 快速开始
|
||||
- `PHASE1_SUMMARY.md` - Phase 1详情
|
||||
- `PHASE2_SUMMARY.md` - Phase 2详情
|
||||
- `TESTING_SUMMARY.md` - 测试说明
|
||||
Reference in new issue
Block a user