Data Q&A best practices

Updated at:

Data Q&A workflow

The data Q&A workflow consists of three main steps: tabular data preparation, Q&A performance evaluation, and Q&A intervention.

  • Tabular data preparation: Standardize your business data tables to improve the model's understanding. This process includes preparing and importing data, and configuring table headers.

  • Q&A performance evaluation: Test and analyze the performance of the data Q&A feature. This includes preparing test cases based on business scenarios and analyzing the evaluation results.

  • Q&A intervention: Optimize results for poorly performing queries. Key methods include optimizing the table structure, adding synonyms, and using table selection intervention.

image.png

Tabular data guidelines

The names and data types defined for data table headers affect how the large language model (LLM) understands user queries. Therefore, the accuracy and completeness of these data definitions are critical. The following sections provide guidelines and examples for table structures, table headers, and cell values.

Table structure guidelines

  1. If your tables are sourced from a database instead of uploaded locally, we recommend isolating the tables used for data Q&A from other business operations. For example, if a table is used for both Business A and data Q&A, deleting data from that table for Business A could harm the data Q&A feature.

  2. Use a wide table where appropriate. A wide table can reduce the need for cross-table queries, but you should avoid excessive redundancy and consider data update requirements.

Note
  • Using a wide table reduces cross-table queries. For example, if Table A contains student grades and Table B contains student hobbies, you can combine them into a single wide table, Table C, to query both grades and hobbies.

  • Tables with too many columns are more difficult and costly to update and maintain.

  • Data Q&A supports tables with a maximum of 100 columns.

  1. When joining multiple tables, distinguish between a primary table and non-primary tables. A primary table typically contains factual, static data that rarely changes. Related attributes that change more frequently can be maintained in a separate, dynamic table, creating a one-to-many relationship (static-dynamic separation). Avoid many-to-many relationships.

Note
  • These joins use relationships defined between table headers. Except for the headers used for joining, all other header names across the joined tables must be unique. The primary table is the one that other tables reference.

  • You can join a maximum of three tables. A column in Table A cannot be a foreign key that references Table B while also being a primary key referenced by Table C. However, a column in Table A can be a primary key that is referenced by both Table B and Table C.

  1. Avoid data redundancy. Each row should represent a unique record without redundant business information that could confuse the model. For example, consider the data in the following table:

University

Major

Research area

Enrollment

Beijing University of Technology

Mathematics

Applied Mathematics

12

Beijing University of Technology

Mathematics

Basic Data

12

Beijing University of Technology

Physics

Applied Physics

11

Note

In this scenario, the table indicates that Beijing University of Technology enrolls a total of 12 students in the Mathematics major. These students can then choose either the Applied Mathematics or Basic Data research area. It does not mean that the university enrolls 12 students in the Applied Mathematics research area and another 12 in the Basic Data research area.

When a user asks, "How many students did Beijing University of Technology enroll?":

  • The bot might incorrectly answer: 35 (12 for Applied Mathematics + 12 for Basic Data + 11 for Applied Physics).

  • The correct number is: 23 (12 for Mathematics + 11 for Physics).

  • Solution: Split the "Research Area" and "Enrollment" columns into two separate tables, as shown below.

University

Major

Enrollment

Beijing University of Technology

Mathematics

12

Beijing University of Technology

Physics

11

University

Major

Research area

Beijing University of Technology

Mathematics

Applied Mathematics

Beijing University of Technology

Mathematics

Basic Data

Beijing University of Technology

Physics

Applied Physics

Table header guidelines

  1. Header name: Use clear nouns or short phrases (fewer than 10 words), such as "Material" or "Product Type". Avoid semantic overlap between header names within the same or across different tables. For example, if you have two headers named "Product Type" and "Category" that have a hierarchical relationship, the model may not know which header to use when a user asks about a "category".

  2. Header type: Choose a type that matches the column's data. Supported types include Text, Numeric, Boolean, Date, and Array.

  3. Header description: Optional. Use this field to explain the meaning of the header name. For example:

    1. For a Boolean value: true means "includes a lightbulb"; false means "does not include a lightbulb".

    2. For a numeric enumeration: 0 means "picked up"; 1 means "shipped"; 2 means "in transit"; 3 means "delivered".

  4. Unit: Optional. Specify a unit for numeric headers as needed.

Cell value guidelines

  1. A cell value must strictly match its header's data type. For example:

    1. If a cell can only contain a number or be empty, the header type should be Numeric.

    2. If a cell can contain one or more enumerated values, the header type should be Array.

  2. Format cell values consistently. For example:

    1. If the header name is "Color," its values should be colors (for example, "light blue"), not descriptions of colors (for example, "light blue like the sky").

    2. If the header name is "City," its values should be "Beijing" or "Shanghai", not "(11) Beijing".

  3. Keep cell values to a reasonable length. For example:

    1. If a header is used in filter conditions, keep its values short (fewer than 10 words) to ensure efficient retrieval.

    2. If a header is only used for returning query results and not for filtering, the value length can be up to 10,000 characters.

  4. If a cell value is used in numerical calculations, its header must be a numeric type, and the value must contain only numbers. For example:

    1. If the header is "Enrollment (excluding exemptions)" and its values must be used for calculations, split the column. For example, change "[(600) School of Engineering] [(02) 02 Financial Engineering Management] Research Area: 25 (excluding exemptions)" to "25".

Table standardization examples

Example 1

  • Original table:

Parameter

Synonyms

Type

Example values

Product Type

-

Text

Mattress (unique value)

Category

Kind

Text

Pocket spring|Spring|Foam|etc.

Material

Fabric, Substance

Text

Pocket spring|Natural materials|Spring|Foam|etc.

  • Issues:

    • The "Product Type" and "Category" columns are semantically ambiguous and can be easily confused.

    • The "Category" and "Material" columns have a large overlap in cell values and should be consolidated.

  • Optimized table:

Parameter

Synonyms

Type

Description

Product Type

-

Text

The category the product belongs to. Example: Mattress

Material

Fabric

Text

The core material of the product. Examples: Pocket spring|Natural materials|Spring|Foam

Example 2

  • Original table:

Parameter

Synonyms

Type

Example values

Number of seats

seating capacity, number of people, seats, number of seats

Text

2-seater|3-seater

Items included with sofa

-

Text

Seat cushion, back cushion, back and seat frame, armrest, assembly parts

  • Issues:

    • Number of seats: The data type is Text, which prevents numerical comparisons in queries.

    • Items included with sofa: This field contains multiple values but is not an array. The model may not recognize individual items. Convert the text to an array.

  • Optimized table:

Parameter

Synonyms

Type

Description

Number of seats

seating capacity, number of people, seats, number of seats

Numeric

Items included with sofa

-

Array (Text)

List of items included with the sofa. Example: ["Seat cushion","Back cushion","Back and seat frame","Armrest","Assembly parts"]

Example 3

  • Original table:

Parameter

Synonyms

Type

Example values

Product type

-

Text

Product category. Example: Lighting

Category

-

Text

Decorative lamps|LED strips|LED night lights|Ceiling lights|Table lamps|etc.

Light color

-

Text

Warm white|We recommend you use an LED GU10 bulb. The light color is warm white

Power source type

Power

Text

This product is battery-powered and requires 3 LR03 AAA 1.5V batteries, sold separately|USB power interface|Hardwired installation

  • Issues:

    • The "Product type" and "Category" columns have a hierarchical relationship ("Product type" is a level-1 category, and "Category" is a level-2 category). This ambiguity confuses the model.

    • The data in the "Light color" column is inconsistent. It contains both standard color names and descriptive text, which prevents it from being used as a filter condition. It should be standardized.

    • The "Power source type" column contains only descriptive text, making it unsuitable for filtering. Standardize these values.

  • Optimized table:

Parameter

Synonyms

Type

Description

Product type

-

Text

Example: Lighting

Light color

-

Text

Example values: Warm white|Milky white|Sunrise yellow

Power source type

Power

Text

Example values: Battery|USB|Hardwired

Q&A performance evaluation

Capabilities and limitations

Understand the capabilities and limitations of the data Q&A feature to design effective tests for your business scenarios.

Supported table structures

  • Flat structure: Each row represents a complete data record, and each column represents an attribute of that record.

  • Relational structure: Data is divided into multiple tables, where each table represents an entity or relationship. Tables are linked by a primary key and a foreign key, as shown in the following figure.

    Note

    Data Q&A supports queries that join up to three tables.

image.png

Supported Q&A capabilities

  • Single-column query: Queries data from a single column with high accuracy. For example: "Which department manages Peking University?"

  • Multi-column query: Queries data from multiple columns. For example: "What are the material and firmness of the XXXX mattress?"

  • Multiple conditions: Queries that contain multiple filter conditions. For example: "Recommend a black, non-adjustable chair."

The feature also provides analytical capabilities, such as:

  • Common aggregation queries: count, sum, max, min, and average.

  • Common analytical queries: period-over-period (PoP) comparison, year-on-year (YoY) comparison, percentage, ranking, and sorting.

  • Zhizi analysis capabilities: factor analysis, outlier detection, and top-N analysis.

The following table describes the specific capabilities.

Capability

Example user query

SELECT

Aggregation functions

Maximum/Minimum/Average/Sum

What is the maximum/minimum/average/total power generation of Company A in January 2022?

Count

How many companies are in each region?

Comparison

Compare the average power generation of companies in Beijing with the average power generation of companies in Shanghai in January 2022.

Period-over-period (PoP) comparison

  • What was the month-over-month power generation for Company B in March 2021?

  • What was the day-over-day change in average power generation for Company B in March 2021?

  • What was the quarter-over-quarter change in average power generation for Company B in Q1 2021?

Year-on-year (YoY) comparison

  • What was the year-on-year power generation for Company B in March 2021?

  • What was the year-on-year growth in average power generation for Company B in March 2021?

Trend

  • What was the monthly power generation trend for Company B in 2021?

  • What is the average power generation trend for Company B over the last 3 years?

Distribution

  • Show the daily power generation distribution for Company B in 2021.

  • Show the distribution of average power generation for all companies in 2021.

Multi-column query

-

  • List each region and its company names.

  • List the power generation for each company on January 1, 2022.

WHERE

Value comparison

Equal to, less than, greater than, greater than or equal to,

less than or equal to, not equal to, range, consecutive

  • Which companies had power generation greater than/less than/greater than or equal to/less than or equal to/equal to/not equal to 100 on January 1, 2022?

  • What was the total power generation for Company A between January 1 and January 2, 2022?

  • In mid-January 2022, for how many days was Company A's total power generation over two consecutive days greater than 100?

Multiple conditions

-

What was the total power generation for Company A between January 1 and January 2, 2022?

Nested conditions

-

Show the power generation details for companies that are located in Beijing and were built before 2000, or are located in Shanghai and were built before 2005.

Subquery

-

Which company in Beijing had higher power generation on January 1, 2022, than Company D's average generation in 2022?

GROUP BY

Single-column grouping

-

What was the average power generation for each company in Beijing in 2022?

Multi-column grouping

-

What was the maximum daily power generation for each company in each region in 2022?

HAVING

Single-condition filter

-

Which companies had an average power generation greater than 100 in 2022, and what were their average generation values?

Multi-condition filter

-

Which regions had an average power generation greater than 80 and a maximum generation greater than 50? What were their average generation values?

Subquery filter

-

Which companies had a higher average power generation in 2022 than Company A's average generation in 2022?

ORDER BY

Single-condition sort

-

Which two companies in Shanghai had the highest average power generation in January 2022?

Multi-condition sort

-

Of the two companies with the highest average power generation in Shanghai in January 2022, which one was built the earliest?

Unsupported table structures

  • Hierarchical structure: Each row represents a node with a hierarchical relationship to other nodes, and each node can have multiple child nodes. For example, geographical data for a country's provinces, cities, and districts is often stored in a hierarchical structure.

  • Star schema: Data is divided into a fact table and more than three dimension tables. The fact table contains measurement values, and the dimension tables contain dimensional information about those values.

Unsupported Q&A capabilities

  • Complex multi-column queries that are difficult to express in a single query statement. For example: "How many people won a prize in the Space Day live event, and who are they?"

  • Semantic retrieval of values in long text fields. For example, if a field value is "operator lacks experience," a user query like "What problems are caused by a lack of experience?" is not supported.

  • Semantic understanding that requires specific industry, professional, or business knowledge. For example, understanding concepts like "fiscal year" (which differs from a calendar year) or "average value" (where the exact calculation method requires business context).

Q&A performance analysis

Based on the capabilities and limitations described above, you can evaluate the performance of the data Q&A feature for your specific business scenarios.

  • Lightweight evaluation: You can perform tests directly in the test window. This is a convenient way to run simple performance tests on the bot. For more information, see Global test window.

  • Batch evaluation: To perform a batch evaluation, see Dialogue effect evaluation.

Q&A intervention

Q&A intervention optimizes the results of poorly performing queries. The main methods include optimizing the table structure, adding synonyms, and using table selection intervention.

  • Table structure optimization: Review and optimize your tables by following the guidelines in the "Tabular data guidelines" section. This improves the model's understanding of the tables and boosts Q&A performance.

  • Add synonyms: Configure synonyms for header names or cell values. This helps the bot map user queries that contain synonyms to the correct header or cell value. For more information, see Data Q&A intervention.

  • Table selection intervention: Force the bot to use a specific table to answer a user's query. For more information, see the retrieval intervention section in Configure bot.