MATIH Platform is in active MVP development. Documentation reflects current implementation status.
12. AI Service
BI Analytics Platform
Chat Sessions

Chat Sessions

Production - Session creation, multi-turn messaging, refinement, history

Chat Sessions manage the conversational lifecycle for BI analytics interactions. Each session maintains state across multiple exchanges, tracking SQL context, visualization preferences, and analysis results.


12.4.1.1Session Lifecycle

# Create a new session
curl -X POST http://localhost:8000/api/v1/bi/sessions \
  -H "Content-Type: application/json" \
  -H "X-Tenant-ID: acme-corp" \
  -d '{"user_id": "user-123"}'
{"session_id": "sess-uuid-456", "tenant_id": "acme-corp", "created_at": "2025-01-15T10:30:00Z"}
# Send a message
curl -X POST http://localhost:8000/api/v1/bi/sessions/sess-uuid-456/messages \
  -H "Content-Type: application/json" \
  -H "X-Tenant-ID: acme-corp" \
  -d '{"message": "Show me monthly revenue for 2024"}'
{
  "success": true,
  "response": "Here is the monthly revenue breakdown for 2024...",
  "intent": "query_data",
  "sql": "SELECT DATE_TRUNC('month', order_date) AS month, SUM(revenue) AS total_revenue FROM orders WHERE YEAR(order_date) = 2024 GROUP BY 1 ORDER BY 1",
  "visualization": {"type": "line", "x": "month", "y": "total_revenue"},
  "data": {"rows": [...], "columns": ["month", "total_revenue"]},
  "insights": ["Revenue peaked in December at $2.1M", "Lowest month was February at $1.2M"],
  "agents_visited": ["router", "sql", "visualization"],
  "execution_time_ms": 2180
}
# Refine current query
curl -X POST http://localhost:8000/api/v1/bi/sessions/sess-uuid-456/refine \
  -H "Content-Type: application/json" \
  -H "X-Tenant-ID: acme-corp" \
  -d '{"refinement": "Break this down by product category"}'
 
# Change visualization
curl -X POST http://localhost:8000/api/v1/bi/sessions/sess-uuid-456/visualization \
  -H "Content-Type: application/json" \
  -d '{"chart_type": "stacked_bar"}'
 
# Get suggestions
curl http://localhost:8000/api/v1/bi/sessions/sess-uuid-456/suggestions
 
# Get history
curl http://localhost:8000/api/v1/bi/sessions/sess-uuid-456/history?limit=20
 
# List sessions
curl "http://localhost:8000/api/v1/bi/sessions?tenant_id=acme-corp&user_id=user-123"
 
# Delete session
curl -X DELETE http://localhost:8000/api/v1/bi/sessions/sess-uuid-456?tenant_id=acme-corp