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.
Image Input Example
Added in VERA Engine 4.6. The following example registers a model for image classification and calls it with an image fetched from S3, passed as a base64-encoded image_url.
1. Register the Model
SQL
1CREATE TEMPORARY MODEL ai_classify_image
2INPUT (input_contents STRING)
3OUTPUT (content STRING)
4WITH (
5 'provider' = 'openai',
6 'endpoint' = '<your-endpoint>',
7 'api-key' = '<your-api-key>',
8 'model' = 'gpt-4.1',
9 'content-type' = 'image_url'
10);2. Prepare Input Data
Use FETCH_CONTENT to retrieve the image bytes and TO_BASE64 to encode them, computing the column ML_PREDICT will read:
SQL
1CREATE TEMPORARY VIEW product_image(id, input_contents) AS
2SELECT id, TO_BASE64(FETCH_CONTENT(s3_uri))
3FROM (VALUES
4 (1, 's3://my-bucket/products/1.jpg'),
5 (2, 's3://my-bucket/products/2.jpg')
6) AS t(id, s3_uri);3. Run the Prediction
SQL
1SELECT id, content AS category
2FROM ML_PREDICT(TABLE product_image, MODEL ai_classify_image, DESCRIPTOR(input_contents));Was this helpful?