Skip to main content

GBI configuration and testing suggestions

This topic describes how to configure and test GBI to help the model understand your business and improve the accuracy of generated SQL statements.

You can configure and test Xiyen in the following ways:
  1. Configure data table information. Descriptions for tables, columns, and values affect how the model selects tables and generates SQL for queries. This information helps the model better understand table content.
  2. Configure enterprise knowledge. After configuring data table information, optimize enterprise knowledge based on GBI test results. Enterprise knowledge includes term definitions, synonym definitions, business logic explanations, and optimization case management. Each type serves a different purpose. For more information, see Enterprise data management.
    • Term definitions: Explain proprietary terms in your business scenarios.
    • Synonym definitions: Explain common alternative names for fields stored in data tables.
    • Business logic explanations: Explain specific logic within your enterprise that is not common knowledge. For example, define calculation formulas or set conventions. Adding more business logic does not always improve performance.
    • Optimization case management: This feature is available only in Standard Edition MIX. If the model still fails to produce the expected results after you adjust your questions and data management settings, add optimization cases to guide the model's learning.
  3. Improve questioning techniques. We recommend asking questions of increasing difficulty to test the effectiveness of Xiyan's responses.

Configure data table information

In Data Table Management, open a connected database, select a data table, and configure its information.

Parameter name

Required

Description

Data table description

Required

A general explanation of the data table. Explain what the table is about, what information it contains, and what it can be used to query.

Common format: This is the xx table. It stores xx information and is used to query xx content.

For example: This is the customers table. It stores customer information and is used to query customer names, emails, and other content.

Column description

Required

Describes the key information of the field. Do not list enumerations or provide excessive explanations in the column description. Briefly describe the business semantics of the field. The description should be 10 characters or less.

For enumerated fields, configure the meaning of each value in the value mapping instead of the column description.

Foreign key

Required for cross-table queries

Foreign keys define dependencies between data tables. Configure foreign keys to join multiple tables.

Candidate values for enumeration type

Required for enumeration fields

Set Is Enumeration to Yes to indicate that the field is an enumeration type. You must then sync the candidate enumeration values.

Enumeration value management

Required for enumeration fields

If the enumeration column stores special codes instead of the actual values, configure the value mappings to explain the meaning of each code. In the figure below, "Enumeration Value" on the left is the value actually stored in the database. "Mapped Value" on the right is the meaning of that value. For example, for product types, 01 represents 'Appliances', 02 represents 'Furniture', and 03 represents 'Apparel'.

image.png

Data sample

Optional

A sample value for the field from the database. For columns that represent dates and times, configure data samples to help the model understand the date and time format.

Configure enterprise knowledge

Why configure enterprise knowledge

When the model does not understand a term or calculation logic in a query, configure the corresponding enterprise knowledge—such as business logic, term definitions, or optimization cases—to help the model understand your business, select the correct tables and fields, and improve the accuracy of generated SQL statements.

Test query

Reason for incorrect model response

Optimization measure

Which region has the highest sales today?

The model used the wrong time field. It selected the delivery time instead of the sales time.

Add a business logic rule: When calculating sales for a period, use the xxx field.

Monthly trend of sales and proportion for engine companies in xx City, xx Province in 2024

The model misinterprets the percentage as the share of engine enterprises in xx City out of all engine enterprises, rather than their share within xx Province. The SQL query calculates the percentage incorrectly.

Add a business logic explanation:

Sales proportion of engine companies in xx City, xx Province = (Sales of each engine company in xx City, xx Province / Sales of all engine companies) × 100%

Query the total account balance for merchant ID xxx

The model selected the wrong field, and the generated SQL was incorrect.

Although the column description defines the corresponding columns, there is still ambiguity between the descriptions for 'total balance' and 'total amount'. Add 'total balance = xxx' and 'total amount = xxx' to the synonym configuration.

For example, imagine you are visiting someone’s house for the first time and need to find something. You can find common items easily. You know that bowls are in the kitchen and clothes are in the closet. You can also find an item if it is clearly labeled. You do not need extra information to find these things. In the same way, the standard model can generate SQL directly for straightforward queries. For uncommon items or items with specific meanings, you need extra information. This is where you need to configure business logic.
  • Where are the clothes I wore for my birthday this year? Without extra information, the model does not know which clothes you mean. You need to provide more details: 'The clothes I wore for my birthday this year are a red coat with a black cat printed on it.' With this input, the model can quickly find the right item. For GBI, 'The clothes I wore for my birthday this year are a red coat with a black cat printed on it' is a business logic rule.
  • Where is Xiao Hei? Again, without extra information, the model does not know what 'Xiao Hei' is. You need to provide a definition: 'Xiao Hei is the little black cat we have at home.' This is a term definition.

Enterprise knowledge configuration principles

  1. Use clear and concise language. Avoid long blocks of text.
  2. Avoid complex reasoning or if-else conditions in business logic.
  3. Write business logic as mathematical formulas or SQL snippets when possible.
  4. Business logic rules must not conflict with each other. They also must not conflict with user queries, table information, or the case library.

Enterprise knowledge configuration instructions

Term definitions

On the Term Definitions page, click Add Term, enter the term name and description, and then click Save.
image
For example: Set Term Name to income, and set Term Description to Income refers to the amount field in the financial_report table, where the amount is a positive number, that is, financial_report.amount > 0.

Synonym definitions

On the Synonym Definitions page, click Add Word, enter the word and its synonyms, select the data table, and then click Confirm.
image
Synonyms mainly include the following types:
  • Synonyms for enumeration values. For example, if an enumeration value is "Hongqi", set Word to Hongqi and set Synonyms to FAW-Hongqi, Hongqi Company.
  • Synonyms for field names. For example, if a field in the data table is "brand", set Word to brand and set Synonyms to enterprise, company.

Business logic explanations

On the Business Logic Explanations page, click Add Logic Explanation, enter the business logic explanation and select the business logic type, and then click Save.
Adding more business logic explanations does not always improve performance. Configure them concisely. For Business Logic Type, select System Smart Judgment. If a business logic rule must be followed for most queries, set its type to Global.
image
Custom metrics, formulas, and other items configured in business logic explanations should be provided as mathematical formulas or SQL snippets. Custom metrics must be set to System Smart Judgment, and you must write the corresponding calculation formula.
  • Mathematical formula format: xx refers to xxx, is defined as xxx, and is calculated by the formula xxx, such as table.columnA / (table.columnB + table.columnC) . For example: Completion rate, with synonyms completion progress, completion status, and completion situation, is defined as: actual value / target value. If the denominator is 0, the completion rate is -999.
  • SQL snippet format: xx refers to xxx, is defined as xxx, and is calculated by xxx, such as SELECT AVG(column_name) AS average_value FROM table_name. For example: Completion rate, with synonyms completion progress, completion status, and completion situation, is calculated by: (CASE WHEN target_value = 0 THEN -999 ELSE actual_value / target_value END AS completion_rate).

Incorrect example

Suggested revision

The logic for the number of users in the customer table is to count(distinct userid) from the ods_xxx_table table.

Users in the customer table refer to the tablename.colname field. To find the number of player users, use count(distinct colname).

Conversion rate, also called lead conversion rate, is defined as: Total number of leads / Total number of firm orders.

Conversion rate, also called lead conversion rate, is defined as: Total number of leads / Total number of firm orders, which is COUNT(DISTINCT clew_identity_id) / SUM(CASE WHEN is_deposit = 1 OR is_deposit_new = 1 THEN 1 ELSE 0 END).

If the table has field a, must field a be included in the where clause during calculation?

When querying for xx, set field A of table xx to xxx.

Optimization case management

This feature is available only in Standard Edition MIX. On the Case Library Management tab of the Optimization Case Management page, click Add Question, enter the question description and the expected complete SQL statement, and then click Save.
image
For example: In Question Description, enter Shanghai car sales in April 2024. In Expected Complete SQL, enter SELECT SUM(total) AS sales_qutity FROM tb_vehicle_newcarn WHERE substr(date,1,5) = "2024-03" AND province = 'Shanghai'.

Questioning techniques

Common query formulas

when + who + where + what? This means querying a specific metric for a subject xx at a time xx with a condition xx. Queries are divided into five levels of difficulty. Ask questions starting from the easiest level: ⭐️All elements in the query directly correspond to specific fields stored in the table. For example: What were the sales for Product A on October 20, 2024? In this query, the time, product, and sales all have corresponding fields in the data table. ⭐️⭐️ The elements in the query correspond to specific fields in the table, but require basic calculations. For example: Calculate the total sales for each category in each quarter over the last two years. ⭐️⭐️⭐️The elements in the query involve enterprise business logic. For example: List the details of all shipped orders. Note: There is no direct field for shipped orders in the data table. Instead, the logistics status field expresses the order status. In this case, you need to configure a business logic rule: When querying order status, it refers to the logistics status of the order and uses the content of the order_status field. ⭐️⭐️⭐️⭐️For Standard Edition MIX, if the model still performs poorly after you optimize business logic or synonym configurations, configure the case library to help the model learn. Add a representative query and its corresponding expected SQL.
image.png
⭐️⭐️⭐️⭐️⭐️ For complex business logic scenarios that can converge, if the above methods do not meet your accuracy and timeliness expectations, use the customized TURBO edition to customize the model for your business.
The customized TURBO edition is only for custom project delivery, including paid proof of concept (POC) projects that use custom models. To purchase the customized TURBO edition, consult your business contact or submit a ticket to the GBI product R&D team before placing an order.

Common mistakes when asking questions

  1. The query is not described clearly

    Incorrect example

    Reason

    Suggested improvement

    Which car's sales increased?

    No time frame is specified, so sales growth cannot be compared.

    Which car's sales increased in August compared to July?

    Coupon usage in September

    Usage is not specified. Does it refer to the coupon usage rate, the amount spent with coupons, or the number of coupons used?

    Number of orders paid with coupons in September, or Amount spent with coupons in September?

  2. The query contains multiple questions Each question can contain only one SQL statement. Questions that require multiple SQL statements cannot be processed.

    Incorrect example

    Suggested improvement

    Transaction amount for each store in May and coupon usage for each outlet in September

    Ask these as two separate questions.

    What were the average sales and monthly sales in Guangdong Province last year?

    This cannot be answered with a single SQL statement. Ask these as two separate questions.

  3. The query contains business logic, calculation formulas, or other complex information

    Incorrect example

    Suggested improvement

    Sales proportion of each vehicle type (tractor, truck, dump truck, mixer truck) in xx City

    • Revise the query to: Sales proportion of each vehicle type in xx City

    • Add a business logic rule: When querying for vehicle types without specifying a particular type, 'vehicle type' refers to tractor, truck, dump truck, and mixer truck, which is `chexing in (1,2,3,4)` in the table field.

    Among this baby data, how many consume xx products, where xx products are goods_brand='xx' in cdp_order_detail_new and goods_brand='xx' in cdp_rolex_sku

    Move this part to a business logic rule: xx products are goods_brand='xx' in cdp_order_detail_new and goods_brand='xx' in cdp_rolex_sku.

  4. The query includes features that GBI does not currently support

    Unsupported feature

    Incorrect example

    Fault Cause

    Suggested improvement

    Non-query scenarios

    Count the number of active users by user role for August 2024 and export the results

    GBI supports downloading data results, but the export command in the query cannot be executed.

    Remove the export command from the query. Change it to: Count the number of active users by user role for August 2024

    BI analysis

    Does employee compensation have a linear relationship with product revenue? If so, explain the correlation and its impact.

    Analysis scenarios such as linear correlation are not currently supported.

    Analysis and prediction queries are not supported. Do not include such descriptions in your queries.

    Multi-turn conversations at the SQL level

    First turn: What were the sales for the Hangzhou outlet in August 2024?

    Second turn: Based on the previous query result, what were the sales in September?

    GBI multi-turn conversations are at the query level. It does not support secondary queries based on the results of the previous query.

    First turn: What were the sales for the Hangzhou outlet in August 2024?

    Second turn: What were the sales in September?

FAQ

  1. Dates and times
    • GBI has a default understanding of time. For dynamic time expressions such as 'today' or 'last year', GBI uses UTC+8 as the current time for calculations by default. This cannot be customized.
    • The dynamic time expressions supported by GBI and their corresponding calculation logic. Business logic configuration examples.xlsx
    • The calculation logic for dynamic time expressions cannot be customized. You cannot change the time inference by configuring business logic. For example, GBI's default for 'the last three days' or 'the past few days' includes today. If you do not want to include today, rephrase the query: 'the last three days, not including today'.
  2. Output display
    • Query results: GBI displays the actual column names and values found in the database by default. You cannot change this by configuring business logic. For example, the following business logic rule is not supported: Display Chinese names for result fields instead of the original English names.
    • Text response: The text response from GBI is a summary of the database query results. You cannot adjust it with business logic. For example, the following business logic rule is not supported: When a query starts with 'Hey', respond with the fixed text xxxx.