Running an AI query with SQL DI web UI
After an AI object is enabled for AI query, you can run queries on the object on the AI objects page of the SQL Data Insights (SQL DI) user interface.
Before you begin
Make sure that you have the authorization that is required for a specific task in SQL DI. See Managing SQL DI user permissions and Configuring setup user ID for SQL DI for details.
Procedure
- Sign in your SQL DI web UI with a valid RACF® user ID at the following address:
https://<SQLDI-IPAddress>:<SQLDI-PortNumber>SQL DI uses a login group to identify and authorize users. The default group name is
SQLDIGRP. Make sure that the user ID that you specify is defined in your SQL DI login group. - On the
Connectionspage, select a connection and click theaction menu.
- Select
List AI objectsto open the AI objects page for the connection. - Click Run query to open the Run query page with the query editor.
- On the Run query page, select a query type from the options menu and then enter a query in the SQL editor.
- Optionally, select one of the following query types based on the insights you want your query to discover:
- Semantic similarity: A similarity query identifies groups of similar records or entities in records. Consider selecting semantic similarity if your query intends to identify the similarities of customer characteristics and behaviors in industries, such as commerce, finance, and insurance.
- Semantic dissimilarity: A dissimilarity query finds the outliers from the norm in records. Consider selecting semantic dissimilarity if your query intends to detect operational anomalies, fraudulent activities, and other patterns of deviation.
- Semantic clustering: A clustering query forms a cluster of entities in records and evaluates whether or not an additional entity belongs in the cluster. Consider selecting semantic clustering if your query intends to examine similarities or dissimilarities across multiple entities in a broader context.
- Semantic analogy: An analogy query determines if the relationship between two entities applies to that of a second pair of entities. Consider selecting semantic analogy if your query intends to discover your customers' preference for a specific product and the degree of their affinity for other products.
- Semantic commonality: A commonality query identifies the entities in records that exhibit the most common or uncommon patterns. Consider using semantic commonality if your query intends to detect the normal or aberrant characteristics and behaviors of your customers.
Note: Selecting a query type is optional, and not all available semantic query types, such as semantic commonality, are listed on the options menu. With or without a selected query type, SQL DI will process your query and invoke the AI function you specify. You can specify theAI_ANALOGY,AI_COMMONALITY,AI_SEMANTIC_CLUSTER, orAI_SIMILARITYfunction in your query. See Db2 built-in functions for SQL DI for details about the AI functions. - In the SQL editor, customize the sample query or enter a new one.
When you select a query type, SQL DI populates the corresponding tab of the SQL editor with a sample query. You can customize the sample query based on your need.
Alternatively, enter a new query as shown in the following example. This simple query specifies the AI_COMMONALITY function and intends to find the top 20 customers by their CUSTOMERID who exhibit the most common pattern of behaviors:
SELECT AI_COMMONALITY(CUSTOMERID) AS SCORE, C.* FROM DSNAIDB.CHURN C ORDER BY SCORE DESC FETCH FIRST 20 ROWS ONLY;If you want to find the top 10 customers by their CUSTOMERID who exhibit the most uncommon pattern of behaviors, enter the following query that also specifies the AI_COMMONALITY function:
SELECT AI_COMMONALITY(CUSTOMERID) AS SCORE, C.* FROM DSNAIDB.CHURN C ORDER BY SCORE ASC FETCH FIRST 10 ROWS ONLY;The most common pattern means that the scores of the top 20 customers converge toward the centroid value of the whole data set, and the most uncommon pattern indicates that the scores of the top 10 customers deviate the most from the centroid value.
SQL DI retains and caches the SQL statement on each tab of the editor. If needed, click Add SQL + to add a new tab or click X to remove a tab from the editor.
You can open up to 10 tabs of the query editor and enter a single query per tab. When the limit of 10 tabs is reached, you must close some existing tabs in order to open new ones. When you close a tab, the SQL statement on the tab and in the cache is deleted.
- Optionally, select one of the following query types based on the insights you want your query to discover:
- Click Run to run the query and review the results in the
Result setsection.- You can run the query on different tabs at the same time. A query run on each tab returns the results in the corresponding
Result setsection of the tab. Any subsequent run repopulates and refreshes the result set. If there is no matching record for a query, you will see an "Unable to retrieve query results" message in the section. In this case, verify that there are matching records for the specified query or update the SQL statement in the editor and run the query again. - By default, SQL DI fetches and displays 50 rows for a query result set on this page. If you want to see fewer than 50 rows, you can specify the
fetch * rowsoption in your SQL statement. You have the option to export the displayed rows into a CSV file. - SQL DI loads the remaining rows of a query result set in the backend. You have the option to download the remaining rows or the entire set of your query result. The default value for the maximum number of loaded rows is 1000. If you want more rows loaded, change the default value on the
Settingspage as described in Viewing or modifying your SQL DI server settings by using the web UI. - An AI query returns an SQL null value if it includes functions with arguments of null, filtered, or unseen values. Filtered values result from the application of the NULL values that you specify for all columns or a specific column. In the AI model, they are represented with the
DB2_GENERATED_EMPTYstring. Unseen values are those that are not present in the AI object when it's enabled for AI query. If your query includes arguments with null, filtered, or unseen values, SQL DI does not compute any result and thus returns an SQL null value. - For best query results from the AI_SEMANTIC_CLUSTER function, consider specifying constant or unchanging values for three clustering-arguments.
- You can run the query on different tabs at the same time. A query run on each tab returns the results in the corresponding