Skip to content

AI functions: send X-ClickHouse-AI-Function header from OpenAI provider - #110449

Merged
george-larionov merged 5 commits into
masterfrom
ai-functions-openai-function-name-header
Jul 28, 2026
Merged

george-larionov merged 5 commits into
masterfrom
ai-functions-openai-function-name-header

Conversation

@george-larionov

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

Copy link
Copy Markdown
Member

Tag every OpenAI-format request with the SQL name of the calling AI function so an upstream endpoint can identify it. Header only; other providers ignore the new AIRequest/AIEmbeddingRequest field.

With the change, the outbound POST gains one extra header line. For an aiGenerate call against a keyed collection, the request headers look like:

  POST /v1/chat/completions HTTP/1.1
  Host: your-endpoint.example.com
  Content-Type: application/json
  Authorization: Bearer <api_key>
  X-ClickHouse-AI-Function: aiGenerate
  Content-Length: 142

Changelog category (leave one):

  • Experimental Feature

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

Tag OpenAI-format HTTP requests with the SQL name of the calling AI function for upstream endpoint identification.

Version info

  • Merged into: 26.8.1.312 (included in 26.8 and later)
  • Backported to: 26.7.2.38, 26.6.2.139, 26.5.6.101

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b9da01b]

Summary: ✅


AI Review

Summary

The PR adds X-ClickHouse-AI-Function to OpenAI-format AI requests by threading the calling function name through both the chat and embedding request paths. I re-checked the prior inline discussion against current head, including the earlier aiEmbed coverage gap, and did not find any remaining correctness, compatibility, or coverage issues in the current implementation.

Final Verdict

Status: ✅ Approve

@george-larionov
george-larionov force-pushed the ai-functions-openai-function-name-header branch from c146c9d to 6f61d3e Compare July 14, 2026 21:05
@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Jul 14, 2026
@rschu1ze rschu1ze self-assigned this Jul 16, 2026
Comment thread src/Functions/FunctionBaseAI.cpp Resolved
Comment thread src/Functions/AI/OpenAIProvider.cpp Resolved
Comment thread src/Functions/AI/IAIProvider.h Resolved
@george-larionov
george-larionov marked this pull request as ready for review July 16, 2026 18:58
@george-larionov

Copy link
Copy Markdown
Member Author

The failing test is fixed on master, doing a rebase on fresh master

@george-larionov
george-larionov force-pushed the ai-functions-openai-function-name-header branch from 4bd14cd to 971c5d3 Compare July 21, 2026 14:53
@mintlify

mintlify Bot commented Jul 21, 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 21, 2026, 4:52 PM

@george-larionov

Copy link
Copy Markdown
Member Author

Cannot start clickhouse-server is the only failure, but the related issue is closed as not planned.

@george-larionov

Copy link
Copy Markdown
Member Author

Failures are due to ASAN run hitting memory limit, tracked by #111304

george-larionov and others added 5 commits July 27, 2026 23:39
Tag every OpenAI-format request with the SQL name of the calling AI
function so an upstream endpoint can identify it. Header only; other
providers ignore the new AIRequest/AIEmbeddingRequest field.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The AI functions already expose their SQL name via IFunction::getName.
Use it for the X-ClickHouse-AI-Function header and drop the duplicate
functionName virtual and its four overrides.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Both request construction sites populate function_name via getName, so
drop the empty check and assert the invariant in the provider.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Note in the docs that requiring `model` as a positional argument enforces
reproducible embeddings, and trim redundant comments in aiEmbed.cpp.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
aiEmbed now takes model as a required positional argument, so the
header test must pass it explicitly like every other aiEmbed call.

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

Copy link
Copy Markdown
Member Author

Investigating CI failures, filed: #112203

@clickhouse-gh

clickhouse-gh Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 78.40% 78.40% +0.00%

Changed lines: Changed C/C++ lines covered: 41/42 (97.62%) · Uncovered code

Full report · Diff report

@george-larionov
george-larionov added this pull request to the merge queue Jul 28, 2026
Merged via the queue into master with commit 71ec9af Jul 28, 2026
180 checks passed
@george-larionov
george-larionov deleted the ai-functions-openai-function-name-header branch July 28, 2026 20:31
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 28, 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
clickhouse-gh Bot pushed a commit that referenced this pull request Jul 30, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jul 30, 2026
Backport #110449 to 26.7: AI functions: send X-ClickHouse-AI-Function header from OpenAI provider
robot-clickhouse added a commit that referenced this pull request Aug 1, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Aug 1, 2026
Cherry pick #110449 to 26.5: AI functions: send X-ClickHouse-AI-Function header from OpenAI provider
robot-clickhouse added a commit that referenced this pull request Aug 1, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 1, 2026
george-larionov added a commit that referenced this pull request Aug 1, 2026
Backport #110449 to 26.5: AI functions: send X-ClickHouse-AI-Function header from OpenAI provider
george-larionov added a commit that referenced this pull request Aug 1, 2026
Backport #110449 to 26.6: AI functions: send X-ClickHouse-AI-Function header from OpenAI provider

This branch was successfully deployed

1 active deployment
staging - docs — b9da01bc Deployed Jul 28, 2026 by mintlify[bot]
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.

5 participants