ML_PREDICT
1 min read
On this page
This topic describes how to use the ML_PREDICT function for AI inference in your Flink jobs.
Limitations
- Supported in VERA Engine 4.1 or later.
- The throughput of
ML_PREDICToperators is subject to the rate limits of your model service provider. When rate limits are reached, the Flink job may experience backpressure at theML_PREDICToperators, which can lead to timeout errors or job restarts.
Syntax
SQL
1ML_PREDICT(TABLE table_name, MODEL model_name, DESCRIPTOR(input_column_names))Input Parameters
Example
The following example registers a sentiment analysis model and uses it to predict sentiment categories for movie reviews.
1. Register the Model
SQL
1CREATE TEMPORARY MODEL ai_analyze_sentiment
2INPUT (input STRING)
3OUTPUT (content STRING)
4WITH (
5 'provider' = 'openai',
6 'endpoint' = '<your-endpoint>',
7 'apiKey' = '<your-key>',
8 'model' = 'gpt-5.1',
9 'system-prompt' = 'Classify the text below into one of the following labels: [positive, negative, neutral, mixed]. Output only the label.'
10);2. Prepare Test Data
SQL
1CREATE TEMPORARY VIEW movie_comment(id, movie_name, user_comment, actual_label)
2AS VALUES
3 (1, 'Silent Echo', 'A haunting story that kept me guessing until the end.', 'positive'),
4 (2, 'The Velvet Gate', 'Nothing special.', 'negative');3. Run the Prediction
SQL
1SELECT id, movie_name, content as predict_label, actual_label
2FROM ML_PREDICT(TABLE movie_comment, MODEL ai_analyze_sentiment, DESCRIPTOR(user_comment));Output Results
The prediction results in the predict_label column match the actual results in the actual_label column.
Was this helpful?