A production-ready Retrieval-Augmented Generation (RAG) system for Formula 1 data, featuring microservices architecture, multiple retrieval strategies, streaming responses, and comprehensive F1 data loading capabilities.
This project combines two powerful systems:
- RAG Microservices - A sophisticated AI-powered chat system for querying F1 data
- F1 Data Loading - Scripts to populate your vector database with comprehensive F1 historical data
- Docker Desktop installed and running
- Pinecone account with API key
- OpenAI API key (for data loading)
- 8GB RAM minimum (16GB recommended)
Create a .env file in the root directory:
# Pinecone (required for both)
PINECONE_API_KEY=your-pinecone-api-key
PINECONE_ENVIRONMENT=us-east-1-aws
PINECONE_INDEX=your-index-name
# OpenAI (required for data loading)
OPENAI_API_KEY=your-openai-api-key
# RAG System Configuration
OLLAMA_MODEL=llama3.1
OLLAMA_HOST=http://ollama:11434
REDIS_HOST=redis
REDIS_PORT=6379
API_URL=http://localhost:8000If you already have data in Pinecone or want to try the system first:
cd rag-microservices
./scripts/setup.sh
./scripts/start.shOpen http://localhost:3000 to use the chat interface.
To populate your Pinecone database with F1 historical data:
cd rag-microservices/data-loading
# Install dependencies
pip install -r requirements-data.txt
# Load complete F1 database (1950-latest)
python ingest_complete_database.py
# OR for quick test with modern data only (2020-latest)
python ingest_complete_database.py --modern-onlyThen start the RAG system as shown in Option A.
.
βββ .env # Environment configuration
βββ .env.example # Example configuration
βββ data/ # F1 CSV data files (optional)
β
βββ rag-microservices/ # Main RAG system
βββ README.md # Detailed RAG documentation
βββ QUICKSTART.md # Quick start guide
βββ GET_STARTED.md # 5-minute setup
βββ PROJECT_SUMMARY.md # Technical overview
β
βββ .env # RAG system config
βββ docker-compose.yml # Service orchestration
β
βββ services/ # Microservices
β βββ rag-service/ # LangChain RAG service
β βββ kong/ # API Gateway
β βββ frontend/ # Next.js UI
β
βββ scripts/ # Deployment scripts
β βββ setup.sh # Initial setup
β βββ start.sh # Start services
β βββ stop.sh # Stop services
β βββ test-api.sh # Test endpoints
β βββ seed-data.sh # Sample data
β
βββ docs/ # Documentation
β βββ DEPLOYMENT.md # Production deployment
β βββ TROUBLESHOOTING.md # Common issues
β
βββ data-loading/ # F1 data loading scripts
βββ README.md # Data loading guide
βββ ingest_complete_database.py
βββ ingest_csv_data.py
βββ ingest_fantasy_data.py
βββ requirements-data.txt
βββ src/ # Data loading modules
- 4 Retrieval Strategies: Similarity, MMR, Multi-Query, Compression
- Streaming Responses: Real-time token-by-token generation
- Conversation Memory: Redis-backed session management
- Kong API Gateway: Rate limiting, CORS, health checks
- Modern Frontend: Next.js with TypeScript and Tailwind CSS
- Local LLM: Ollama (Llama 3.1) for complete privacy
- Production Ready: Docker containerized with health checks
- Comprehensive Data: 1950-present Formula 1 history
- Multiple Sources: CSV files, FastF1 API, Ergast API
- Telemetry Data: Modern races include detailed telemetry
- Fantasy Metrics: Driver value, points potential, recommendations
- Flexible Loading: Complete database or targeted updates
-
Load historical data:
cd rag-microservices/data-loading python ingest_complete_database.py -
Start RAG system:
cd .. ./scripts/start.sh -
Ask questions like:
- "Who won the 2023 Monaco Grand Prix?"
- "What are Lewis Hamilton's career statistics?"
- "Compare Max Verstappen and Charles Leclerc's performance at Monza"
-
Load fantasy-optimized data:
cd rag-microservices/data-loading python ingest_fantasy_data.py -
Start RAG system and ask:
- "Best driver picks for Silverstone?"
- "Which drivers offer the best value this weekend?"
- "Red Bull's historical performance at Spa?"
You can extend the data-loading scripts to ingest your own documents:
- Add your custom data loader in
data-loading/src/ - Follow the pattern in
csv_data_ingestion.py - Run your custom loader to populate Pinecone
- Start the RAG system and chat with your data!
- Backend: Python 3.11, FastAPI, LangChain
- LLM: Ollama (Llama 3.1) - runs locally
- Vector DB: Pinecone (cloud-based)
- Cache/Memory: Redis
- API Gateway: Kong
- Frontend: Next.js 14, TypeScript, Tailwind CSS
- Infrastructure: Docker, Docker Compose
- Processing: Python 3.11, pandas, numpy
- APIs: FastF1, Ergast, OpenF1
- Embeddings: OpenAI text-embedding-3-small
- Vector DB: Pinecone
- GET_STARTED.md - 5-minute setup
- QUICKSTART.md - Detailed guide
- RAG System README - Complete RAG documentation
- Data Loading README - Data ingestion guide
- PROJECT_SUMMARY.md - Architecture overview
- DEPLOYMENT.md - Production deployment
- TROUBLESHOOTING.md - Common issues
Once running, access these services:
- Frontend: http://localhost:3000
- Kong Gateway: http://localhost:8000
- RAG Service: http://localhost:8001/health
The system supports 4 different retrieval strategies:
| Strategy | Best For | Speed |
|---|---|---|
| Similarity | Direct questions | β‘β‘β‘ Fast |
| MMR | Diverse perspectives | β‘β‘ Medium |
| Multi-Query | Complex questions | β‘ Slow |
| Compression | Long documents | β‘ Slow |
Try them all using the frontend's strategy selector!
- Complete DB (1950-latest): ~$10-12 in OpenAI embeddings
- Modern only (2020-latest): ~$3-4
- Updates: ~$1-2 per update
- Ollama: Free (runs locally)
- Pinecone: ~$70-100/month (Starter plan)
- Hosting: $50-200/month (if deploying to cloud)
This is a development/demo configuration. For production:
- Add authentication to Kong (JWT/Key Auth plugins)
- Use SSL/TLS with reverse proxy (Nginx + Let's Encrypt)
- Secure environment variables (AWS Secrets Manager, etc.)
- Implement proper network isolation
- Enable audit logging
See DEPLOYMENT.md for details.
βββββββββββββββ
β Browser β
ββββββββ¬βββββββ
β
β
βββββββββββββββ
β Frontend β β Next.js UI
β :3000 β
ββββββββ¬βββββββ
β
β
βββββββββββββββ
β Kong β β API Gateway
β :8000 β
ββββββββ¬βββββββ
β
β
ββββββββ
β RAG β β LangChain Service
β:8001 β
βββββ¬βββ
β
βββββ΄βββββββββββ
β β
ββββββββββββ βββββββββββ
β Pinecone β β Ollama β β Infrastructure
β Vector β β + Redis β (Data + AI)
β DB β β β
ββββββββββββ βββββββββββ
β
β
[Offline Data Loading]
data-loading/ scripts
populate Pinecone
cd rag-microservices
./scripts/test-api.sh# All services
docker-compose logs -f
# Specific service
docker-compose logs -f rag-servicedocker-compose up -d --build rag-serviceThis is a complete, standalone project. Feel free to fork and customize for your needs!
MIT License - use freely for your projects.
- Check TROUBLESHOOTING.md
- Review service logs:
docker-compose logs - Verify environment configuration in
.env - Ensure all services are healthy:
docker ps
- Configure your environment variables in
.env - Choose your path:
- Load F1 data β Use for F1 queries
- Skip data β Use with your own documents
- Start the RAG system:
cd rag-microservices && ./scripts/start.sh - Open http://localhost:3000
- Explore different retrieval strategies
- Deploy to production when ready
Built with: LangChain β’ Ollama β’ Pinecone β’ Kong β’ Next.js β’ FastAPI β’ Redis
Ready to query your F1 knowledge base! ποΈπ