Configure question templates, terms, and business logic to expand the LLM's domain knowledge and improve the accuracy of generated data queries.
Overview
ChatBI uses a Large Language Model (LLM) to understand natural language questions and generate SQL queries. Although LLMs have strong general capabilities, they need additional domain knowledge for high accuracy in business-specific scenarios. The knowledge base provides this domain-specific knowledge through three types of objects: Question Template, Term Management, and Business Logic.
|
Object type |
Problem solved |
Typical use cases |
|
question template |
Provides fast, consistent responses for common analytical queries. |
High-frequency queries (such as "monthly sales ranking by store"), complex multi-table joins, and scenarios that require precise field mapping. |
|
Term Management |
Ensures the LLM accurately recognizes business-specific vocabulary. |
Abbreviations (such as "MoM" for month-over-month or "YoY" for year-over-year), multilingual terms, and synonym mapping. |
|
business logic |
Standardizes business rules and calculation methods. |
Business metric definitions (such as "a valid order has an order amount > 0 and a status of 'Paid'"), and data filtering rules. |
Access the feature
Only ChatBI administrators can view and edit the knowledge base. Members cannot access this feature.
-
Access the ChatBI portal.
Log in to Alibaba Cloud, then access the ChatBI intelligent data insights page in your browser. Select the access point that corresponds to the region of your DataWorks resources, such as your Serverless Resource Group and Datasets.
-
In the left-side navigation pane, click Knowledge Base.

Configure the knowledge base
The knowledge base contains three types of objects: Question Template, Term Management, and Business Logic.
Configure question templates
Go to the knowledge base page and click the Question Template tab, where you can add a new question template in two ways:
-
Add a template from the UI.
-
On the knowledge base page, click Add to open the Create Question Template page.
-
Configure the parameters for the question template:
Parameter
Description
Question
Define a common question used in a session. For example:
Monthly sales trend of Product B in Store A.The question can include variables in the
${parameter_name}format. If you define variables, you must provide enumerated or sample values in the Parameters field. For example:Monthly sales trend of ${commodityName} in ${shopName}.SQL
Provide an accurate and executable SQL query based on the question. If the question contains a
${parameter_name}, the SQL must also include a parameter with the same name. For example:SELECT shop_name, commodity_name, sales, month FROM ads_order_table WHERE shop_Name = ${shopName} AND commodity_Name = ${commodityName} ORDER BY month;Parameter
If you use variables like
${parameter_name}in the question or SQL, you must provide a list of possible or example values here. For example:${parameter_name}: ["value1","value2","value3"]Datasets
The datasets this template applies to. If empty, it applies globally.
-
After you complete the configuration, click Save.
-
-
Bulk import templates from a file.
-
On the knowledge base page, click Import and Add.
-
In the import dialog box, click Download Template. In the template file, fill in the Question Template, Template Script, Template Parameters, and Datasets columns. The parameters are the same as those used for UI configuration.
-
Drag and drop the local file, or click + in the dialog box to select the file to import.
-
After you add the file, click Confirm.
-
Recommendations
-
Prioritize high-frequency questions: Start by configuring templates for the top 20 most frequently asked questions.
-
Use parameters to improve reusability: Define variable parts of a question (such as store names, product names, or time ranges) as ${parameter_name}. This allows one template to cover multiple similar questions.
-
Validate your SQL: Before saving, run the SQL query on your dataset to ensure it is syntactically correct and returns the expected results.
Configure term management
Go to the knowledge base page and click the Term Management tab. You can add a term in one of two ways:
-
Add a term from the UI.
-
Click Add to open the Create Term page.
-
Configure the key parameters for the term:
Parameter
Description
Term
A common or specialized word used in business communication and analysis. For example: month-over-month.
Alias
Synonyms, abbreviations, full names, or translations of the term. Press Enter after each alias to add multiple aliases.
Datasets
Specifies the datasets this term applies to. If left empty, the term applies globally.
-
After you complete the configuration, click Save.
-
-
Bulk import terms from a file.
-
On the knowledge base page, click Import and Add.
-
In the import dialog box, click Download Template. In the template file, fill in the Term, Alias, Description, and Datasets columns. The parameters are the same as those used for UI configuration.
-
Drag and drop the local file, or click + in the dialog box to select the file to import.
-
After you add the file, click Confirm.
-
Recommendations
-
Prioritize business-specific terms: Focus on adding jargon, abbreviations, and internal codenames that the LLM is unlikely to know.
-
Build a comprehensive alias system: For a single term, configure multiple forms such as its English abbreviation, full name, and informal expressions. For example, aliases for "month-over-month" can include ["MoM", "Month over Month", "monthly growth rate"].
-
Avoid conflicts with common words: Do not configure terms for common words like "order" or "user" unless they have a special business meaning.
Configure business logic
Go to the knowledge base page and click the Business Logic tab. You can add business logic in one of two ways:
-
Add business logic from the UI.
-
Click Add to open the Create Business Logic page.
-
Configure the key parameters for the business logic:
Parameter
Description
Business Concept
The name of a common concept in business communication and analysis. For example: valid order.
Logic Explanation
A definition for the business concept. For example: ord_cnt_1d > 0 indicates a valid order.
Datasets
Specifies the datasets this business logic applies to. If left empty, the logic applies globally.
Field
Associate the business concept with specific table fields from the selected dataset.
-
After you complete the configuration, click Save.
-
-
Bulk import business logic from a file.
-
On the knowledge base page, click Import and Add.
-
In the import dialog box, click Download Template. In the template file, fill in the Business Concept, Logic Explanation, Associated table fields, and Datasets columns. The parameters are the same as those used for UI configuration.
-
Drag and drop the local file, or click + in the dialog box to select the file to import.
-
After you add the file, click Confirm.
-
Recommendations
-
Define key business metrics: Configure the calculation logic for core KPIs as business logic, such as "valid orders", "active users", and "conversion rate".
-
Be specific in the logic explanation: Explain not just what the concept is, but also how to calculate it. For example: "valid order = valid_order_flag = 1 and sales_amount > 0".
-
Associate physical fields: Select all relevant fields involved in the business logic to help the model understand the relationships between them.
Manage the knowledge base
ChatBI administrators can edit and delete the knowledge base objects they create.
Edit a knowledge base object
-
In the left-side navigation pane, click Knowledge Base to go to the knowledge base page.
-
On the tab for the desired object type, click Operation in the Edit column.
The parameters are the same as described in Configure the knowledge base.
Search for a knowledge base object
-
To find an object, go to the relevant tab, enter a keyword in the search box, and press Enter.
-
You can also click a knowledge base object to view its details.
Delete a knowledge base object
To remove an object, find it on the appropriate tab and click Operation in the Delete column.
Use case walkthrough
This e-commerce scenario compares ChatBI's performance with and without a knowledge base.
Scenario
An e-commerce company uses ChatBI to analyze sales data. The underlying table schema is as follows:
-
Table name:
ads_order_table -
Key fields:
shop_name(store name),product_name(product name),sales_amount(sales amount),order_date(order date), andvalid_order_flag(valid order flag, where 1 indicates a valid order)
Case 1: Value of question templates
User question
"What were the sales for iPhones in the East China Flagship Store last month?"
❌ Without knowledge base
ChatBI interpretation:
-
May fail to correctly map "East China Flagship Store" to the corresponding field value.
-
May interpret "iPhones" as a keyword match instead of an exact match.
-
May calculate the time range for "last month" incorrectly.
Generated SQL (potentially incorrect):
SELECT SUM(sales_amount)
FROM ads_order_table
WHERE shop_name LIKE '%East China%'
AND product_name LIKE '%iPhone%'
AND order_date >= '2026-02-01'
AND order_date < '2026-03-01';
Issues:
-
The
shop_name LIKE '%East China%'condition might match the wrong stores. -
The query does not filter for valid orders.
-
The time range may be inaccurate.
Result: ⚠️ Inaccurate data or query failure.
✅ With a question template
Knowledge base configuration:
|
Question |
What are the ${period} sales for ${productCategory} in ${region}${shopName}? |
|
SQL |
|
|
Parameters |
|
ChatBI workflow:
-
Matches the question to the configured question template.
-
Extracts parameters: shopName="East China Flagship Store", productCategory="iPhone", and period="last month".
-
Automatically calculates the time range for "last month": February 1, 2026 to March 1, 2026.
-
Generates a precise query using the template's SQL.
Generated SQL (correct):
SELECT SUM(sales_amount) as total_sales
FROM ads_order_table
WHERE shop_name = 'East China Flagship Store'
AND product_category = 'iPhone'
AND order_date >= '2026-02-01'
AND order_date < '2026-03-01'
AND valid_order_flag = 1;
Result: ✅ Precise match and accurate query.
Case 2: Value of term management
User question
"What was the MoM growth rate for the East China Flagship Store last month?"
❌ Without terms
ChatBI interpretation:
-
Cannot recognize the meaning of "MoM".
-
May interpret it as a field name or return an error.
Result: ⚠️ "Field 'MoM' not found" or query fails due to misunderstanding.
✅ With term management
Knowledge base configuration:
|
Term |
month-over-month |
|
Alias |
["MoM", "Month over Month", "monthly growth rate"] |
|
Description |
The percentage increase in data for the current month compared to the previous month. |
ChatBI workflow:
-
Recognizes that "MoM" is an alias for "month-over-month".
-
Understands that it needs to calculate: (Current Month - Previous Month) / Previous Month * 100%.
-
Generates a query that retrieves data from the last two months to perform the calculation.
Generated SQL (correct):
WITH monthly_sales AS (
SELECT
DATE_FORMAT(order_date, '%Y-%m') as month,
SUM(sales_amount) as sales
FROM ads_order_table
WHERE shop_name = 'East China Flagship Store'
AND valid_order_flag = 1
AND order_date >= '2026-01-01'
AND order_date < '2026-03-01'
GROUP BY DATE_FORMAT(order_date, '%Y-%m')
)
SELECT
(curr.sales - prev.sales) / prev.sales * 100 as mom_growth_rate
FROM monthly_sales curr
JOIN monthly_sales prev
ON prev.month = '2026-01'
AND curr.month = '2026-02';
Result: ✅ Correctly calculates the month-over-month growth rate.
Case 3: Value of business logic
User question
"Calculate the sales from valid orders for the East China Flagship Store last month."
❌ Without business logic
ChatBI interpretation:
-
Does not know the specific definition of a "valid order".
-
May omit the key filtering condition.
Generated SQL (incomplete):
SELECT SUM(sales_amount)
FROM ads_order_table
WHERE shop_name = 'East China Flagship Store'
AND order_date >= '2026-02-01'
AND order_date < '2026-03-01';
Issue: The query does not filter for valid orders.
Result: ⚠️ Data includes invalid orders, leading to an inflated result.
✅ With business logic
Knowledge base configuration:
|
Business concept |
valid order |
|
Logic |
A valid order is defined by valid_order_flag = 1 and sales_amount > 0. |
|
Associated fields |
ads_order_table.valid_order_flag, ads_order_table.sales_amount |
ChatBI workflow:
-
Recognizes "valid order" as a business concept.
-
Retrieves the business logic definition from the knowledge base.
-
Automatically adds the correct filtering conditions to the query.
Generated SQL (correct):
SELECT SUM(sales_amount) as valid_sales
FROM ads_order_table
WHERE shop_name = 'East China Flagship Store'
AND order_date >= '2026-02-01'
AND order_date < '2026-03-01'
AND valid_order_flag = 1
AND sales_amount > 0;
Result: ✅ Accurately calculates sales for valid orders.
Verifying the knowledge base
After configuring the knowledge base, verify that it works correctly:
-
Ask questions in a ChatBI session: Use the example questions from your configured question templates and check if the generated SQL meets your expectations.
-
Test term recognition: Use aliases of configured terms (such as "MoM") in your questions and observe whether ChatBI understands them correctly.
-
Verify business logic: Ask questions involving business concepts (such as "valid order") and check if the generated SQL includes the correct business logic filtering conditions.
-
Compare results: Record the change in question-answering accuracy before and after configuring the knowledge base to quantify the improvement.
FAQ
-
Q: What do I do if my knowledge base configuration does not take effect?
A: Please check the following:
-
Confirm that the knowledge base object is associated with the correct dataset or set to apply globally.
-
Check that the SQL syntax in the question template is correct and that the parameter names match.
-
Verify that the user's question is similar enough to the question template for a successful match.
-
Terms and business logic are only triggered when explicitly mentioned in the question.
-
-
Q: How does ChatBI handle conflicts between rules?
A: ChatBI applies rules in the following order of precedence:
-
Dataset-level configurations take precedence over global configurations.
-
Question templates have the highest priority and their SQL is used directly.
-
We recommend that you periodically review and merge duplicate or conflicting configurations.
-
-
Q: Will the knowledge base affect ChatBI's performance?
-
A: No. The knowledge base uses a retrieval and matching process with negligible impact on response speed (typically under 100 ms). A well-configured knowledge base often improves overall efficiency by reducing incorrect queries and manual corrections.