Skip to content

AI functions: resolve credentials from ai_function_credentials setting instead of param - #106881

Merged
george-larionov merged 16 commits into
masterfrom
ai-functions/making-credential-named-collection-setting-not-param
Jun 19, 2026
Merged

george-larionov merged 16 commits into
masterfrom
ai-functions/making-credential-named-collection-setting-not-param

Conversation

@george-larionov

@george-larionov george-larionov commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

Drop the leading named-collection argument from aiClassify, aiEmbed, aiGenerate, aiTranslate, and aiExtract. The collection is now named by the new ai_function_credentials setting; an empty setting raises an exception. Update the test and docs.

Changelog category (leave one):

  • Experimental Feature

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

Add new ai_function_credentials setting for setting AI function credentials, instead of per-function parameter.

Version info

  • Merged into: 26.6.1.1013

@george-larionov george-larionov changed the title AI functions: resolve credentials from ai_credentials setting AI functions: resolve credentials from ai_credentials setting instead of param Jun 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b22b16c]

Summary: ✅


AI Review

Summary

This PR moves AI function credential selection from a leading named-collection argument to the ai_function_credentials setting, and updates the direct function docs, stateless coverage, integration tests, fuzzer groups, and setting history. The direct execution path and earlier review threads are mostly addressed, but the new MATERIALIZED column guidance still describes the wrong settings context for background mutation recomputation.

Findings

⚠️ Majors

  • [docs/en/sql-reference/functions/ai-functions.md:101] The MATERIALIZED recomputation recipe says to set allow_experimental_ai_functions / ai_function_credentials in a settings profile and grant NAMED COLLECTION to the table owner, but background MergeTree mutation tasks rebuild their query context from the configured background context/profile via makeQueryContextForMutate, not from the ALTER query settings or a normal user/table-owner profile. Users following this recipe can still get an empty ai_function_credentials during ALTER TABLE ... MATERIALIZE COLUMN.
    Suggested fix: document that mutation recomputation needs these settings in the configured background profile (background_profile, or the background/system profile fallback), and keep the per-session/user access guidance separate for INSERT-time DEFAULT evaluation.
Tests

⚠️ The current tests cover direct calls, access checks, and DEFAULT evaluation, but they do not prove the documented background MATERIALIZED mutation workflow. A focused test or a corrected doc statement for the background-profile requirement would close this gap.

Final Verdict

Status: ⚠️ Request changes

Minimum required action: fix the MATERIALIZED column documentation so it names the background mutation profile/settings context instead of implying an ordinary user/table-owner profile is sufficient.

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Jun 9, 2026
Comment thread src/Functions/FunctionBaseAI.cpp Resolved
Comment thread src/Core/Settings.cpp Resolved
Comment thread src/Functions/aiExtract.cpp Resolved
Comment thread src/Functions/aiGenerate.cpp Resolved
@george-larionov
george-larionov force-pushed the ai-functions/making-credential-named-collection-setting-not-param branch from 3f72c49 to 4fc6760 Compare June 11, 2026 17:27
Comment thread src/Functions/aiGenerate.cpp Resolved
@george-larionov
george-larionov marked this pull request as ready for review June 11, 2026 18:11
Comment thread src/Functions/FunctionBaseAI.cpp Resolved
@george-larionov
george-larionov force-pushed the ai-functions/making-credential-named-collection-setting-not-param branch from d474d9c to 8c29f26 Compare June 11, 2026 22:03
@rschu1ze rschu1ze self-assigned this Jun 12, 2026
Comment thread src/Functions/FunctionBaseAI.cpp Resolved
@george-larionov
george-larionov force-pushed the ai-functions/making-credential-named-collection-setting-not-param branch 2 times, most recently from 96c9988 to 7fe7a16 Compare June 17, 2026 17:26
george-larionov and others added 11 commits June 18, 2026 15:31
Drop the leading named-collection argument from `aiClassify`, `aiEmbed`,
`aiGenerate`, `aiTranslate`, and `aiExtract`. The collection is now named
by the new `ai_credentials` setting; an empty setting raises an exception.
Update the test and docs.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…examples

Add the new `ai_credentials` setting to `SettingsChangesHistory.cpp` so
`02995_new_settings_history` passes. Rename the per-function doc example
collection to `my_ai_credentials` to match the Configuration section.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…umns

The collection is resolved live from `ai_credentials`, not captured in the
column definition. `DEFAULT` columns need the setting in the inserting
session; `MATERIALIZED` mutation-recompute needs it in a settings profile.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
After dropping the collection parameter, `instruction_or_schema` is the
second argument, not the third.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The test called the old two-argument forms, so with an empty
`ai_credentials` the queries failed as non-access errors and never
exercised the `NAMED_COLLECTION` access check. Set `ai_credentials` to
the collection and call the one-argument forms, including the zero-row
variants.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
After dropping the collection argument, the second positional argument
differs by function: `aiEmbed` takes a `UInt` dimensions and `aiClassify`
an `Array(String)`, while `aiGenerate`/`aiExtract`/`aiTranslate` take a
String. Since swapFuncs swaps the name only, group just the String-arg
functions and drop the incompatible ones.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The functions check `allow_experimental_ai_functions` before resolving
`ai_credentials`, so the examples failed with `SUPPORT_IS_DISABLED` on a
default server. Set the flag in both example forms and add a disclaimer
about experimental status near the top.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Drop the leading collection argument from every aiGenerate/aiClassify/
aiExtract/aiTranslate/aiEmbed call and pass the collection via the
`ai_credentials` query setting instead. All 33 tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
george-larionov and others added 4 commits June 18, 2026 15:31
`resolveAINamedCollection` ran per `executeImpl` (once per chunk) and
re-read the setting each time. Read it once in the constructor (like
`allow_experimental_ai_functions`), store it, and pass the collection
name into `resolveAINamedCollection`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…mples

Resolving ai_function_credentials runs a NAMED COLLECTION access check, so
the profile recipe alone is insufficient. State the settings + grant
requirements once up front.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@george-larionov
george-larionov force-pushed the ai-functions/making-credential-named-collection-setting-not-param branch from 5af1092 to 6e2f501 Compare June 18, 2026 15:31
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
Renamed to ai_function_credentials within the same unreleased cycle; the
old name never shipped.

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

clickhouse-gh Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.30% +0.10%
Functions 92.50% 92.60% +0.10%
Branches 77.50% 77.50% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 152/157 (96.82%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@george-larionov
george-larionov added this pull request to the merge queue Jun 19, 2026
Merged via the queue into master with commit 4182188 Jun 19, 2026
166 checks passed
@george-larionov
george-larionov deleted the ai-functions/making-credential-named-collection-setting-not-param branch June 19, 2026 01:48
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 19, 2026
@george-larionov george-larionov changed the title AI functions: resolve credentials from ai_credentials setting instead of param AI functions: resolve credentials from ai_function_credentials setting instead of param Jun 19, 2026
@alexey-milovidov alexey-milovidov added the post-rejected Should've been rejected, but got merged. label Jun 22, 2026
@alexey-milovidov alexey-milovidov self-assigned this Jun 22, 2026
alexey-milovidov added a commit that referenced this pull request Jun 23, 2026
The revert of #106881 removed the experimental-gate note from the AI
functions documentation, but the `allow_experimental_ai_functions`
setting predates #106881 and is still enforced by `FunctionBaseAI` and
`FunctionAiEmbed` (they throw `SUPPORT_IS_DISABLED` when it is not set).
Without the note, a user following the documentation hits the
experimental-gate exception before named-collection resolution.

Restore the note so the documented examples remain usable. This is
independent of the reverted `ai_function_credentials` design.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@groeneai groeneai mentioned this pull request Jul 1, 2026
1 task done
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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The revert of ClickHouse#106881 removed the experimental-gate note from the AI
functions documentation, but the `allow_experimental_ai_functions`
setting predates ClickHouse#106881 and is still enforced by `FunctionBaseAI` and
`FunctionAiEmbed` (they throw `SUPPORT_IS_DISABLED` when it is not set).
Without the note, a user following the documentation hits the
experimental-gate exception before named-collection resolution.

Restore the note so the documented examples remain usable. This is
independent of the reverted `ai_function_credentials` design.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

post-rejected Should've been rejected, but got merged. pr-experimental Experimental Feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants