All Products
Search
Document Center

ApsaraDB for SelectDB:AI_CLASSIFY

Last Updated:Mar 28, 2026

Classifies text into one of the labels you specify, using a Large Language Model (LLM).

Syntax

AI_CLASSIFY([<resource_name>], <text>, <labels>)

Parameters

ParameterRequiredDescription
<resource_name>NoThe name of the AI resource. If omitted, the resource set by default_ai_resource is used.
<text>YesThe text to classify.
<labels>YesAn array of classification labels.

Return value

  • Returns a string containing the single label that best matches the text.

  • Returns NULL if any input value is NULL.

Results may vary between calls because the output is generated by an LLM.

Examples

Example 1: Use the default AI resource

Set the default resource, then call AI_CLASSIFY without specifying a resource name.

SET default_ai_resource = 'resource_name';
SELECT AI_CLASSIFY('SelectDB is a databases system.', ['useage', 'introduce']) AS Result;
+-----------+
| Result    |
+-----------+
| introduce |
+-----------+

Example 2: Specify the AI resource explicitly

Pass the resource name as the first argument to override the default.

SELECT AI_CLASSIFY('resource_name', 'SelectDB is developing rapidly.', ['science', 'sport']) AS Result;
+---------+
| Result  |
+---------+
| science |
+---------+