An interactive platform for exploring and comparing 5 different document re-ranking techniques with real-time evaluation and visualization for improving the accuracy of RAG systems.
- 5 Re-ranking Techniques: Cross-Encoder, LLM-based, Cohere API, Hybrid Pipeline, Learning to Rank
- Interactive Playground: Custom queries/documents + 4 preset categories (Technology, Science, Business, Healthcare)
- Real-time Evaluation: NDCG, MRR, MAP, Precision@K with interactive Plotly visualizations
- Production API: FastAPI backend with comprehensive endpoints and documentation
- Educational Content: Code examples, case studies, and "Lost in the Middle" problem explanation
- Modern UI: Streamlit interface with session persistence, loaders, and downloadable JSON results
- Python 3.8+
- OpenAI API key (for LLM-based re-ranking)
- Cohere API key (for Cohere re-ranking)
# Clone repository
git clone https://github.com/AIAnytime/Re-ranking-Playground
cd Re-ranking-Playground
# Create environment file
echo "OPENAI_API_KEY=your_openai_key_here" > .env
echo "COHERE_API_KEY=your_cohere_key_here" >> .env
# Install dependencies
pip install -r requirements.txtLaunch Streamlit App:
streamlit run app.py🌐 Access: http://localhost:8501
Start FastAPI Backend:
uvicorn api:app --reload🌐 API Docs: http://localhost:8000/docs
| Technique | Accuracy | Speed | Cost | Best Use Case |
|---|---|---|---|---|
| Cross-Encoder | High (0.85-0.95) | Slow (~100ms/doc) | Free | High accuracy needs |
| LLM-based | Very High (0.90-0.98) | Very Slow (1-3s) | High ($0.002/1K tokens) | Complex reasoning |
| Cohere API | High (0.88-0.94) | Fast (~50ms/doc) | Medium ($0.001/search) | Production systems |
| Hybrid Pipeline | High (0.86-0.93) | Medium (~200ms/doc) | Low | Balanced performance |
| Learning to Rank | Medium (0.75-0.85) | Very Fast (~10ms/doc) | Free | High-volume systems |
- Input: Query + Document collection
- Processing: Apply selected re-ranking technique(s)
- Evaluation: Calculate NDCG, MRR, MAP, Precision@K metrics
- Visualization: Interactive charts and comparisons
- Export: Download results as JSON
Stanford research shows LLMs struggle with information in the middle of long contexts, significantly impacting RAG systems:
- Problem: Most relevant documents get lost in middle positions
- Impact: Up to 40% degradation in search quality
- Solution: Re-ranking optimizes document ordering for better LLM processing
POST /rerank- Re-rank documents using specified techniqueGET /health- Health check and model statusGET /- API information
import requests
response = requests.post("http://localhost:8000/rerank", json={
"query": "machine learning applications",
"documents": ["AI in healthcare", "ML in finance", "Deep learning"],
"technique": "cross_encoder",
"top_k": 5
})- Frontend: Streamlit + Custom CSS
- Backend: FastAPI + Async Support
- Models: Sentence Transformers, OpenAI GPT, Cohere API
- Visualization: Plotly Interactive Charts
- ML: scikit-learn, LightGBM, NumPy
Built with ❤️ by AI Anytime & Sonu Kumar
Note: Ensure your API keys are properly configured in the .env file for full functionality.
