Skip to main content
This guide walks through implementing a new RAG architecture in the benchmark, from design to evaluation.

Overview

The benchmark currently includes six RAG architectures:
  • Simple Semantic RAG: Direct vector similarity matching
  • Hybrid RAG: BM25 + Semantic ensemble retrieval
  • Hybrid RAG + RRF: Reciprocal Rank Fusion
  • HyDE RAG: Hypothetical document embeddings
  • Query Rewriter RAG: Multi-query reformulation
  • PageIndex RAG: Page-aware retrieval
You can add new architectures by following the established patterns.

Implementation Requirements

Required Function Signature

Every RAG implementation must provide a query_for_evaluation() function:

Return Dictionary Structure

The function must return:

Step-by-Step Implementation

1

Create New RAG Module

Create a new file in src/rag/ for your RAG implementation:
Start with imports and basic setup:
2

Configure Models and Vector Store

Set up the required components:
3

Define Prompt Templates

Create prompts specific to your strategy:
4

Implement Core Processing Function

Create the main processing function for your strategy:
5

Implement Evaluation Wrapper

Create the required query_for_evaluation() function:
6

Integrate with Evaluator

Register your RAG architecture in src/evaluation/ragas_evaluator.py:
Also add evaluation helper function:
7

Update CLI Script

Add your RAG to the evaluation script in scripts/run_evaluation.py:

Testing Your Implementation

Unit Testing

Create a test file to verify basic functionality:

Interactive Testing

Run your implementation directly:

Evaluation Testing

Run a full evaluation:

Evaluation and Analysis

Single Model Evaluation

Multi-Model Comparison

Comprehensive Benchmark

Performance Considerations

Optimization Tips

  1. Cache Embeddings: Reuse embeddings when possible
  2. Batch Processing: Process multiple queries together
  3. Async Operations: Use async/await for parallel API calls
  4. Connection Pooling: Reuse HTTP connections

Monitoring Costs

The framework automatically tracks:
  • Input/output tokens per query
  • Cost per query and total cost
  • Execution time
View costs in evaluation results:

Example: Semantic Reranking RAG

Here’s a complete example implementing semantic reranking:

Next Steps

Integrating Models

Test your RAG with different LLMs

Customizing Metrics

Add custom evaluation metrics

API Reference

Explore the complete API

Contributing

Contribute your implementation