Probability assessment
This topic describes how to use AI_PROB to evaluate the probability that a given condition holds by using a decision model.
Limitations
-
Requires Ververica Runtime (VVR) 11.10.preview1 or later.
-
Before you use this function, activate the Flink AI service (built-in models).
For model registration, execution requirements, and error handling, see Overview of decision functions.
Syntax
AI_PROB(
MODEL => MODEL <model_name>,
STATE => <state>,
QUESTION => <question>
[, CRITERIA => <criteria>]
[, DETAILS => <details>]
[, CONFIG => <config>]
[, FAIL_ON_ERROR => <fail_on_error>]
)
Parameters
|
Parameter |
Data type |
Required |
Default value |
Description |
|
MODEL |
MODEL |
Yes |
None |
A registered decision model. The output column must be of the |
|
STATE |
STRING or VARIANT |
Yes |
None |
The content to be evaluated. |
|
QUESTION |
STRING |
Yes |
None |
A non- |
|
CRITERIA |
ARRAY<STRING> |
No |
None |
An array of two string constants that describe, in |
|
DETAILS |
BOOLEAN |
No |
FALSE |
Specifies whether to return the full answer. The value must be a Boolean literal. |
|
CONFIG |
MAP<STRING, STRING> |
No |
None |
Invocation-level configuration. The keys and values must be string constants. For more information about the configuration method, see General invocation. |
|
FAIL_ON_ERROR |
BOOLEAN |
No |
TRUE |
Specifies whether the job reports an error when a prediction ultimately fails. The value must be a Boolean literal. |
For example, in ARRAY['No customer service follow-up required', 'Customer service follow-up still required']:
-
The first element maps to
false, which indicates that no customer service follow-up is required. -
The second element maps to
true, which indicates that customer service follow-up is still required.
Return values
Returns DOUBLE, which indicates the probability that the condition holds. The value ranges from 0 to 1.
When DETAILS => TRUE is set, the function returns VARIANT, which contains details such as the probability that the condition holds. For the structure and field descriptions, see Model Studio Decision Model API. In "Response parameters", see the answers part.
For the return structure after FAIL_ON_ERROR => FALSE is set, see Error handling.
Returns NULL when STATE is NULL.
Examples
Test statements
CREATE TEMPORARY MODEL jev_model
INPUT (state STRING)
OUTPUT (answer VARIANT)
WITH (
'provider' = 'dashscope',
'task' = 'decision',
'model' = 'decision-model-preview'
);
CREATE TEMPORARY VIEW tickets(id, content) AS VALUES
(1, 'The product does not power on. I want to return it.'),
(2, 'The refund has arrived, but no one has picked up the return.'),
(3, 'The earlier issue is resolved. Thank you.');
SELECT
id,
AI_PROB(
MODEL => MODEL jev_model,
STATE => content,
QUESTION => 'Does the user still have a request that requires customer service?',
CRITERIA => ARRAY['No customer service follow-up required', 'Customer service follow-up still required']
) AS need_help
FROM tickets;
Sample output
The following is only an example of the output format. The actual probabilities are subject to the response of the model.
|
id |
need_help |
|
1 |
0.99 |
|
2 |
0.98 |
|
3 |
0.02 |
Filter by probability
In a WHERE clause, you can use AI_PROB directly. The following example uses the model and the view created in the preceding sections, and retains only the records whose probability of requiring follow-up is no less than 0.8.
SELECT id, content
FROM tickets
WHERE AI_PROB(
MODEL => MODEL jev_model,
STATE => content,
QUESTION => 'Does the user still have a request that requires customer service?'
) >= 0.8;