Model inference

更新时间:
复制 MD 格式

When a model is in the READY state, you can use system functions to call the model for tasks such as inference, prediction, and generation.

Prerequisites

A model is created or imported and the status of the model is Ready. For more information, see Model creation and Model management.

Non-Time Series Tasks

Syntax

SELECT function_name(model_name, field1_name, field2_name, ..., params) [FROM table_name [WHERE clause]];

Parameters

  • function_name: the name of the system function. Set this parameter to ai_infer. ai_infer is the inference function

  • model_name: the name of the model. This parameter must be specified. The value of this parameter is of the VARCHAR type.

  • field_name: the fields that you must configure for the task. You can specify multiple fields at the same time. The following table describes the fields that you can configure for this parameter in different tasks.

    Task type

    Parameter

    Required

    Parameter type

    Description

    Feature extraction

    field1_name

    Yes

    VARCHAR

    The text constant for which to perform feature extraction (vectorization).

    Text-based image generation

    field1_name

    Yes

    VARCHAR

    The name of the text column in the table specified in the FROM clause, or a text constant.

    Semantic retrieval

    field1_name

    Yes

    VARCHAR

    The text constant that needs to be retrieved.

    Basic Q&A

    field1_name

    Yes

    VARCHAR

    The input question.

    Query-based Q&A

    field1_name

    Yes

    VARCHAR

    The input question.

  • params: the parameter that is used to adjust the inference task. This parameter is optional. The value of this parameter is in the following format: key1=value1, [key2=value2]. The following table describes the options that you can configure for this parameter.

    Task type

    Parameters

    Description

    Feature extraction

    normalize

    Specifies whether to normalize the returned vector. Valid values:

    • true: Yes. This is the Default value.

    • false: The vector is not normalized.

    Text-based image generation

    None

    None

    Semantic retrieval

    score

    Specifies whether to return semantic similarity. Valid values:

    • true: Indicates yes.

    • false: No

    topK

    The number of most semantically similar data records that are returned by the retrieval task. Valid values: [1, 10000]. Default value: 10.

    efSearch

    The length of the dynamic list. Valid values: [1, 1000]. Default value: 100. A larger value of efSearch indicates that the query is more precise. However, more resources are consumed and the query speed may be degraded.

    threshold

    The minimum semantic similarity of the returned data. Valid values: [0, 1.0]. Default value: 0.6.

    returnChunk

    Specifies whether to return document chunks instead of the original corpus. This parameter is valid only if the text_splitter parameter is set to on when the model is created. Valid values: `true` and `false`.

    • true: Yes.

    • false: No.

    extendChunk

    The number of preceding and succeeding chunks to return for context extension. This parameter is valid only if returnChunk is set to true and the text_splitter parameter is set to on when the model is created. The value must be in the range of [1, 100].

    rrfK

    The constant K for the Reciprocal Rank Fusion (RRF) algorithm used in hybrid retrieval. This parameter is valid only if hybrid retrieval is enabled when the model is created. The value must be in the range of [1, 100]. The default value is 60.

    verbose

    Specifies whether to return detailed information. Valid values:

    • true: Yes.

    • false: No.

    Basic Q&A

    None

    None

    Query-based Q&A

    topK

    The number of most semantically similar data records that are returned by the retrieval task. Valid values: [1, 10000]. Default value: 10.

    efSearch

    The length of the dynamic list. Valid values: [1, 1000]. Default value: 100. A larger value of efSearch indicates that the query is more precise. However, more resources are consumed and the query speed may be degraded.

    threshold

    The minimum semantic similarity of the returned data. Valid values: [0, 1.0]. Default value: 0.6.

    extendChunk

    The number of preceding and succeeding chunks to return for context extension when chunks are retrieved. This parameter is valid only if the text_splitter parameter is set to on when the model is created. The value must be in the range of [1, 100].

    verbose

    Specifies whether to return detailed information. Valid values:

    • true: Yes.

    • false: No.

Returned values

Task type

Returned value type

Description

Feature extraction

VARCHAR

The vector that corresponds to the text.

Text-based image generation

VARCHAR

The Lindorm S3-compatible protocol address of the image.

Semantic retrieval

VARCHAR

The list of semantically similar text in JSON format.

Basic Q&A

VARCHAR

The answer to the input question.

Query-based Q&A

VARCHAR

The answer to the input question.

Examples

You can execute the following statement to use the ai_infer function to perform model inference.

SELECT `design_desc`, ai_infer('interior_design', `design_desc`) as 'design_image' FROM design_desc;
Note

The returned values depends on the value of the TASK parameter that you specify when you create the model.

Time series tasks

Syntax

SELECT function_name(field_name, model_name, params) FROM table_name [WHERE clause] SAMPLE BY time_interval;

Parameters

function_name: the name of the system function. Valid values:

  • FORECAST: the function used for time series forecasting. For more information about how to configure the field_name, model_name, and params parameters of the FORECAST function, see Time series forecasting function.

  • ANOMALY_DETECT: the function used for time series anomaly detection. For more information about how to configure the field_name, model_name, and params parameters of the ANOMALY_DETECT function, see Time series anomaly detection function.

Returned values

Task type

Returned value type

Description

Time series forecasting

DOUBLE

The result of the time series forecasting task.

Time series anomaly detection

BOOLEAN

The time series anomaly detection results are as follows:

  • True: Anomalies are detected.

  • False: No anomalies are detected.

Examples

SELECT device_id, region, `time`, raw(temperature) as temperature, anomaly_detect(temperature, ad_model) as detect_result from sensor WHERE time >= '2022-01-01 00:00:00' and time < '2022-01-01 00:01:00' SAMPLE BY 0;