Repository navigation
Adding aiEmbed function - #102922
Merged
Merged
Adding aiEmbed function#102922
aiEmbed function#102922Conversation
aiGenerateEmbedding function
george-larionov
force-pushed
the
feature/ai-func-infrastructure
branch
from
April 17, 2026 14:34
673355f to
49de7bb
Compare
george-larionov
force-pushed
the
feature/ai-embeddings
branch
from
April 17, 2026 15:12
fcd742a to
1ef615b
Compare
george-larionov
marked this pull request as ready for review
April 17, 2026 20:03
george-larionov
marked this pull request as draft
April 17, 2026 20:15
aiGenerateEmbedding functionaiGenerateEmbedding and aiGenerateSQL functions
Contributor
|
Workflow [PR], commit [dfbdcd8] Summary: ❌
AI ReviewSummaryThis PR adds Findings❌ Blockers
Final Verdict
|
pjhampton
reviewed
Apr 20, 2026
pjhampton
reviewed
Apr 20, 2026
george-larionov
force-pushed
the
feature/ai-embeddings
branch
from
May 6, 2026 11:52
203ea6e to
94c4acf
Compare
Port embedding generation onto the reworked `feature/ai-text-functions` infrastructure: - Add `AIEmbeddingRequest`/`AIEmbeddingResponse` back to `IAIProvider` (with a default `NOT_IMPLEMENTED` `embed` method), and implement it in `OpenAIProvider`. This also serves HuggingFace TEI and other OpenAI-compatible embedding endpoints, and derives the embedding URL from the configured chat endpoint if needed. - `aiGenerateEmbedding` takes a mandatory named collection followed by the text column and an optional constant `dimensions`. Argument validation goes through `FunctionArgumentDescriptors`, matching the style of the other AI functions. - Returns non-nullable `Array(Float32)`; empty array for empty/NULL input or when the request fails with `ai_function_throw_on_error = 0` or a quota is exceeded with `ai_function_throw_on_quota_exceeded = 0`. - The `OrNull` variant is dropped: `ai_function_throw_on_error` already covers the fall-back-to-default behavior for the whole AI family. - Deduplicates identical texts within a query and batches unique texts into `ai_function_embedding_max_batch_size` entries per HTTP request. No background thread pool and no result cache, matching the simplified execution model of the reworked infrastructure.
Extends the AI function test suite with `aiGenerateEmbedding`-specific coverage: the function is registered, argument-count validation, rejecting a non-constant `collection`, rejecting a non-constant `dimensions`, and rejecting wrong types (signed int, string) for `dimensions`; return type is `Array(Float32)` both with and without `dimensions`; empty input returns zero rows without hitting the network; unknown named collection raises `NAMED_COLLECTION_DOESNT_EXIST`; and the `ai_function_embedding_max_batch_size` setting default is `100`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Generates a ClickHouse SQL query from a natural-language prompt, limiting schema introspection to tables/columns the caller has SHOW TABLES / SHOW COLUMNS grants on so nothing is leaked to the LLM endpoint. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
george-larionov
force-pushed
the
feature/ai-embeddings
branch
from
May 6, 2026 13:01
94c4acf to
7c38ca3
Compare
This reverts commit 7c38ca3.
aiGenerateEmbedding and aiGenerateSQL functionsaiGenerateEmbedding function
shankar-iyer
approved these changes
May 22, 2026
Split `AIQuotaTracker::recordResponse` into `recordAttempt` (api_calls) and `recordTokens` (in/out tokens), and move the `recordAttempt` / `++total_api_calls` calls to before the provider request. A failing endpoint with `ai_function_throw_on_error = 0` and retries no longer bypasses `ai_function_max_api_calls_per_query`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Move `aiEmbed`'s `dimensions` bounds check and `FunctionBaseAI`'s `buildSystemPrompt` / `buildResponseFormat` calls above the `input_rows_count == 0` return. Malformed constant arguments (e.g. `aiEmbed`'s out-of-range `dimensions`, `aiExtract`'s broken JSON schema) now fail consistently regardless of source cardinality. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…eturn Add `IAIProvider::supportsEmbeddings()`, defaulting to `false` and overridden to `true` in `OpenAIProvider`. `aiEmbed` now checks the capability immediately after `createAIProvider`, and both `aiEmbed` and `FunctionBaseAI::executeImpl` invoke `createAIProvider` before the `input_rows_count == 0` fast path so that an unknown provider name or an `aiEmbed` call against a chat-only provider (e.g. anthropic) fails the query consistently regardless of source cardinality. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
LLVM Coverage Report
Changed lines: 76.12% (306/402) | lost baseline coverage: 4 line(s) · Uncovered code |
This was referenced Jun 30, 2026
fm4v
added a commit
that referenced
this pull request
Jul 1, 2026
Backport #102922 to 26.4: Adding `aiEmbed` function
fm4v
added a commit
that referenced
this pull request
Jul 1, 2026
Backport #102922 to 26.5: Adding `aiEmbed` function
This was referenced Jul 1, 2026
kewin-robetti
pushed a commit
to viasoftkorp/ClickHouse
that referenced
this pull request
Aug 24, 2026
Backport of ClickHouse#102922. `introduced_in` and the `ai_function_embedding_max_batch_size` settings-history entry are set to 26.4. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
kewin-robetti
pushed a commit
to viasoftkorp/ClickHouse
that referenced
this pull request
Aug 24, 2026
Backport of ClickHouse#102922. `introduced_in` and the `ai_function_embedding_max_batch_size` settings-history entry are set to 26.5. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
3rd part of #100735.
Adds
aiEmbed(collection, text[, dimensions]), an SQL function that returns a text embedding asArray(Float32). Like the existing AI functions it reads its provider, endpoint, model, and API key from a named collection, is gated behindallow_experimental_ai_functions, and participates in the shared per-query quotas (ai_function_max_input_tokens_per_query,ai_function_max_api_calls_per_query). The optionaldimensionsargument, when supported by the model (e.g.OpenAI's
text-embedding-3-*), requests a specific output size; otherwise the model's native size is returned. Supported providers are the OpenAI-compatible ones — OpenAI, vLLM, Ollama, HuggingFace TEI; Anthropic has no public embeddings APIand is intentionally unsupported.
Unlike the other AI functions,
aiEmbedbatches within a single block of rows: up toai_function_embedding_max_batch_size(default100) inputs are sent in one HTTP request, then the response is matched back to input rows byindex.This cuts per-row overhead substantially for typical ingestion patterns such as
INSERT INTO docs SELECT id, doc, aiEmbed('creds', doc) FROM …or avector Array(Float32) DEFAULT aiEmbed('creds', doc)column. NULL and empty-string rows areskipped from batches and produce
[]without any HTTP call.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add
aiEmbedfunction for using LLM APIs to generate embeddings from within ClickHouse.Documentation entry for user-facing changes
Note
Cursor Bugbot is generating a summary for commit 075a761. Configure here.
Version info
26.6.1.206(included in26.6and later)26.5.5.14,26.4.5.91