[FLINK-40572][runtime] Support dynamic AI model selection - #4525
Open
haruki-830 wants to merge 1 commit into
Open
[FLINK-40572][runtime] Support dynamic AI model selection#4525haruki-830 wants to merge 1 commit into
haruki-830 wants to merge 1 commit into
Conversation
haruki-830
marked this pull request as ready for review
September 8, 2026 02:16
yuxiqian
reviewed
Sep 9, 2026
yuxiqian
left a comment
Member
There was a problem hiding this comment.
Thanks Haruki for the cleaning-up work, just left some minor comments.
|
|
||
| /** Resolves AI model clients by their logical names during expression evaluation. */ | ||
| @Internal | ||
| public class AiModelClientResolver { |
Member
There was a problem hiding this comment.
Seems this resolver is just wrapping the Map internally. Can we keep it as-is for simplicity?
Comment on lines
+197
to
+202
| private static <T> T resolveModel( | ||
| AiModelClientResolver modelClientResolver, | ||
| String modelName, | ||
| String functionName, | ||
| Class<T> requiredCapability, | ||
| String capabilityName) { |
Member
There was a problem hiding this comment.
Stating the required interface explicitly could be useful:
Suggested change
| private static <T> T resolveModel( | |
| AiModelClientResolver modelClientResolver, | |
| String modelName, | |
| String functionName, | |
| Class<T> requiredCapability, | |
| String capabilityName) { | |
| private static <T> T resolveModel( | |
| AiModelClientResolver modelClientResolver, | |
| String modelName, | |
| String functionName, | |
| Class<T> requiredCapability) { |
and
throw new UnsupportedOperationException(
"Model '"
+ modelName
+ "' could not be used in "
+ functionName
+ " because it does not implement "
+ requiredCapability.getSimpleName()
+ " interface.");
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of this pull request?
This PR fixes FLINK-40572 and follows up on the remaining work discussed in #4520.
Previously, the model argument of an AI function had to be a string literal. The parser extracted the model name before execution, and
JaninoCompilerrewrote it to a pre-bound model client variable. As a result, expressions such as columns,IF, andCASEcould not be used to select an AI model dynamically.This PR evaluates the model argument for each record and resolves the selected model at runtime. It allows a pipeline to choose among the models declared in
pipeline.modelbased on record contents.Brief change log
AiModelClientResolverfor resolving declared model clients at runtime.STRINGexpression for every record.IF, andCASEexpressions.JaninoCompiler.Verifying this change
This change added and updated tests and can be verified as follows:
AiFunctionsTestto cover runtime model resolution, missing models, null model names, incompatible capabilities, and null-input short-circuiting.AiFunctionParserTestto cover dynamic model expressions and user-defined function precedence.FlinkPipelineAiFunctionITCaseto verify dynamic model selection in a running pipeline.flink2profile.mvn spotless:check.Documentation
Was generative AI tooling used to co-author this PR?
Generated-by: OpenAI Codex (GPT-5)