Skip to content

Make model a required positional argument for aiEmbed - #110619

Merged
alexey-milovidov merged 6 commits into
masterfrom
ai-functions/require-model-param-for-aiEmbed
Jul 19, 2026
Merged

alexey-milovidov merged 6 commits into
masterfrom
ai-functions/require-model-param-for-aiEmbed

Conversation

@george-larionov

@george-larionov george-larionov commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

aiEmbed now takes model as a required positional argument: aiEmbed(text, model[, params]). The model is read only from that argument — not from the parameter map, and not from the named collection (unlike the text functions, which still read model from the map or the collection).

Example:

-- Fails — model argument omitted:
SELECT aiEmbed('Hello world');
-- Received exception:
-- Code: 42. DB::Exception: An incorrect number of arguments was specified
-- for function 'aiEmbed'. (NUMBER_OF_ARGUMENTS_DOESNT_MATCH)

-- Works — model as the second positional argument:
SELECT aiEmbed('Hello world', 'text-embedding-3-small', map('credentials', 'ai_embedding_credentials'));

-- credentials can be omitted when the ai_function_embedding_default_credentials setting is set:
SELECT aiEmbed('Hello world', 'text-embedding-3-small');

Changelog category (leave one):

  • Experimental Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The aiEmbed function now takes model as a required positional argument (aiEmbed(text, model[, params])) instead of reading it from the named collection. This ensures reproducibility for embeddings.

`aiEmbed` now takes `model` only from the parameter map and no longer
reads it from the named collection. The resolver distinguishes the two
required-parameter cases so the error message points to the map.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2e3bf11]

Summary: ✅


AI Review

Summary

This PR moves aiEmbed to aiEmbed(text, model[, params]), stops reading model from the parameter map or named collection, and updates the docs/tests around that contract. The implementation is internally consistent, but it still breaks already-stored aiEmbed expressions and existing embedding named collections created under the old contract, so I would not merge it as-is.

Findings

⚠️ Majors

  • [src/Functions/aiEmbed.cpp:98-108, src/Functions/FunctionBaseAI.cpp:267-273] [dismissed by author -- https://github.com/Make model a required positional argument for aiEmbed #110619#discussion_r3590629512] Existing persisted objects created on earlier builds now start throwing after upgrade: DEFAULT / MATERIALIZED expressions such as aiEmbed(doc) or aiEmbed(doc, map(...)) fail the new positional-model validation, and any embedding named collection that still contains model is now rejected before execution. That is an upgrade-time compatibility break against previously valid metadata, not just a new-call-site API change. Suggested fix: keep the legacy one/two-argument forms and the collection/model fallback behind compatibility (or another explicit transition setting), or scope the new validation to newly created expressions / collections only.
Final Verdict

Status: ⚠️ Request changes

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Jul 15, 2026
@mintlify

mintlify Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Jul 15, 2026, 9:13 PM

Comment thread src/Functions/aiEmbed.cpp Resolved
model = 'gpt-4o-mini',
api_key = 'sk-...';

-- `aiEmbed` does not read `model` from the named collection; pass it in the parameter map instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could argue that the actually called model is identified by the model name and the endpoint (instead of just by the model name). But I suppose just using the model name is "safe enough".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is a tradeoff here in favor of ease-of-use

Comment thread src/Functions/aiEmbed.cpp Resolved
Comment thread src/Functions/aiEmbed.cpp Resolved
Comment thread src/Functions/aiEmbed.cpp Resolved
@rschu1ze rschu1ze self-assigned this Jul 16, 2026
@ayakovlev-clickhouse

ayakovlev-clickhouse commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Since function requires an explicit model, let's make it part of the function signature

SELECT aiEmbed('Hello world', 'text-embedding-3-small') 
 
-- or with credentials supplied in the map:
SELECT aiEmbed('Hello world', 'text-embedding-3-small', map('credentials', 'ai_embedding_credentials'));

This will minimize the need to use optional map.

@george-larionov
george-larionov marked this pull request as ready for review July 16, 2026 18:59
Change the aiEmbed signature to `aiEmbed(text, model[, params])`. `model`
is now a required constant String positional argument, read only there:
not from the parameter map, not from the named collection. This reverts
the map-only `model` requirement and its resolver change in
FunctionBaseAI.

Tested: stateless 03300/04142/04492 and integration test_ai_functions
(48 passed).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Functions/aiEmbed.cpp Resolved
Update the `ai_function_embedding_default_credentials` setting doc and the
AI functions doc: `aiEmbed` takes `model` as a required positional
argument, not from the named collection. Drop the stale "endpoint and
model differ" wording.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@george-larionov george-larionov changed the title Require model parameter in the map for aiEmbed Make model a required positional argument for aiEmbed Jul 17, 2026
Comment thread src/Functions/aiEmbed.cpp Resolved
george-larionov and others added 3 commits July 17, 2026 18:52
Previously an `aiEmbed` named collection that defined `model` was
silently ignored. `resolveAIParams` now throws when the collection
defines `model` but the function does not read it from the collection
(i.e. aiEmbed, which takes `model` as a positional argument).

Also drop the `isPlainString` wrapper in favor of a `static_cast` that
selects the `isString(const IDataType &)` overload directly.

Tested: stateless 03300/04142/04492 and integration test_ai_functions
(49 passed).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`model` in the parameter map was already rejected as an unknown key.
Give it a dedicated message pointing to the positional argument instead
of the generic "unknown parameter". Behavior (BAD_ARGUMENTS) unchanged;
covered by the existing 03300 case.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
aiEmbed changed to `aiEmbed(text, model[, params])`, so swapping its
name with aiGenerate (`aiGenerate(text[, params])`) produced
arity-mismatched calls that degenerate into
NUMBER_OF_ARGUMENTS_DOESNT_MATCH. Split them into separate single-member
swap groups; aiEmbed's arity matches no other AI function.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.10% 86.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 78.20% 78.10% -0.10%

Changed lines: Changed C/C++ lines covered: 63/63 (100.00%) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 19, 2026
Merged via the queue into master with commit e20ecd2 Jul 19, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the ai-functions/require-model-param-for-aiEmbed branch July 19, 2026 00:51
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 19, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 30, 2026
alexey-milovidov added a commit that referenced this pull request Jul 31, 2026
Resolve conflicts by adapting #110619 (make `model` a required positional
argument for `aiEmbed`) onto the 26.5 AI-function API, where the named
collection is the first positional argument and the parameter-map API of
#109232 does not exist. The 26.5 signature becomes
`aiEmbed(collection, text, model[, dimensions])`; a named collection that
defines `model` is rejected for `aiEmbed` rather than silently ignored.
The params-map-specific parts of the original change (Settings.cpp,
QueryFuzzer.cpp, FunctionBaseAI parameter-map handling) do not apply to
26.5 and are dropped; tests and docs are adapted accordingly.
tests/integration/test_ai_functions/test.py and
04492_ai_functions_default_credentials.sql do not exist in 26.5 and stay
deleted.
alexey-milovidov added a commit that referenced this pull request Jul 31, 2026
Resolve cherry-pick conflicts for backporting #110619 (make `model` a
required positional argument for `aiEmbed`) onto 26.6, where the AI
functions use the older architecture: a single `ai_function_credentials`
named collection and a positional `dimensions` argument instead of the
parameter map. The signature on 26.6 becomes `aiEmbed(text, model[, dimensions])`:
`model` is read only from the argument, and a named collection that
defines `model` is rejected for `aiEmbed` rather than silently ignored.
The default-credentials settings and the parameter map do not exist on
26.6, so those parts of the original change are dropped.
robot-ch-test-poll4 added a commit that referenced this pull request Jul 31, 2026
Cherry pick #110619 to 26.5: Make model a required positional argument for aiEmbed
robot-ch-test-poll4 added a commit that referenced this pull request Jul 31, 2026
Cherry pick #110619 to 26.6: Make model a required positional argument for aiEmbed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 31, 2026
george-larionov added a commit that referenced this pull request Jul 31, 2026
26.6 carries #106881 (credentials from `ai_function_credentials`), which master
reverted and re-landed as #109232, so that setting is replaced by the two
default-credentials settings. Keep 26.6's retry handling and converge `aiEmbed`
to `aiEmbed(text, model[, params])` so the #110619 backport is not undone.

Related: #112520 (comment)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@george-larionov george-larionov removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 1, 2026
@george-larionov

Copy link
Copy Markdown
Member Author

Recreating all the backports since they were stale (due to other backports landing between their creation and now).

george-larionov added a commit that referenced this pull request Aug 1, 2026
#110619's source changes are already on 26.5: they were pulled in when
#109232 was backported. The only net change is adding the
`test_ai_functions` integration test, which 26.5 lacked.
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 1, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…uire-model-param-for-aiEmbed

Make model a required positional argument for aiEmbed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-experimental Experimental Feature pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.4-must-backport v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants