Using MaiAgent Knowledge Base for Text to SQL
If you want your AI assistant to help analyze data in Excel or spreadsheet format, you can follow these steps to enable the AI assistant to generate statistical analysis results.
Step 1: Switch AI Assistant to Agent Mode
Agent mode grants the AI assistant the ability to use tools. In this mode, the AI assistant can understand the structure of spreadsheet data and use the Text-to-SQL tool for analysis.
Select MaiAgent in Agent mode. After switching, no changes are needed to the URL field below.


You must select the maiagent service and save the result, otherwise the text to SQL tool cannot be enabled
Step 2: Upload Spreadsheet Files like CSV
1. Enter the knowledge base page and click edit operation

2. Upload files (.xls, .xlsx, .csv)
You can download the sample file (100 items of food sales file.xlsx) for testing to experience the AI assistant's data analysis capabilities.
Number of spreadsheet columns and Reranker retrieval segment count are two completely independent configuration parameters that have no dependency or mutual influence on each other.
For Reranker introduction, please refer to: Technical Manual - Reranker Model


When the file appears in the knowledge base and the processing status shows "Completed" (as shown in the right image above), the system will automatically create a database, and the AI assistant can read your file to help you generate calculation and statistical results using SQL syntax.
📍Note: Text-to-SQL Q&A functionality cannot be used without uploaded data

Table Format Notes
Step 3: Converse with AI Assistant
After completing the above steps, you can enter the AI assistant conversation page and directly tell the AI assistant your needs in natural language, just like discussing with another person.
Data Analysis
The Text to SQL tool can help you analyze data in spreadsheets, for example: "Help me find the best-selling dairy products from last year"

When you make a request, the AI assistant will automatically invoke the Text-to-SQL tool.
This tool acts like a translator, converting what you say into SQL syntax that computers understand, allowing the AI assistant to extract data from the database.
The AI assistant will automatically add conditional judgments, sorting criteria, and other query restrictions to convert your needs into more complete query instructions.
AI Assistant's Thinking Query: Find the best-selling dairy products from last year, sorted in descending order by sales quantity. Automatically adds descending order conditions to make results better match your needs.
AI Assistant's Response (click on tool response to view):


Result
The AI assistant found all sales data for "dairy products" and other field data for those items.
Each row represents one data record, including: Product ID, Product Name, Product Category, Sales Amount, Sales Quantity......
Based on this data, the AI assistant determined that the best-selling dairy product is "cheese," with a sales quantity of 110 and sales amount of 40,150 yuan.
Report Creation (Canvas Mode)
The Text to SQL tool can also help you create beautiful reports. This feature requires enabling Canvas mode:
Go to "AI Assistant Settings Page > Response Mode Settings" and find Agent Mode


Change Agent mode from normal mode to Canvas Mode

After saving the settings, you can converse with the AI assistant, for example: "Please help me generate a visualized revenue report after statistics"

AI Assistant's Thinking Query: Calculate revenue statistics for each product in the food company, including total revenue, average revenue, revenue standard deviation, revenue distribution ranges, revenue proportion by category, and other statistical indicators. Automatically generates calculation results needed for reports to better match your needs.
AI Assistant's Response (click on tool response to view):
[('分類營收占比-主食', '10.72%'), ('分類營收占比-乳製品', '11.97%'), ('分類營收占比-冷凍', '9.06%'), ('分類營收占比-罐頭', '10.25%'), ('分類營收占比-肉類', '13.23%'), ('分類營收占比-蔬果', '13.34%'), ('分類營收占比-調料', '4.51%'), ('分類營收占比-零食', '14.53%'), ('分類營收占比-飲料', '12.40%'), ('商品總數', '100'), ('平均營收', '19546.06'), ('最低營收', '1400'), ('最高營收', '63364'), ('營收標準差', '15736.83'), ('總營收', '1954606')]Result
The AI assistant obtains all automatically calculated statistical item results from the tool and returns them.
The AI assistant uses this data as the basis for visualization and creates an interactive report screen using Canvas.
Click on the "Use Canvas" box to view the screen content

The report display screen is shown below. You can:
Switch between viewing original code or screen
Switch report content according to the statistical category you want to view (this varies depending on each AI assistant's output)

When switching to other categories, you can view the category revenue proportion pie chart and distribution analysis bar chart:


Conclusion
Using the MaiAgent Text to SQL tool, you can quickly enable the AI assistant to help you analyze spreadsheet content and generate beautiful reports. Start experiencing now and let the AI assistant become your data analysis helper!
Last updated
Was this helpful?
