All Products
Search
Document Center

ApsaraDB for SelectDB:AI_SENTIMENT

Last Updated:Mar 28, 2026

Classifies the sentiment of a text string as positive, negative, neutral, or mixed.

Syntax

AI_SENTIMENT([<resource_name>], <text>)

Parameters

ParameterDescription
<resource_name>Optional. The name of the AI resource to use. If omitted, the session default set by SET default_ai_resource is used.
<text>The text string to analyze.

Return value

Returns one of the following strings:

ValueMeaning
positiveThe text expresses a favorable or approving sentiment.
negativeThe text expresses an unfavorable or critical sentiment.
neutralThe text expresses no strong positive or negative sentiment.
mixedThe text contains both positive and negative sentiment.

Returns NULL if any input value is NULL.

Results are generated by a Large Language Model (LLM) and may vary across runs.

Examples

Analyze a single string

Set a default resource and call the function without specifying one explicitly:

SET default_ai_resource = 'resource_name';
SELECT AI_SENTIMENT('SelectDB is a great DB system.') AS Result;
+----------+
| Result   |
+----------+
| positive |
+----------+

Specify a resource explicitly

Pass the resource name as the first argument to override the session default:

SELECT AI_SENTIMENT('resrouce_name', 'I hate sunny days.') AS Result;
+----------+
| Result   |
+----------+
| negative |
+----------+

Usage notes

  • If <resource_name> is omitted, set a session default with SET default_ai_resource = '<resource_name>' before calling the function.

  • Because the result is generated by an LLM, the same input may produce different outputs across runs. Do not rely on exact result reproducibility for production workflows that require deterministic output.