MealDB RAG System - A fast Retrieval-Augmented Generation system for recipe search using TheMealDB API with local caching and SQLite FTS5 indexing.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .envpython -m src.cli init# Basic search
python -m src.cli ask "How to make pasta?"
# With SQL mode (requires API key)
python -m src.cli ask --use-toolfront-sql "List Mexican dishes"- Run
python -m pytest tests/for unit tests - Test data fetching with
python -m src.cli init - Verify search with sample queries
- Check cache efficiency on repeated runs
- Use type hints for all function parameters and returns
- Follow PEP 8 conventions
- Keep functions focused and under 30 lines
- Document complex logic with inline comments
- Use descriptive variable names
-
Cache Layer (
src/cache.py)- File-based caching with expiry
- Reduces API calls to TheMealDB
-
Database (
src/db.py)- SQLite with FTS5 for fast search
- Separate tables for meals and ingredients
- Standalone FTS table for flexibility
-
API Client (
src/mealdb_api.py)- Async fetching with rate limiting
- Fetches by first letter (a-z, 0-9)
-
RAG Engine (
src/rag.py)- Retrieval using FTS5 BM25 scoring
- Optional ToolFront SQL integration
- Context-based answer generation
- Issue: SQLite FTS5 doesn't support UPSERT
- Solution: Use DELETE then INSERT pattern
- Issue: No such package exists
- Solution: FTS5 is built into SQLite, remove from requirements
- Issue: .env not being read
- Solution: Add
load_dotenv()to config.py
- Issue: OpenAI quota limit reached
- Solution: Use different API key or model provider
- Cache API responses (24hr default)
- Use FTS5 for O(log n) search
- Batch database operations
- Async API calls with throttling
- Never commit .env files
- Use .gitignore for sensitive data
- Validate all user inputs for SQL
- Sanitize FTS5 queries
- Add more recipe sources
- Implement semantic search
- Add nutritional analysis
- Create web interface
- Support multi-language queries
- Add meal planning features