AI-powered natural language to SQL converter with semantic caching and agentic UI.
# 1. Set your OpenAI API key
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY
# 2. Start all services
docker-compose up -d
# 3. Open http://localhost:3000- 🤖 Agentic UI with CopilotKit: Interactive AI chat interface
- 🔄 Hierarchical Multi-Agent System: Cache → SQL Generator → Executor
- ⚡ Semantic Caching: Lightning-fast query retrieval with Qdrant
- 🗄️ Universal Database Support: Works with any SQLAlchemy-supported database
- 🎯 Automatic Schema Detection: Reads your database structure dynamically
- 🐳 Docker Compose Stack: One command to run everything
- 👍👎 RL Feedback Loop: Human feedback improves SQL generation over time
- 2+ thumbs down: Warning - query type needs review
- 3+ thumbs down: Critical - agent needs retraining
- 2+ thumbs up: Good performance
- 3+ thumbs up: Excellent - consistently performing well
- Frontend (Port 3000): Next.js + CopilotKit UI
- Backend (Port 8000): FastAPI + LangGraph
- Qdrant (Port 6333): Vector database for caching
- Open http://localhost:3000
- Type a natural language question
- View generated SQL and results
- Provide feedback: Click thumbs up/down to train the AI
- Thumbs up: Query is correct
- Thumbs down: Query is incorrect
- Watch the agent improve over time!
Example Questions:
Show me all customers from California
What are the top 5 best-selling products?
What is the total revenue by category?
Which customers spent more than $500?
The agent learns from your feedback:
- First query: No feedback data, generates SQL normally
- After 2 thumbs down:
⚠️ Warning shown, agent becomes more careful - After 3 thumbs down: 🚨 Critical alert, agent needs retraining
- After 2 thumbs up: ✅ Good performance indicator
- After 3 thumbs up: 🌟 Excellent performance, agent continues approach
The system uses similar successful queries as examples for future generations.
curl -X POST http://localhost:8000/api/query \
-H "Content-Type: application/json" \
-d '{"question": "Show me all customers"}'Update backend/.env:
# PostgreSQL
DATABASE_URL=postgresql://user:password@localhost:5432/mydb
# MySQL
DATABASE_URL=mysql://user:password@localhost:3306/mydb
# SQLite (default)
DATABASE_URL=sqlite:///./test.dbThe system automatically detects your schema!
start-dev.batThis will start:
- Qdrant (if not running)
- Backend on port 8000
- Frontend on port 3000
Backend:
cd backend
pip install -r requirements.txt
python -m uvicorn api:app --reload --host 0.0.0.0 --port 8000Frontend:
cd frontend
npm install
npm run dev.
├── backend/
│ ├── main.py # Text2SQL implementation
│ ├── api.py # FastAPI REST API
│ ├── Dockerfile
│ └── requirements.txt
├── frontend/
│ ├── app/ # Next.js app
│ ├── components/ # React components
│ ├── Dockerfile
│ └── package.json
├── docker-compose.yml # Docker orchestration
├── setup.bat # Windows setup script
└── README.md
# Start services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
# Rebuild
docker-compose up -d --build
# Clean slate
docker-compose down -vEdit backend/main.py, QdrantCache.search() method (default: 0.85)
Edit agent nodes in backend/main.py (default: gpt-4)
┌─────────────┐
│ Frontend │ :3000 (Next.js + CopilotKit)
└──────┬──────┘
│
▼
┌─────────────┐
│ Backend │ :8000 (FastAPI + LangGraph)
└──────┬──────┘
│
├──────────┐
▼ ▼
┌──────────┐ ┌────────┐
│ Qdrant │ │ DB │
│ :6333 │ │ SQLite │
└──────────┘ └────────┘
User Question → Cache Agent → [Cache Hit?]
├─ Yes → Executor → Results
└─ No → SQL Generator → Executor → Results
Includes a shopping/sales database with:
- customers: Customer information
- products: Product catalog
- sales: Transaction records
- sales_summary: Daily metrics
POST /api/query- Execute natural language queryPOST /api/feedback- Submit thumbs up/down feedbackGET /api/feedback/stats- Get overall feedback statisticsGET /api/schema- Get database schemaGET /health- Health checkGET /docs- API documentation
docker info # Check Docker is running
docker-compose logs -f # View logsEdit docker-compose.yml ports section
Verify .env has valid OPENAI_API_KEY
- Docker Desktop
- OpenAI API key
- 4GB RAM minimum
MIT