AI_SENTIMENT
Overview
AI_SENTIMENT is an AI sentiment analysis function provided by Singdata Lakehouse. It analyzes the sentiment of input text and returns one of four labels: positive, negative, neutral, or mixed. Supports Chinese, English, Japanese, and many other languages — one line of SQL is all it takes.
Singdata pushes AI computation down to the storage and execution engine layer. Data is processed intelligently within the platform without leaving the system, ensuring data security while significantly reducing task latency.
Syntax
Parameters
Required Parameters
model
Specifies the model for sentiment analysis. Supports two sources:
Source 1: API Gateway Endpoint (Recommended)
A platform administrator pre-configures model services in the API Gateway. Regular users reference them with the endpoint: prefix, without needing to know the underlying connection details.
Source 2: API Connection Object
Users create their own connection objects via CREATE API CONNECTION, suitable for custom service addresses, authentication keys, or private deployment models.
CREATE API CONNECTION field descriptions:
| Field | Description |
|---|---|
TYPE | Fixed as ai_function |
PROVIDER | Model provider identifier, e.g. 'bailian', 'openai', 'anthropic' |
BASE_URL | Base API URL of the model service |
API_KEY | Authentication key for calling the service |
text
The input text to analyze, type STRING. Supports Chinese, English, Japanese, French, German, Spanish, and many other languages — no need to specify the language manually; the model detects it automatically.
Return Value
STRING type, one of the following values:
| Value | Meaning |
|---|---|
positive | Text expresses a positive evaluation or optimistic sentiment |
negative | Text expresses a negative evaluation or pessimistic sentiment |
neutral | Text contains no clear sentiment (e.g. factual statements, notifications) |
mixed | Text contains both positive and negative sentiment |
Error Behavior
By default, if the function cannot process the input, it returns NULL without raising an error. In multi-row queries, rows that error return NULL without affecting other rows.
Usage Notes
- NULL and empty strings both return NULL: When
textisNULLor an empty string'', the function returnsNULLwithout error. Whitespace-only strings (e.g.' ') are sent to the model and typically returnneutral. - Results are non-deterministic: LLM-based sentiment analysis may vary slightly across model versions or call times; the same input may produce different results across executions.
- Note the difference between
mixedandneutral:mixedmeans the text contains both positive and negative evaluations (e.g. "food was great but service was terrible");neutralmeans the text has no emotional tone (e.g. "meeting at 3pm"). - Multilingual requires no extra configuration: The model automatically detects the input language; Chinese, English, Japanese, French, German, Spanish, and others all work directly.
Examples
Basic Usage
Multilingual
Semantic Understanding Capabilities
The model handles the following without extra configuration:
Batch Analysis on Table Data
Sentiment Distribution Statistics
Prioritize Negative Support Tickets
Limitations
modelparameter is required: Omitting it causes the errorAI function must have at least two arguments.- Invalid
modelformat causes an error:modelmust use'endpoint:<name>'or'<connection_name>:<model_name>'format; incorrect format causesInvalid model coordinates. - Input length is model-limited: Input text length is limited by the underlying model's context window; overly long text is automatically truncated without error.
- No dimension-level sentiment analysis: Only overall sentiment is returned; per-dimension analysis (e.g. "price", "service") is not supported.
