Skip to content

[FLINK-40416][runtime] Add built-in text AI functions - #4512

Merged
yuxiqian merged 2 commits into
apache:masterfrom
haruki-830:feature/text-ai-functions
Sep 1, 2026
Merged

[FLINK-40416][runtime] Add built-in text AI functions#4512
yuxiqian merged 2 commits into
apache:masterfrom
haruki-830:feature/text-ai-functions

Conversation

@haruki-830

Copy link
Copy Markdown
Contributor

What is the purpose of this pull request?

This PR implements FLINK-40416 by adding six built-in text AI functions to Pipeline transforms:

  • AI_CLASSIFY
  • AI_TRANSLATE
  • AI_SUMMARIZE
  • AI_SENTIMENT
  • AI_EXTRACT
  • AI_MASK

Brief change log

  • Add Calcite definitions and Janino/runtime dispatch for the six text AI functions.
  • Use English built-in prompt templates and return structured responses as VARIANT.
  • Define NULL semantics: NULL input or a NULL model response returns NULL.
  • Raise a function-specific error for a non-NULL invalid JSON response.
  • Validate model references and text-generation/embedding capabilities.
  • Preserve UDF-first behavior when a UDF has the same name as a built-in AI function.
  • Extend the Dummy model, E2E coverage, and English/Chinese documentation.

Verifying this change

This change added tests and was verified as follows:

  • Runtime parser, Janino, and function tests passed on both Flink 1.20 and Flink 2 profiles: 42 tests per profile.
  • Composer MiniCluster tests with the Dummy model passed on both profiles: 4 tests per profile.
  • Added regression coverage for same-name UDF precedence.
  • Updated AiFunctionE2eITCase; the Docker-based Pipeline E2E test was not run locally.
  • Spotless, Checkstyle, and diff checks passed.

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? English and Chinese docs

Was generative AI tooling used to co-author this PR?
  • Yes (OpenAI Codex)

Generated-by: OpenAI Codex

@github-actions github-actions Bot added docs Improvements or additions to documentation composer runtime e2e-tests add-ons labels Aug 21, 2026
@haruki-830
haruki-830 marked this pull request as ready for review August 24, 2026 09:31
@yuxiqian yuxiqian self-assigned this Aug 27, 2026
@yuxiqian

Copy link
Copy Markdown
Member

Looks good! One minor question: why do we need to modify JaninoParser after #4505? Shouldn't the UDF-precedence logic have been implemented there?

@haruki-830

Copy link
Copy Markdown
Contributor Author

The 2 PRs apply to different validation paths. #4505 makes Calcite validation follow the existing UDF-first Janino behavior, while this PR adds AI model reference and capability validation that runs earlier.
Without this check, a same-named UDF such as AI_SENTIMENT(id) would be treated as the built-in AI function and rejected before #4505’s resolution logic is reached. So I think it is necessary to keep this handling.

One minor question: why do we need to modify JaninoParser after #4505? Shouldn't the UDF-precedence logic have been implemented there?

@yuxiqian

yuxiqian commented Sep 1, 2026

Copy link
Copy Markdown
Member

Got it, thanks for the clarification!

@yuxiqian
yuxiqian merged commit f535d56 into apache:master Sep 1, 2026
38 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants