Business scoring

Updated at:

This topic describes how to use AI_SCORE to score input content against custom ordered levels by using a decision model.

Limitations

For model registration, execution requirements, and error handling, see Overview of decision functions.

Syntax

AI_SCORE(
    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 VARIANT type.

STATE

STRING or VARIANT

Yes

None

The content to be scored.

QUESTION

STRING

Yes

None

A non-NULL string constant that describes the scoring goal.

CRITERIA

ARRAY<STRING>

Yes

None

An array of descriptions ordered from the lowest level to the highest level. Each item corresponds to one level and must be a string constant.

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 the limits on the number of scoring levels, see Model Studio Decision Model API. In "Request parameters", see the questions part.

Return values

Returns DOUBLE. When N levels are defined, the level indexes range from 0 to N−1, and the score ranges from 0 to N−1.

A score can be a decimal. For example:

ARRAY['No impact on usage', 'Some features affected', 'Unable to continue using the product']

The corresponding level indexes are 0, 1, and 2, and the score ranges from 0 to 2.

When DETAILS => TRUE is set, the function returns VARIANT, which can contain details such as the score, the confidence level, and the probability of each level. 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 feedback(id, content) AS VALUES
    (1, 'All main features work normally, with occasional lag.'),
    (2, 'Some features are unavailable, but the product still works.'),
    (3, 'I cannot log in at all and can no longer use the product.');

SELECT
    id,
    AI_SCORE(
        MODEL => MODEL jev_model,
        STATE => content,
        QUESTION => 'How much does the issue affect the user?',
        CRITERIA => ARRAY[
            'No impact on usage',
            'Some features affected',
            'Unable to continue using the product'
        ]
    ) AS impact
FROM feedback;

Sample output

The following is only an example of the output format. The actual scoring results are subject to the response of the model.

id

impact

1

0.20

2

1.10

3

1.98

Retrieve detailed results

The following example uses the model and the view created in the preceding sections, and retrieves the full answer by setting DETAILS => TRUE.

CREATE TEMPORARY VIEW impact_results AS
SELECT
    id,
    AI_SCORE(
        MODEL => MODEL jev_model,
        STATE => content,
        QUESTION => 'How much does the issue affect the user?',
        CRITERIA => ARRAY[
            'No impact on usage',
            'Some features affected',
            'Unable to continue using the product'
        ],
        DETAILS => TRUE
    ) AS decision_result
FROM feedback;

SELECT
    id,
    decision_result
FROM impact_results;

References