186 lines
4.6 KiB
Markdown
186 lines
4.6 KiB
Markdown
# 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`
|