Skip to content

Add negative-case tests for the Quantized vector codec - #111084

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/vector-quantize-codec-negative-tests
Jul 26, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/vector-quantize-codec-negative-tests

Conversation

@groeneai

@groeneai groeneai commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

Adds negative-case coverage for the Quantized(...) vector column codec (#108565), requested by @egor-click on that PR. Test-only, no source change.

Two new stateless tests:

  • 02354_vector_search_quantize_codec_negative.sql: the codec's error surface, all SQL-observable.
    • DDL-time ILLEGAL_COLUMN: the codec is only valid on Array(Float32|Float64|BFloat16), so a non-Array column, Array(Int32), Array(String), Array(Nullable(Float32)) and Array(LowCardinality(Float32)) are rejected at CREATE TABLE.
    • DDL-time BAD_ARGUMENTS: Quantized(...) is a NONE-category codec and cannot be chained with a compression codec.
    • Write-time SIZES_OF_ARRAYS_DONT_MATCH: a vector whose length differs from the declared dimensions (short, empty, or a mixed-length block) is rejected on INSERT.
  • 02354_vector_search_quantize_codec_bf16_precision.sql: stores Array(BFloat16) and runs the two-stage vector_search_use_quantized_codes path. This covers the coarse-storage case (the existing two-stage tests all store Array(Float32)): the shortlist is rescored against the stored BFloat16 vectors, so the final top-k still matches an exact BFloat16 brute-force scan.

Version info

  • Merged into: 26.8.1.136 (included in 26.8 and later)

@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review — adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).

# Sev Finding Verdict Evidence / action
1 ⚠️ BFloat16 round-trip unproven: the test claimed preservation but asserted only length(vec)=64, and both sides of every comparison came from the same codec-backed table AGREE — fixed @ 38d49ed Added an independent uncompressed control table quantize_bf16_plain and a byte-exact assertion (quantize_bf16 JOIN control WHERE vec != vec = 0, equal counts). Verified codec reads are byte-identical to the control. 50/50 pass.
2 ⚠️ no-parallel-replicas tag on the negative test is unnecessary (its own comment said "defensive rather than required") AGREE — fixed @ 38d49ed Verified the negative test reads no .quantized subcolumn (only count()) and its final SELECT runs correctly under enable_parallel_replicas=1. Removed the tag + comment. Kept the tag only on the bf16 test, which needs it (two-stage plan-shape assertion is disabled under parallel replicas). 50/50 pass.

Severity: ❌ blocker / ⚠️ major / 💡 nit. Delta recheck on the fix commit: 0 findings.

Session id: cron:clickhouse-author-slot-0:20260720-131501

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Each error is triggered on demand by a concrete CREATE/INSERT and verified locally: non-Array / Array(Int32
b Root cause explained? N/A (not a bug fix). Motivation is a coverage gap: the 20 existing 02354_vector_search_quantize_codec_* tests never exercised the write-path length check, the DDL type-rejection path, or a two-stage query over a coarse (BFloat16) storage type.
c Fix matches root cause? Yes. The two new tests target exactly that uncovered surface: DDL/write error paths + the Array(BFloat16) two-stage-vs-exact case @egor-click asked about.
d Test intent preserved / new tests added? Yes. Two new tests added; no existing test weakened or removed.
e Both directions demonstrated? Yes. -- { serverError NAME } fails the run if the expected error is NOT raised (so each line proves both the valid path and the exact rejection); the bf16 test asserts the plan shape fires AND results equal exact brute-force; a control table proves byte-exact round-trip. 50/50 randomized runs of each test pass (100/100, 0 fail).
f Fix is general across code paths? N/A (test-only, no source change).
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes, for the tests: DDL cases cover non-Array, Array(Int32), Array(String), Array(Nullable(Float32)), Array(LowCardinality(Float32)); write cases cover short / empty / mixed-length; storage covers Array(BFloat16). Nullable(Array(Float32)) was intentionally excluded because it raises a generic "Array cannot be inside Nullable" unrelated to the codec.
h Backward compatible? (maintainer-approved exception only) N/A (test-only, no behavior change).
i Invariants and contracts preserved? N/A (test-only, no source change).

Session id: cron:clickhouse-author-slot-0:20260720-131501

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @shankar-iyer — could you review this? It adds the negative-case coverage requested by @ egor-click on #108565: the Quantized vector codec's DDL type rejection (non-Array and non-float-element columns, codec chaining) and write-time length check, plus an Array(BFloat16) two-stage-vs-exact case for the coarse-storage scenario. Test-only.

@clickhouse-gh

clickhouse-gh Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [68374b6]

Summary: ✅


AI Review

Summary

The current diff adds one new stateless test, 02354_vector_search_quantize_codec_negative.sql, covering Quantized(...) DDL-type rejection, chaining rejection, and insert-time dimension mismatch. I did not find a code-level problem in the added coverage: the invalid-type cases exercise the ILLEGAL_COLUMN validation in ColumnsDescription::attachQuantizeSerializationIfNeeded, and the short/empty/mixed inserts target the SIZES_OF_ARRAYS_DONT_MATCH checks in SerializationQuantizedVector. The only issue I found is outside the diff itself: the PR body still says there are two new tests and still describes the removed 02354_vector_search_quantize_codec_bf16_precision.sql, so the written scope no longer matches the current change.

Missing context / blind spots
  • ⚠️ I could not run the new stateless test locally because this checkout does not contain a usable build* directory or test binaries. A local pass of 02354_vector_search_quantize_codec_negative.sql would close that gap.
Final Verdict

✅ No inline review findings on the current code. After updating the PR description to match the one-test diff, this looks ready from a code-review standpoint.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 20, 2026
@egor-click egor-click added can be tested Allows running workflows for external contributors pr-ci and removed pr-ci labels Jul 20, 2026
@shankar-iyer shankar-iyer self-assigned this Jul 20, 2026
@@ -0,0 +1,81 @@
-- Tags: no-parallel-replicas

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a strange test. It does run statements but we are not testing an edge case here. In fact, what is asserted here (scan result of a brute-force scan on a bf16 column equals the scan result of a 2-step scan against br16 column with int8 quantization) is actually numerically unstable. Suggest to remove the entire test.

@rschu1ze

Copy link
Copy Markdown
Member

Cover the Quantized(...) codec error surface (feature added in ClickHouse#108565),
requested by egor-click:

- 02354_vector_search_quantize_codec_negative.sql: DDL-time ILLEGAL_COLUMN
  for non-Array and non-float-element columns, DDL-time BAD_ARGUMENTS for
  chaining with a compression codec, and write-time SIZES_OF_ARRAYS_DONT_MATCH
  for a vector length that differs from the declared dimensions.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done, thanks.

  1. Removed 02354_vector_search_quantize_codec_bf16_precision.sql — its round-trip equality assertion was numerically unstable, as you noted (our own internal review had flagged the same test as weak). The PR is now a single commit adding only 02354_vector_search_quantize_codec_negative.sql (the DDL/write error-surface coverage @ 68374b6).

  2. Docs PR for the codec: Docs: add the Quantized vector codec to the CREATE TABLE codecs page #111128. It adds Quantized(...) to the CREATE TABLE codecs page under Specialized Codecs (it preprocesses vector data rather than encrypting, so it doesn't fit under Encryption Codecs on that page) and links to the full reference in the vector-search docs.

@alexey-milovidov alexey-milovidov self-assigned this Jul 26, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 26, 2026
Merged via the queue into ClickHouse:master with commit 1011611 Jul 26, 2026
178 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 26, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…antize-codec-negative-tests

Add negative-case tests for the Quantized vector codec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-ci 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.

6 participants