Conversational Text2SQL
Text2SQL supports multi-turn conversations where the AI remembers previous queries, results, and context. This enables natural follow-up questions and iterative data exploration.Basic Conversation
Use thechat() method instead of toSql() for conversational interactions:
Message Format
Messages follow the standard chat format:User Messages
Including Previous Messages
Streaming Responses
Thechat() method returns a streaming response:
Chunk Types
Context Persistence
Conversations are automatically saved to the context store:Chat IDs
Each conversation has a uniquechatId:
User IDs
Track conversations per user:Follow-Up Patterns
Text2SQL understands common follow-up patterns:Refinement (“but only X”)
Extension (“and also Y”)
Pivot (“what about Z instead”)
Reference Resolution (“it”, “those”, “them”)
Abort Signal
Cancel long-running queries:Conversation Management
Retrieve Conversation History
Clear Conversation
Branch Conversation
Create a new conversation branch:User Memory
Store user-specific preferences and context:Real-Time Collaboration
Multiple users can collaborate on the same conversation:Conversation Metadata
Attach metadata to conversations:Error Recovery in Conversations
The AI automatically retries failed queries:Best Practices
1. Use Consistent Chat IDs
2. Store User Context
3. Handle Streaming Errors
4. Implement Timeouts
5. Persist Important Conversations
Complete Example
conversation-app.ts
Next Steps
Explainability
Convert SQL to plain English explanations
Core API
Full Text2SQL API reference