Classifies text into one of the labels you specify, using a Large Language Model (LLM).
Syntax
AI_CLASSIFY([<resource_name>], <text>, <labels>)Parameters
| Parameter | Required | Description |
|---|---|---|
<resource_name> | No | The name of the AI resource. If omitted, the resource set by default_ai_resource is used. |
<text> | Yes | The text to classify. |
<labels> | Yes | An 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 |
+---------+