For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

To learn more about Text2SQL, see: Technical Manual — Text to SQL

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 results

When 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

Before starting, you need to prepare: an enterprise relational database or Excel files (uploaded to the Knowledge Base)

If using a database, it is recommended that you:

  • Ensure the data table structure is clear

  • Create appropriate indexes

  • Maintain data quality

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

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

  • MaiAgent supports:

    • MySQL

    • PostgreSQL

    • Oracle DB

    • Microsoft SQL Server (MSSQL)

  • The maiagent option applies to Excel files you have already uploaded to the MaiAgent Knowledge Base

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?