Configure and call AI models
Integrate built-in AI models into Flink data ingestion jobs for real-time intelligent processing, such as text summarization and vectorization.
Prerequisites
-
Realtime Compute engine: VVR 11.9 (including Preview versions) or later.
-
Additional dependency: Upload the flink-cdc-pipeline-model-openai-compatible JAR package as an additional dependency of the job.
How it works
Integrating AI inference models involves two steps:
-
Define models: Define models in the pipeline block of a YAML job draft. You can also directly reference models created in the metastore.
-
Use models: Call AI inference or vector generation models in the transform block of a YAML job draft.
Each model requires a unique name, which serves as the function name used to call the model in data transformations.
Configure and call Flink AI built-in models
Step 1: Prepare prerequisites
Before you begin, follow the instructions in Flink AI service (built-in models) to activate the Flink AI service.
In addition, you must upload the flink-cdc-pipeline-model-openai-compatible JAR package as an additional dependency of the job and attach it to the job draft.
Step 2: Define models in the pipeline block
To define AI models, add a list of model fields to the pipeline module of a YAML job draft. Each model must have a unique name that complies with general identifier rules: it must start with a letter and can contain only letters, underscores, and digits.
The following parameters are required:
-
The model identifier
name, which can be freely chosen but must be a valid identifier. -
The model type
type, which is fixed toopenai-compatible. -
The name of the model to call in Model Studio, specified by
model.
When you use the Flink AI service, the connection address and access credentials are built into the platform and provided dynamically. You do not need to specify endpoint or api-key in the job.
pipeline:
model:
- name: CHAT
type: openai-compatible
model: qwen-plus
user-prompt: Please summarize the input.
- name: GET_EMBEDDING
type: openai-compatible
model: text-embedding-v4
The following table lists all the parameters that you can specify.
|
Parameter |
Type |
Required |
Default value |
Description |
|
name |
STRING |
Yes |
N/A |
The alias of the model in the pipeline, referenced by AI functions. It must be unique and comply with identifier naming rules. |
|
type |
STRING |
Yes |
N/A |
The model type. Set this parameter to openai-compatible. |
|
model |
STRING |
Yes |
N/A |
The actual model name used by the Flink AI service for inference. For more information about available models, see Built-in models. |
|
endpoint |
STRING |
No |
N/A |
The base URL of the OpenAI-compatible API service. You do not need to specify this parameter when you use the Flink AI service. |
|
api-key |
STRING |
No |
N/A |
The API key used to authenticate requests to the OpenAI-compatible API service. You do not need to specify this parameter when you use the Flink AI service. |
|
task |
STRING |
No |
cdc-yaml-ai-task |
The task name of the model, used as the task group in monitoring metrics. |
|
error-handling-strategy |
STRING |
No |
retry |
The strategy for handling failed requests. Valid values: retry, failover, and ignore. |
|
retry-num |
INT |
No |
100 |
The maximum number of attempts for a single model call when error-handling-strategy is set to retry. |
|
retry-fallback-strategy |
STRING |
No |
failover |
The strategy after retries are exhausted. Valid values: failover and ignore. This parameter cannot be set to retry. |
|
retry-backoff-strategy |
STRING |
No |
fixed |
The retry backoff strategy. Valid values: fixed and exponential. |
|
retry-backoff-base-interval |
DURATION |
No |
1 s |
The base interval between retries, for example, 500 ms, 1 s, or 2 min. |
|
system-prompt |
STRING |
No |
N/A |
The system prompt added to the request. For regular text generation, it is placed before the system prompt of the AI function itself. |
|
user-prompt |
STRING |
No |
N/A |
A user prompt appended after the model input. |
|
temperature |
DOUBLE |
No |
Determined by the model service |
The sampling temperature. |
|
top-p |
DOUBLE |
No |
Determined by the model service |
The probability mass for nucleus sampling. |
|
stop |
STRING |
No |
N/A |
Stops generation when a specified string is encountered. |
|
max-tokens |
INT |
No |
Determined by the model service |
The maximum number of tokens that can be generated in a single request. |
|
presence-penalty |
DOUBLE |
No |
Determined by the model service |
The presence penalty, used to reduce the tendency of the model to repeat existing topics. |
|
n |
LONG |
No |
Determined by the model service |
The number of candidate results to generate. The current client returns only the first result. |
|
seed |
LONG |
No |
N/A |
The random seed, which can be used to improve the reproducibility of results when supported by the model service. |
|
response-format |
STRING |
No |
json_object |
The response format. Only json_object is supported. |
|
content-type |
STRING |
No |
text |
The input type of the model. Valid values: text and image_url. When set to image_url, the input string is sent as an image URL. |
|
extra-header |
STRING |
No |
N/A |
HTTP headers to attach to the request, declared as a JSON object. |
|
extra-body |
STRING |
No |
N/A |
Vendor-specific extension parameters to attach to the request body, declared as a JSON object. |
|
dimension |
INT |
No |
Determined by the model service |
The dimension of the vector returned by AI_EMBED. This parameter takes effect only when the model supports custom dimensions. |
Step 3: Call AI Function in the transform module
The following built-in AI functions can be called in the transform module, categorized by modality.
The first parameter of each built-in AI function is the model identifier that you defined in the pipeline block, which is the value of the name parameter in model.
Text generation functions
-
AI_COMPLETE
-
Purpose: A general-purpose text generation function that processes input text according to a given prompt. Suitable for content generation, text rewriting, and general question answering.
-
Usage example:
AI_COMPLETE('chat_model', content_string, 'Summarize the input content') -
Example output:
{"result":"Summary of the input content"}
-
-
AI_CLASSIFY
-
Purpose: Classifies input text into specified candidate categories. Separate multiple categories with commas.
-
Usage example:
AI_CLASSIFY('chat_model', content_string, 'news,sports,entertainment') -
Example output:
{"category":"sports","confidence":0.95}
-
-
AI_TRANSLATE
-
Purpose: Translates input text from a source language into a target language. When the source language is set to
auto, the model detects it automatically. -
Usage example:
AI_TRANSLATE('chat_model', content_string, 'auto', 'en') -
Example output:
{"translated_text":"Hello, world.","detected_language":"zh"}
-
-
AI_SUMMARIZE
-
Purpose: Generates a summary of input text. The third parameter specifies the maximum number of characters allowed in the summary.
-
Usage example:
AI_SUMMARIZE('chat_model', content_string, 200) -
Example output:
{"summary":"Summary of the input content"}
-
-
AI_SENTIMENT
-
Purpose: Analyzes the sentiment of input text. The value range of the sentiment score
scoreis-1.0to1.0. -
Usage example:
AI_SENTIMENT('chat_model', review_content) -
Example output:
{"score":0.8,"label":"positive","confidence":0.92}
-
-
AI_EXTRACT
-
Purpose: Extracts structured information from unstructured text according to a specified schema.
-
Usage example:
AI_EXTRACT('chat_model', content_string, '{"name":"string","age":"integer"}') -
Example output:
{"extracted_json":"{\"name\":\"John\",\"age\":25}"}
-
-
AI_MASK
-
Purpose: Identifies and masks sensitive information of specified types. Separate multiple entity types with commas.
-
Usage example:
AI_MASK('chat_model', content_string, 'name,phone,email') -
Example output:
{"masked_text":"Contact: Zhang*, phone: 138****8000","detected_entities":"name,phone"}
-
Text vectorization functions
-
AI_EMBED
-
Purpose: Converts input text into floating-point vectors. Suitable for semantic search, similarity computation, and text clustering.
-
Usage example:
AI_EMBED('embedding_model', content_string) -
Example output:
[0.0123, -0.0876, 0.2345, ...]
-
Multimodal generation functions
-
AI_IMAGE_COMPLETE
-
Purpose: Generates text from image binary data and a prompt. Suitable for image captioning, content recognition, and visual question answering.
-
Usage example:
AI_IMAGE_COMPLETE('vision_model', image_bytes, 'Describe the product in the image') -
Example output:
"The image shows a pair of white sneakers."
-
Multimodal vectorization functions
-
AI_IMAGE_EMBED
-
Purpose: Converts image binary data into floating-point vectors. Suitable for image-to-image search, image clustering, and multimodal retrieval.
-
Usage example:
AI_IMAGE_EMBED('image_embedding_model', image_bytes) -
Example output:
[0.0312, -0.1024, 0.2867, ...]
-
Complete configuration example
The following example reads articles and images from MySQL, calls the text summarization and vectorization functions, and writes the results to a DLF Paimon data lake.
By default, AI inference models are evaluated sequentially. Limited by network I/O rates, this may cause issues such as reduced throughput and slow checkpoints.
You can set the transform.async-execution.enabled parameter to enable asynchronous AI inference optimization, which is an experimental feature. For more information about the features and limitations of this parameter, see Pipeline parameters.
source:
type: mysql
using.built-in-catalog: mysql_catalog
tables: inventory.articles
sink:
type: paimon
using.built-in-catalog: dlf_catalog
transform:
- source-table: inventory.articles
projection: >-
id,
AI_SUMMARIZE('chat_model', content, 200) AS summary,
AI_EMBED('embedding_model', content) AS text_embedding,
AI_IMAGE_COMPLETE('chat_model', image_bytes, 'Describe the content of the image') AS image_description,
AI_IMAGE_EMBED('embedding_model', image_bytes) AS image_embedding
pipeline:
# Enable the experimental asynchronous AI inference optimization
transform.async-execution.enabled: true
parallelism: 4
model:
- name: chat_model
type: openai-compatible
model: qwen3.7-max
- name: embedding_model
type: openai-compatible
model: qwen3-vl-embedding
dimension: 1024
When you use the built-in models of the Flink AI service, you do not need to configure endpoint or api-key. When you connect to an external OpenAI-compatible API service, you must configure both parameters.
Reuse AI model definitions from Flink SQL
Currently, only AI models of the openai-compat and dashscope types defined in Flink SQL are supported.
Create an inference model
VVR 11.7 and later support creating persistent models in the metastore by using CREATE MODEL. When you use built-in models, you do not need to configure endpoint or api-key.
CREATE MODEL qwen_chat
USING openai_compatible
WITH (
'provider' = 'openai-compat',
'task' = 'chat/completions',
'model' = 'qwen3.7-max'
);
CREATE MODEL multimodal_embedding
USING openai_compatible
WITH (
'provider' = 'dashscope',
'task' = 'multimodal-embedding',
'model' = 'qwen3-vl-embedding',
'content-type' = 'image_url',
'dimension' = '512'
);
Reuse an existing model
After the model is created, you can reference the Flink SQL model by its full name in a YAML pipeline:
pipeline:
model:
- name: chat_model
reuse-model: vvp.default.qwen_chat
- name: image_embedding_model
reuse-model: vvp.default.multimodal_embedding