Conversational SQL
Production - Multi-turn SQL refinement, follow-up queries, context tracking
Conversational SQL enables multi-turn interactions where users iteratively refine their queries through follow-up questions. The system maintains conversation context to understand references to previous queries and results.
12.3.8.1Conversation Flow
User: "Show me total sales by region"
-> SQL: SELECT region, SUM(sales) FROM orders GROUP BY region
User: "Filter that to just Q4 2024"
-> SQL: SELECT region, SUM(sales) FROM orders WHERE order_date >= '2024-10-01' AND order_date < '2025-01-01' GROUP BY region
User: "Now sort by sales descending and show top 5"
-> SQL: SELECT region, SUM(sales) AS total_sales FROM orders WHERE order_date >= '2024-10-01' GROUP BY region ORDER BY total_sales DESC LIMIT 5
User: "What about the same thing for Q3?"
-> SQL: SELECT region, SUM(sales) AS total_sales FROM orders WHERE order_date >= '2024-07-01' AND order_date < '2024-10-01' GROUP BY region ORDER BY total_sales DESC LIMIT 5Refinement API
curl -X POST http://localhost:8000/api/v1/bi/sessions/{session_id}/refine \
-H "Content-Type: application/json" \
-H "X-Tenant-ID: acme-corp" \
-d '{"refinement": "Add a filter for the EMEA region only"}'{
"success": true,
"response": "I have added a filter for the EMEA region.",
"sql": "SELECT product_name, SUM(sales) AS total_sales FROM orders WHERE region = 'EMEA' AND order_date >= '2024-10-01' GROUP BY product_name ORDER BY total_sales DESC LIMIT 5",
"visualization": {"type": "bar", "x": "product_name", "y": "total_sales"}
}