Text to SQL Feature
This article introduces how to use the Text to SQL feature in the MaiAgent system, helping you easily query database information using everyday conversation
What is Text to SQL?
Text to SQL (also known as Text2SQL) is an intelligent tool that automatically converts natural language questions (everyday human language) into SQL database query statements. Simply put, it enables the AI Assistant to "understand human language" and directly operate on databases.
Imagine you are a convenience store owner:
Traditional approach:
You: "Help me check how many bottles of cola were sold yesterday"
Employee: "Boss, you need to teach me how to use the POS system to query..."
You: "Click here, select there, enter conditions..."
Requires hands-on instruction, which is time-consuming.
With Text2SQL:
You: "Help me check how many bottles of cola were sold yesterday"
AI Employee: "Sure!" (automatically generates the query method and calls the database) → "87 bottles of cola were sold yesterday"
Core Features of Text to SQL
Natural language question → AI understanding & analysis → SQL query statement → Execute query → Return resultsWhen you ask the AI Assistant "Find the best-selling beverage from yesterday," the AI Assistant first analyzes your question, understands that you want to find a "beverage" that sold the "best" "yesterday," then generates SQL syntax to query the database, and finally tells you the result: "cola."
What Text to SQL Can Help AI Accomplish
Use Cases
Medical Clinic
School Management
Retail Chain Store
Advantages of Text to SQL
Efficiency Improvement
Traditional approach: Requires an SQL expert to write queries → 30 minutes
Text2SQL: Ask in natural language → 3 seconds
Lower Barrier
No need to learn complex SQL syntax
No need to memorize database structure
Anyone can query data
Real-Time Interaction
Ask and get answers immediately
Supports follow-up questions
Dynamically adjust query conditions
How to Use Text to SQL in MaiAgent
1. Access AI Assistant Settings
Select the AI Assistant you want to configure
Switch to the Response Mode settings page
2. Switch the AI Assistant's Response Mode to Agent Mode
Make sure to switch to Agent Mode, otherwise the AI Assistant cannot use the Text to SQL feature
For detailed information about each Response Mode, refer to: Create AI Assistant
3. Enter the Enterprise Database URL
Use the dropdown menu to select the database service used by your enterprise
Enter the database service URL used by your enterprise to allow the MaiAgent system to connect to the database


Make sure the URL format is correct and includes the necessary connection information, such as: hostname, port, database name, username, and password.
MaiAgent
Microsoft SQL Server(MSSSQL)
Connect to an existing MSSQL database by pasting the MSSQL database connection string
Note: Ensure the database URL is accessible by the MaiAgent service
MySQL
Connect to an existing MySQL database by pasting the MySQL database connection string
Note: Ensure the database URL is accessible by the MaiAgent service

Oracle
Connect to an existing Oracle database by pasting the Oracle database connection string
Note: Ensure the database URL is accessible by the MaiAgent service
PostgreSQL
Connect to an existing PostgreSQL database by pasting the PostgreSQL database connection string
Note: Ensure the database URL is accessible by the MaiAgent service

4. Click Save to Store the Settings

With this setup, the AI Assistant can help you quickly query your inventory, employee information, and more, and compile well-organized reports and trends for you.
Troubleshooting
Connection failed: Check the database URL format and network connectivity
Query error: Verify that table names and field names are correct
Insufficient permissions: Check database user permission settings
Slow response: Check query complexity and consider adding indexes
Text2SQL turns the AI Assistant into a database expert, allowing anyone to quickly obtain business insights using natural language, greatly improving the efficiency of data-driven decision making!
Last updated
Was this helpful?
