Repository navigation
AI functions parameter map - #109232
AI functions parameter map#109232
Conversation
c8f24f3 to
e9f1c4c
Compare
|
Workflow [PR], commit [995571d] Summary: ✅
AI ReviewSummaryThis PR rewires the AI functions around a trailing Findings
Tests
Final Verdict
|
| addSettingsChanges(settings_changes_history, "26.7", | ||
| { | ||
| {"s3_validate_etag_on_read", false, true, "New setting to detect concurrent in-place overwrites of S3/GCS objects during a read by validating the GET response ETag against the listed one. previous_value=false so `compatibility` with versions before 26.7 restores the pre-existing behavior (no validation)."}, | ||
| {"ai_function_text_default_credentials", "", "", "New setting: default named collection for the text AI functions (aiGenerate, aiClassify, aiExtract, aiTranslate) when the call omits credentials."}, |
There was a problem hiding this comment.
Just "New setting" will do the trick ;-)
There was a problem hiding this comment.
Why? All the others have some description
There was a problem hiding this comment.
SettingsChangesHistory.cpp is only used by compatibility, so the reason field is most useful when it explains a behavior flip or why previous_value differs from the normal docs default. For a brand-new setting with previous_value == new_value == "", the full semantics already live in Settings.cpp, so repeating the whole setting description here mostly duplicates the reference docs. That was the reasoning behind the suggestion to keep it at New setting.
There was a problem hiding this comment.
Ok, I see I am outnumbered 😅
| std::string_view name; | ||
| AIParamKind kind; | ||
| /// `std::nullopt` => required: the resolver throws if the key is absent everywhere. | ||
| std::optional<Field> default_value; |
There was a problem hiding this comment.
Ah, I asked elsewhere why std::nullopt is passed instead of an empty string. I think I now know why.
There was a problem hiding this comment.
Yes, also trying to future proof the code so that it is possible later to distinguish an absent value from an empty value. The empty value (empty string) could be passed on to the endpoint which can then decide the value (f.e. the model) to use based on various info like the calling function.
1a52d61 to
8ead71a
Compare
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
… migration The `/docs` tree is mid-migration from Docusaurus to Mintlify. Per `docs/AGENTS.md`, contributors should edit only the legacy `/docs/en` files (which build the current Docusaurus site); the Mintlify files are not to be edited yet. The AI review bot (`ci/jobs/copilot_review_job.py`) follows `.claude/skills/review/SKILL.md`, so without this note it asks contributors to also update the served `.mdx` reference pages, which is against the migration policy. Add the `docs/AGENTS.md` guidance verbatim to the skill's documentation review section, plus an explicit instruction not to flag a PR for editing only `/docs/en` and not the Mintlify files. Related: ClickHouse#109232 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Move the named collection out of the positional arguments. Credentials now come from a `credentials` key in an optional trailing `Map(String, String)` argument, or from `ai_function_text_default_credentials` (chat functions) / `ai_function_embedding_default_credentials` (aiEmbed) when the map omits it. The map also carries tunables (`model`, `max_tokens`, `temperature`, `system_prompt`, `instructions`, `dimensions`); each function declares its params, defaults, and required-ness via a small spec resolved centrally. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Reject duplicate keys in the parameter map instead of silently keeping the last value, matching the unknown-key rejection. - AIParams::getString/getFloat/getUInt throw a DB::Exception on a missing key rather than std::map::at's std::out_of_range. - Drop the unnecessary ColumnMap.h include. - Tests: negative / out-of-range max_tokens and duplicate map key. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Parse UInt map values (max_tokens, dimensions) with overflow checking so a value above UInt64 max is rejected instead of silently wrapping (e.g. "18446744073709551616" -> 0). Add a test for the wrap boundary. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Expand each function's `params` documentation with per-key meaning and defaults. - Clarify the `AIParamKind` and parameter-parsing comments. - Parse parameters via exhaustive `switch` over `AIParamKind` so a new kind is a compile error rather than a silent fallthrough; guard `getResolvedAIParam` with `chassert`. - Add a test rejecting a parameter map passed in the prompt position. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Style check: give the small AI-parameter `std::vector`/`std::map` config containers `STYLE_CHECK_ALLOW_STD_CONTAINERS`-marked aliases instead of raw std containers. - clang-tidy (cppcoreguidelines-init-variables): initialize `value` in the UInt parameter parser. - Fast test: update 04142_ai_functions_named_collection_access to the new signature (credentials via the parameter map); reference unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 317/332 (95.48%) · Uncovered code |
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.
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]>
Cherry pick #109232 to 26.5: AI functions parameter map
Cherry pick #109232 to 26.6: AI functions parameter map
26.6 gained #107927 (retriable provider error classification) after this branch was cut, so keep its retry code and layer the parameter map on top instead of reverting it. Drop `resolveConfig`/`resolveTemperature`, superseded by `resolveAIParams`, and take the integration tests from master so the new retry tests use the parameter map and `aiEmbed`'s positional model. Related: #112710 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Backport #109232 to 26.5: AI functions parameter map
Backport #109232 to 26.6: AI functions parameter map
… migration The `/docs` tree is mid-migration from Docusaurus to Mintlify. Per `docs/AGENTS.md`, contributors should edit only the legacy `/docs/en` files (which build the current Docusaurus site); the Mintlify files are not to be edited yet. The AI review bot (`ci/jobs/copilot_review_job.py`) follows `.claude/skills/review/SKILL.md`, so without this note it asks contributors to also update the served `.mdx` reference pages, which is against the migration policy. Add the `docs/AGENTS.md` guidance verbatim to the skill's documentation review section, plus an explicit instruction not to flag a PR for editing only `/docs/en` and not the Mintlify files. Related: ClickHouse#109232 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ault-credentials-params-map AI functions parameter map
Description
Reworks how the experimental AI functions (
aiGenerate,aiEmbed,aiClassify,aiExtract,aiTranslate) receive credentials and tunables.Previously the named collection was a mandatory first positional argument, and each tunable (
system_prompt,temperature,dimensions, translateinstructions) was a separate positional argument. This made a casual call verbose and forced every query to name the collection.Now:
The per-row text is the first argument; the named collection is no longer positional.
Credentials are resolved from a
credentialskey in an optional trailingMap(String, String)argument, or — when the map omits it — from a default-credentials setting:ai_function_text_default_credentialsfor the text functions (aiGenerate/aiClassify/aiExtract/aiTranslate),ai_function_embedding_default_credentialsforaiEmbed.The split exists because a chat-completions endpoint/model differs from an embeddings one, and the named collection's
endpointis used verbatim.The same map carries the tunables:
model(overrides the collection),max_tokens,temperature,system_prompt(aiGenerate),instructions(aiTranslate),dimensions(aiEmbed). Map values are strings; unknown keys and duplicate keys are rejected; integer values are overflow-checked and capped atInt64max.Internally, each function declares its parameters (name, kind, default-or-required, whether it inherits from the named collection) via a small spec, and a single resolver in
FunctionBaseAIdoes the parsing, validation and defaulting.Note: an explicitly empty value is now honored (
map('system_prompt', '')sends an empty system prompt); the default applies only when the key is absent.This is a breaking change to the AI function signatures, but they are experimental (guarded by
allow_experimental_ai_functions) and were introduced only in 26.4/26.6.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
AI functions no longer take the named collection as the first positional argument. Credentials come from the
ai_function_text_default_credentials/ai_function_embedding_default_credentialssettings or from acredentialskey in an optional trailingMap(String, String)argument, which also carries tunables (model,max_tokens,temperature,system_prompt,instructions,dimensions).Documentation entry for user-facing changes
Version info
26.7.1.641(included in26.7and later)26.6.2.137,26.5.6.99