Todos os produtos
Search
Central de documentação

Realtime Compute for Apache Flink:AI_SENTIMENT

Última atualização: Jul 24, 2026

AI_SENTIMENT classifica o sentimento de uma coluna de texto usando um Large Language Model (LLM) e retorna uma pontuação, um rótulo e um valor de confiança para cada linha.

Limitações

  • Requer Ververica Runtime (VVR) 11.4 ou posterior.

  • Para usar o Flink AI service (modelos integrados), é necessário ter o VVR 11.7 ou posterior e ativar o Flink AI service. Para obter mais detalhes, consulte Flink AI service (modelos integrados).

  • O throughput está limitado pelo rate limit da plataforma de modelos. Quando esse limite é excedido, o operador Flink sofre backpressure e se torna um gargalo. Em casos graves, isso gera erros de timeout no operador e provoca o reinício do job.

Sintaxe

AI_SENTIMENT(
  MODEL => MODEL <model_name>,
  INPUT => <input_column>
)

Parâmetros de entrada

Parâmetro

Tipo de dados

Descrição

MODEL <model_name>

MODEL

O service de modelo registrado a ser utilizado. Registre um service de modelo em Model Settings. O tipo de saída do modelo deve ser VARIANT.

<input_column>

STRING

Coluna de texto a ser analisada.

Saídas

AI_SENTIMENT retorna uma linha para cada linha de entrada com as seguintes colunas:

Coluna

Tipo de dados

Descrição

score

DOUBLE

Pontuação de sentimento variando de -1.0 a 1.0. Valores de referência: -1.0 extremamente negativo, -0.5 moderadamente negativo, 0.0 neutro, 0.5 moderadamente positivo, 1.0 extremamente positivo.

label

STRING

Classificação do sentimento. Valores válidos: positive, negative, neutral.

confidence

DOUBLE

Nível de confiança do modelo no rótulo previsto, entre 0.0 e 1.0.

Exemplo

O exemplo a seguir usa um modelo integrado do Flink e a função AI_SENTIMENT para classificar o sentimento de comentários sobre filmes.

Dados de teste

id

movie_name

comment

actual_label

1

Good Stuff

I loved the part where the child guessed sounds. It was one of the most romantic narratives I've seen in a movie. Very gentle and full of love.

positive

2

Dumpling Queen

Nothing remarkable.

negative

Instrução SQL

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

-- Create a view with the test data
CREATE TEMPORARY VIEW movie_comment(id, movie_name, user_comment, actual_label)
AS VALUES
  (1, 'Good Stuff',      'I loved the part where the child guessed sounds. It was one of the most romantic narratives I\'ve seen in a movie. Very gentle and full of love.', 'positive'),
  (2, 'Dumpling Queen',  'Nothing remarkable.', 'negative');

-- Call AI_SENTIMENT using positional arguments
SELECT id, movie_name, actual_label, score, label, confidence
FROM movie_comment,
LATERAL TABLE(
  AI_SENTIMENT(MODEL general_model, user_comment));

-- Call AI_SENTIMENT using named arguments
SELECT id, movie_name, actual_label, score, label, confidence
FROM movie_comment,
LATERAL TABLE(
  AI_SENTIMENT(
    MODEL => MODEL general_model,
    INPUT => user_comment));

Saída

O label previsto corresponde ao actual_label em ambas as linhas.

id

movie_name

actual_label

score

label

confidence

1

Good Stuff

positive

0.8

positive

0.95

2

Dumpling Queen

negative

-1.0

negative

0.95