Skip to content

Latest commit

Β 

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

F1 RAG Microservices Platform

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.

🏎️ What This Is

This project combines two powerful systems:

  1. RAG Microservices - A sophisticated AI-powered chat system for querying F1 data
  2. F1 Data Loading - Scripts to populate your vector database with comprehensive F1 historical data

πŸš€ Quick Start

1. Prerequisites

  • Docker Desktop installed and running
  • Pinecone account with API key
  • OpenAI API key (for data loading)
  • 8GB RAM minimum (16GB recommended)

2. Configure Environment

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:8000

3. Option A: Start RAG System (No Data Loading)

If you already have data in Pinecone or want to try the system first:

cd rag-microservices
./scripts/setup.sh
./scripts/start.sh

Open http://localhost:3000 to use the chat interface.

3. Option B: Load F1 Data First

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-only

Then start the RAG system as shown in Option A.

πŸ“ Project Structure

.
β”œβ”€β”€ .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

🎯 Features

RAG Microservices

  • 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

F1 Data Loading

  • 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

πŸ”§ Common Use Cases

Use Case 1: Chat About F1 History

  1. Load historical data:

    cd rag-microservices/data-loading
    python ingest_complete_database.py
  2. Start RAG system:

    cd ..
    ./scripts/start.sh
  3. 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"

Use Case 2: F1 Fantasy Assistant

  1. Load fantasy-optimized data:

    cd rag-microservices/data-loading
    python ingest_fantasy_data.py
  2. 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?"

Use Case 3: Load Custom Data

You can extend the data-loading scripts to ingest your own documents:

  1. Add your custom data loader in data-loading/src/
  2. Follow the pattern in csv_data_ingestion.py
  3. Run your custom loader to populate Pinecone
  4. Start the RAG system and chat with your data!

πŸ“Š Technology Stack

RAG System

  • 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

Data Loading

  • Processing: Python 3.11, pandas, numpy
  • APIs: FastF1, Ergast, OpenF1
  • Embeddings: OpenAI text-embedding-3-small
  • Vector DB: Pinecone

πŸ“– Documentation

Quick Start

Main Documentation

Technical Details

🌐 Service URLs

Once running, access these services:

🎨 Retrieval Strategies

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!

πŸ’° Cost Considerations

Data Loading (One-time)

  • Complete DB (1950-latest): ~$10-12 in OpenAI embeddings
  • Modern only (2020-latest): ~$3-4
  • Updates: ~$1-2 per update

Running RAG System

  • Ollama: Free (runs locally)
  • Pinecone: ~$70-100/month (Starter plan)
  • Hosting: $50-200/month (if deploying to cloud)

πŸ” Security Notes

This is a development/demo configuration. For production:

  1. Add authentication to Kong (JWT/Key Auth plugins)
  2. Use SSL/TLS with reverse proxy (Nginx + Let's Encrypt)
  3. Secure environment variables (AWS Secrets Manager, etc.)
  4. Implement proper network isolation
  5. Enable audit logging

See DEPLOYMENT.md for details.

🚦 Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   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

πŸ› οΈ Development

Running Tests

cd rag-microservices
./scripts/test-api.sh

Viewing Logs

# All services
docker-compose logs -f

# Specific service
docker-compose logs -f rag-service

Rebuilding After Changes

docker-compose up -d --build rag-service

🀝 Contributing

This is a complete, standalone project. Feel free to fork and customize for your needs!

πŸ“ License

MIT License - use freely for your projects.

πŸ†˜ Need Help?

  1. Check TROUBLESHOOTING.md
  2. Review service logs: docker-compose logs
  3. Verify environment configuration in .env
  4. Ensure all services are healthy: docker ps

🎯 Next Steps

  1. Configure your environment variables in .env
  2. Choose your path:
    • Load F1 data β†’ Use for F1 queries
    • Skip data β†’ Use with your own documents
  3. Start the RAG system: cd rag-microservices && ./scripts/start.sh
  4. Open http://localhost:3000
  5. Explore different retrieval strategies
  6. Deploy to production when ready

Built with: LangChain β€’ Ollama β€’ Pinecone β€’ Kong β€’ Next.js β€’ FastAPI β€’ Redis

Ready to query your F1 knowledge base! πŸŽοΈπŸ†

About

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.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages