A comprehensive web application demonstrating semantic caching capabilities using Redis Cloud and OpenAI, replicating and enhancing the functionality of the original demo_search.py
script.
- Interactive Web Interface: Beautiful, responsive UI built with Bootstrap and Font Awesome
- Single Query Testing: Execute individual queries and observe caching behavior
- Semantic Caching Demo: Run identical queries twice to demonstrate cache performance
- Similarity Demo: Test semantically similar queries to showcase cache effectiveness
- Real-time Performance Metrics: View query timing, cache hit/miss status, and speedup calculations
- Query History: Track all executed queries with timestamps and performance data
- API Status Monitoring: Real-time OpenAI API connectivity and quota status checking
- Accordion Interface: Clean, collapsible response display with proper formatting
- Python 3.8+
- Redis Cloud account and connection string
- OpenAI API key
- Virtual environment (recommended)
-
Clone the repository:
git clone https://github.com/svkmsr6/redis-semantic-cache-demo.git cd redis-semantic-cache-demo
-
Create and activate virtual environment:
python -m venv redis-searchenv # On Windows: redis-searchenv\Scripts\activate # On macOS/Linux: source redis-searchenv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.env
file in the root directory:RDS_URI=your_redis_connection_string OPENAI_API_KEY=your_openai_api_key
python app.py
Then open your browser to: http://localhost:5000
python demo_search.py
- Windows: Double-click
start_webapp.bat
or runstart_webapp.ps1
- Cross-platform: Use the VS Code task "Run Redis Semantic Cache Web App"
The web application provides three main demonstration modes:
- Enter any query to test individual caching behavior
- See real-time performance metrics
- View cache hit/miss status
- Executes the same query twice
- Demonstrates cache performance improvement
- Shows detailed performance analysis with speedup calculations
- Tests semantically similar queries
- Choose from default queries or create custom ones
- Observe how semantic similarity affects caching
redis-semantic-cache/
βββ app.py # Flask web application
βββ demo_search.py # Original command-line demo
βββ rsearch_module/ # Core semantic search functionality
β βββ __init__.py
βββ templates/
β βββ index.html # Web interface template
βββ static/
β βββ style.css # Custom styling
βββ requirements.txt # Python dependencies
βββ start_webapp.bat # Windows launcher
βββ start_webapp.ps1 # PowerShell launcher
βββ README_webapp.md # Web app specific documentation
βββ .env # Environment variables (create this)
The Flask application exposes several REST endpoints:
GET /
- Main web interfaceGET /api/status
- Check OpenAI API statusPOST /api/query
- Execute a single queryPOST /api/demo/caching
- Run caching demonstrationPOST /api/demo/similarity
- Run similarity demonstrationGET /api/history
- Get query historyPOST /api/history/clear
- Clear query history
The application tracks and displays:
- Query Execution Time: Precise timing for each query
- Cache Hit/Miss Status: Visual indicators for cache effectiveness
- Performance Speedup: Calculated improvement from caching
- Time Saved: Actual time savings from cache hits
- Responsive Design: Works on desktop, tablet, and mobile
- Accordion Responses: Clean, collapsible display of AI responses
- Real-time Status: Live API connectivity monitoring
- Performance Metrics: Visual charts and indicators
- Query History: Persistent session history with timestamps
- Backend: Flask, OpenAI API, Redis
- Frontend: Bootstrap 5, Font Awesome, Vanilla JavaScript
- Caching: Redis Vector Library (redisvl) with semantic cache
- Embeddings: Sentence Transformers (all-mpnet-base-v2)
- AI Model: OpenAI GPT-4o-mini
-
API Status Red:
- Check your OpenAI API key in
.env
- Verify billing status at OpenAI dashboard
- Check your OpenAI API key in
-
No Cache Hits:
- Verify Redis connection string
- Check Redis Cloud connectivity
-
Slow Initial Queries:
- Normal behavior for first-time queries
- Subsequent similar queries should be faster
-
Module Import Errors:
- Ensure virtual environment is activated
- Run
pip install -r requirements.txt
QUOTA_EXCEEDED
: Check OpenAI billing and usage limitsAUTH_ERROR
: Verify OpenAI API key is correctRATE_LIMITED
: Wait and retry, or upgrade OpenAI plan
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Redis for powerful caching capabilities
- OpenAI for advanced language models
- Bootstrap team for excellent UI framework
- Sentence Transformers for embedding models
If you encounter any issues or have questions:
- Check the troubleshooting section above
- Review the issues page
- Create a new issue with detailed information
Made with β€οΈ for the Redis and AI community