Skip to content

Add integration tests for AI functions - #103053

Merged
george-larionov merged 6 commits into
masterfrom
feature/ai-text-functions-integration-tests
Jun 11, 2026
Merged

george-larionov merged 6 commits into
masterfrom
feature/ai-text-functions-integration-tests

Conversation

@george-larionov

@george-larionov george-larionov commented Apr 17, 2026 •

Copy link
Copy Markdown
Member

Adds integration tests with a mock OpenAI-compatible HTTP server for aiGenerate, aiClassify, aiExtract, aiTranslate, and aiEmbed.

For chat completions, the mock detects response_format in requests and returns structured JSON matching the schema (for aiClassify and aiExtract), or echoes the user message as plain text (for aiTranslate and aiGenerate). For embeddings, the
mock returns one deterministic float vector per input, honoring the optional dimensions argument and reporting prompt_tokens so quota and token-accounting paths are exercised.

Coverage per function:

  • Basic execution, multi-row processing, ProfileEvents, NULL handling
  • aiClassify: JSON schema with enum constraint, postProcessResponse extraction of category field
  • aiExtract: simple instruction mode (single result field) and JSON schema mode (multi-field extraction)
  • aiTranslate: plain text response, optional instructions argument
  • aiGenerate: error throw/graceful paths
  • aiEmbed: native and explicit dimensions, multi-row batching into a single HTTP call, ai_function_embedding_max_batch_size splitting inputs across multiple calls, NULL/empty inputs mapping to [] without a request, error throw/graceful paths,
    rejection of malformed provider responses (duplicate index, wrong cardinality), and ai_function_max_input_tokens_per_query quota truncation

To be merged after #102922

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Note

Low Risk
Low risk: only adds integration-test code and a standalone mock server, with no production logic changes.

Overview
Adds a new tests/integration/test_ai_functions suite that spins up a ClickHouse instance plus a local OpenAI-compatible mock server, then validates aiGenerate, aiClassify, aiExtract, aiTranslate, and aiEmbed across basic, multi-row, NULL/empty-input, and ProfileEvents/token-accounting scenarios.

The mock server implements chat-completions and embeddings endpoints (including structured response_format JSON-schema replies) plus dedicated failure/malformed-response routes to test error handling, embedding batching (ai_function_embedding_max_batch_size), and quota-cut behavior (ai_function_max_input_tokens_per_query).

Reviewed by Cursor Bugbot for commit e260eec. Bugbot is set up for automated code reviews on this repo. Configure here.

Version info

  • Merged into: 26.6.1.681

@george-larionov
george-larionov force-pushed the feature/ai-text-functions-integration-tests branch 2 times, most recently from 3ee7788 to 6629fdc Compare April 18, 2026 03:49
@george-larionov george-larionov assigned rschu1ze and unassigned rschu1ze Apr 18, 2026
Base automatically changed from feature/ai-text-functions to master April 20, 2026 07:47
@george-larionov george-larionov mentioned this pull request Apr 30, 2026
1 task done
@george-larionov george-larionov mentioned this pull request May 11, 2026
1 task done
@george-larionov
george-larionov force-pushed the feature/ai-text-functions-integration-tests branch from 6629fdc to f4bc442 Compare May 15, 2026 10:11
@clickhouse-gh

clickhouse-gh Bot commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8607433]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, old analyzer, 1/6) FAIL
test_refreshable_mat_view_replicated/test.py::test_circular_dependencies_survive_restart FAIL cidb IGNORED

AI Review

Summary

This PR adds a dedicated test_ai_functions integration suite with a local OpenAI-compatible mock server for aiGenerate, aiClassify, aiExtract, aiTranslate, and aiEmbed. I did not find any new blocker or major issue in the current test-only diff, and the prior clickhouse-gh test-expectation thread is fixed in the current code.

Missing context / blind spots
  • ⚠️ Full GitHub checks were still pending when reviewed: 8 pending, 3 passing, and 23 skipped. The available Praktika summary for the PR showed no failed tests; completed CI would close this gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 15, 2026
@george-larionov
george-larionov force-pushed the feature/ai-text-functions-integration-tests branch from f4bc442 to 136a172 Compare May 15, 2026 16:00
Comment thread src/Functions/FunctionBaseAI.cpp Resolved
Comment thread src/Functions/AI/OpenAIProvider.cpp Resolved
Comment thread src/Functions/aiEmbed.cpp Resolved
@george-larionov george-larionov changed the title Add integration tests for AI text functions Add integration tests for AI functions May 15, 2026
@george-larionov
george-larionov changed the base branch from master to feature/ai-embeddings May 15, 2026 16:18
@alexey-milovidov

Copy link
Copy Markdown
Member

This was fixed by #105146. Let's update the branch.

@george-larionov
george-larionov force-pushed the feature/ai-text-functions-integration-tests branch 2 times, most recently from 69d1161 to e260eec Compare May 21, 2026 17:09
@george-larionov
george-larionov marked this pull request as ready for review May 23, 2026 15:50
Base automatically changed from feature/ai-embeddings to master May 27, 2026 20:29
@george-larionov
george-larionov requested a review from rschu1ze May 27, 2026 21:18
@george-larionov
george-larionov force-pushed the feature/ai-text-functions-integration-tests branch from e260eec to 8902e44 Compare May 29, 2026 22:13
@george-larionov
george-larionov force-pushed the feature/ai-text-functions-integration-tests branch from 8902e44 to a0982c8 Compare June 9, 2026 19:00
@george-larionov
george-larionov removed the request for review from rschu1ze June 9, 2026 21:35
@george-larionov
george-larionov enabled auto-merge June 9, 2026 22:01
george-larionov and others added 2 commits June 10, 2026 20:57
Adds integration tests with a mock OpenAI-compatible HTTP server for
`aiGenerateContent`, `aiClassify`, `aiExtract`, and `aiTranslate`.

The mock detects `response_format` in requests and returns structured
JSON matching the schema (for `aiClassify` and `aiExtract`), or echoes
the user message as plain text (for `aiTranslate` and `aiGenerateContent`).

Coverage per function:
- Basic execution, multi-row processing, ProfileEvents, NULL handling
- `aiClassify`: JSON schema with enum constraint, `postProcessResponse`
  extraction of category field
- `aiExtract`: simple instruction mode (single result field) and JSON
  schema mode (multi-field extraction)
- `aiTranslate`: plain text response, optional instructions argument
- `aiGenerateContent`: error throw/graceful paths

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Extends the existing mock OpenAI-compatible HTTP server with embedding
endpoints (`/v1/embeddings`, plus malformed-response and error variants)
and adds twelve `aiEmbed` cases covering: native and explicit
`dimensions`, multi-row batching into a single HTTP call,
`ai_function_embedding_max_batch_size` splitting inputs across calls,
`NULL` / empty inputs mapping to `[]` without a request, error throw vs.
graceful fallback, provider response validation (duplicate `index`,
wrong cardinality), and `ai_function_max_input_tokens_per_query` quota
truncation.

Also updates the pre-existing `aiGenerateContent` call sites to use the
function's registered name `aiGenerate` so those tests still pass after
rebasing onto `feature/ai-embeddings`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
george-larionov and others added 4 commits June 10, 2026 20:57
Pre-filtered `NULL`/empty inputs no longer count toward `AIRowsSkipped`;
only quota- or error-cut rows do, matching the documented contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Bump mock port to 18123, drop unnecessary sentinel UUIDs in
`test_translate_with_instructions`, and remove a redundant
`TRUNCATE`/`INSERT` from `test_generate_content_basic`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Update embed-validation tests to expect MALFORMED_AI_PROVIDER_RESPONSE
(introduced upstream) instead of RECEIVED_ERROR_FROM_REMOTE_IO_SERVER,
and add coverage for optional api_key in AI named collections: verify
the Authorization header is omitted when no key is set and forwarded
as a Bearer token when present.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@george-larionov
george-larionov force-pushed the feature/ai-text-functions-integration-tests branch from a0982c8 to 8607433 Compare June 10, 2026 20:59
@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.70% 84.60% -0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.30% 77.20% -0.10%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 467 line(s), 60 function(s) across 129 file(s) · Details

Top files
  • src/Functions/AI/OpenAIProvider.cpp: 43 line(s), 1 function(s)
  • src/Interpreters/IcebergMetadataLog.cpp: 25 line(s), 1 function(s)
  • src/AggregateFunctions/AggregateFunctionIntervalLengthSum.cpp: 18 line(s), 40 function(s)
  • src/Functions/aiEmbed.cpp: 18 line(s), 1 function(s)
  • src/Disks/IO/CachedOnDiskWriteBufferFromFile.cpp: 15 line(s)

Full report

@george-larionov

Copy link
Copy Markdown
Member Author

The failing test is flaky and unrelated: #106651

@george-larionov
george-larionov added this pull request to the merge queue Jun 11, 2026
Merged via the queue into master with commit c948242 Jun 11, 2026
164 of 166 checks passed
@george-larionov
george-larionov deleted the feature/ai-text-functions-integration-tests branch June 11, 2026 18:44
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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