AI_CLASSIFY

Updated at:

AI_CLASSIFY classifies text using a large language model (LLM).

Limitations

  • Requires Ververica Runtime (VVR) 11.4 or later.

  • To use the Flink AI service (built-in models), VVR 11.7 or later is required, and the Flink AI service must be activated. For details, see Flink AI service (built-in models).

  • The throughput of AI_CLASSIFY operators is subject to the rate limits of Alibaba Cloud Model Studio. When the rate limits for a model are reached, the Flink job is backpressured with AI_CLASSIFY operators as the bottleneck. In some cases, timeout errors and job restarts may be triggered.

Syntax

AI_CLASSIFY(
  MODEL => MODEL <model_name>,
  INPUT => <input_column>,
  LABELS => <labels>
)

Parameters

Parameter Type Description
MODEL <model_name> MODEL The name of the registered model service. For more information, see Model settings. Note: The output type of this model must be VARIANT.
<input_column> STRING The text column to classify.
<labels> ARRAY<STRING> The classification labels. Must be a constant.

Return values

Column Type Description
category STRING The label assigned by the model.
confidence DOUBLE The confidence level for the assigned label.

Examples

Test data

id content label
1 Li-Ning Way of Wade 10 Basketball Shoes, Performance Basketball Shoes, Shock Absorption and Rebound, Black/Red Digital
2 Apple iPhone 15 Pro Max 256GB, Space Black, 5G Phone, A17 Pro Chip, Titanium Frame Clothing

SQL statements

The following example references a Flink built-in model and uses AI_CLASSIFY to classify product categories.

CREATE TEMPORARY MODEL general_model
INPUT (`input` STRING)
OUTPUT (`content` VARIANT)
WITH (
    'provider' = 'openai-compat',
    'task'      = 'chat/completions',
    'model'     = 'qwen3.6-flash'
);

CREATE TEMPORARY VIEW products(id, content)
AS VALUES
  (1, 'Li-Ning Way of Wade 10 Basketball Shoes, Performance Basketball Shoes, Shock Absorption and Rebound, Black/Red'),
  (2, 'Apple iPhone 15 Pro Max 256GB, Space Black, 5G Phone, A17 Pro Chip, Titanium Frame');

-- Positional argument style
SELECT id, category, confidence
FROM products,
LATERAL TABLE(
  AI_CLASSIFY(MODEL general_model, content, ARRAY['Digital', 'Clothing']));

-- Named argument style
SELECT id, category, confidence
FROM products,
LATERAL TABLE(
  AI_CLASSIFY(
    MODEL  => MODEL general_model,
    INPUT  => content,
    LABELS => ARRAY['Digital', 'Clothing']));

Output

id category confidence
1 Clothing 0.95
2 Digital 0.99