This repository demonstrates the application of rerankers as an Advanced RAG (Retrieval-Augmented Generation) technique to improve retrieval performance. The project showcases how reranking can enhance the quality of retrieved documents before they are passed to the generation model.
This project uses uv for fast and reliable dependency management.
- Python 3.10+
- uv package manager
pip install uvuv syncThis will create a virtual environment and install all required dependencies automatically.
Before running the application, you need to start the Milvus vector database:
cd milvus
docker-compose up -dThis will start Milvus using Docker Compose with the configuration provided in milvus/docker-compose.yml.
Copy the example environment file and configure your API key:
cp .env.example .envThen edit the .env file and replace your_openai_api_key_here with your actual OpenAI API key. You can obtain an API key from the OpenAI Platform.
To run the complete pipeline, execute:
uv run src/main.pyThis will run the complete RAG pipeline with reranking evaluation:
- Data Download: Downloads EUR-Lex legal documents
- Vector Database Setup: Creates embeddings using sentence transformers and stores them in Milvus
- Evaluation Dataset Generation: Generates question-answer pairs from selected documents using OpenAI's LLM
- Cross-Encoder Reranking: Initializes a BAAI/bge-reranker model for improving retrieval results
- Retrieval Comparison: Tests retrieval performance with and without reranking across different top-k values (3, 5, 10, 15)
- RAG Evaluation: Performs end-to-end RAG evaluation comparing baseline retrieval vs. reranked retrieval for answer generation
The results are saved as JSON files in the data/ directory for analysis.