Skip to content

Add dotProductTransposed distance function for QBit - #108100

Merged
alexey-milovidov merged 7 commits into
masterfrom
qbit-dot-product-transposed
Jul 1, 2026
Merged

alexey-milovidov merged 7 commits into
masterfrom
qbit-dot-product-transposed

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 22, 2026 •

Copy link
Copy Markdown
Member

Adds dotProductTransposed, the transposed (bit-plane) inner-product function for the QBit data type.

QBit already supported the transposed distance functions L2DistanceTransposed and cosineDistanceTransposed, but had no inner-product counterpart. This change adds dotProductTransposed, the transposed analogue of dotProduct. Unlike the distance functions, the dot product is a similarity measure: larger values mean more similar vectors.

The function returns Float64 and takes the same (qbit, reference, p) arguments as the other transposed functions, where p selects how many bit planes to read for the precision-speed trade-off. It reuses the generic FunctionArrayDistance kernel machinery: the new DotProductTransposed kernel resolves the SimSIMD dot metric with a scalar fallback. It is also recognized by DistanceTransposedPartialReadsPass, so the partial-reads optimization (optimize_qbit_distance_function_reads) applies to it. scalarProductTransposed is registered as an alias, mirroring the existing dotProduct/scalarProduct pair.

Changelog category (leave one):

  • New Feature

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

Added the dotProductTransposed function (alias scalarProductTransposed) that computes the approximate inner product between a QBit column and a reference vector, complementing the existing L2DistanceTransposed and cosineDistanceTransposed functions.

Version info

  • Merged into: 26.7.1.329 (included in 26.7 and later)

`QBit` already supports the transposed (bit-plane) distance functions
`L2DistanceTransposed` and `cosineDistanceTransposed`, but had no inner
product counterpart. This adds `dotProductTransposed`, the transposed
analogue of `dotProduct`.

Unlike the distance functions, the dot product is a similarity measure:
larger values mean more similar vectors. It returns `Float64` and accepts
the same `(qbit, reference, p)` arguments, where `p` selects how many bit
planes to read for the precision-speed trade-off.

Implementation reuses the generic `FunctionArrayDistance` kernel machinery:
the new `DotProductTransposed` kernel resolves the SimSIMD `dot` metric and
provides a scalar fallback. The function is also recognized by
`DistanceTransposedPartialReadsPass` so the partial-reads optimization
applies to it as well. `scalarProductTransposed` is registered as an alias,
mirroring the `dotProduct`/`scalarProduct` pair.

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

clickhouse-gh Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1f4cb31]

Summary: ✅


AI Review

Summary

This PR adds dotProductTransposed and the scalarProductTransposed alias for QBit, wires the function into the existing transposed-distance execution path and partial-read analyzer pass, and adds focused value/plan coverage including the earlier requested partial-read proof. I did not find any remaining correctness, safety, or coverage issue that needs an inline finding.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jun 22, 2026
@alexey-milovidov
alexey-milovidov requested a review from rienath June 22, 2026 04:39
@rienath rienath self-assigned this Jun 22, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM and it is fairly simple. Only need to add the path for Int8.

@alexey-milovidov alexey-milovidov self-assigned this Jun 28, 2026
alexey-milovidov and others added 2 commits June 28, 2026 21:07
Following the addition of `Int8` to the `QBit` data type (#108105), extend
the new `dotProductTransposed` kernel to handle `Int8` `QBit` columns, the
same way `L2DistanceTransposed` and `cosineDistanceTransposed` already do
after merging `master`.

The `DotProductTransposed` kernel gains the `Int8` scalar branch and the
`max_int8_simd_term` overflow bound (max `|a * b|` is `128 * 128`, when both
elements are `-128`). The rest of the `Int8` machinery - reference type
acceptance, accumulator dispatch, SimSIMD `i8` kernel resolution, and the
int32 overflow guard - is shared by `FunctionArrayDistance` and already
applies once `master` is merged.

Bump the documented `IntroducedIn` version to 26.7 to match the current
development version, and add `Int8` coverage to 04403_dot_product_transposed:
exact full-precision dot products, reduced precision, and a large-dimension
case that exercises the int32-overflow fallback to the `Float64` scalar path.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alexey-milovidov and others added 2 commits June 29, 2026 20:31
Address the AI review on PR #108100. The existing `04403_dot_product_transposed`
test only compares the returned values with `optimize_qbit_distance_function_reads`
disabled and enabled, so it would still pass if `dotProductTransposed` were dropped
from `DistanceTransposedPartialReadsPass` and the query read the whole `QBit` column.

Add `04489_dot_product_transposed_partial_reads_pass`, the plan-level companion to
`03375_l2_distance_transposed_partial_reads_pass`. It uses `EXPLAIN` to prove that
`dotProductTransposed` (and its `scalarProductTransposed` alias) read only the
requested bit planes `vec.1` .. `vec.p` when the optimization is enabled, and the
whole `vec` column when it is disabled.

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

Copy link
Copy Markdown
Member Author

Updated this PR:

  • Merged master (the branch was ~299 commits behind and red).
  • Addressed the AI review's "Request changes": added the plan-level test 04489_dot_product_transposed_partial_reads_pass (companion to 03375_l2_distance_transposed_partial_reads_pass). The pre-existing 04403_dot_product_transposed only compares returned values with optimize_qbit_distance_function_reads on/off, so it would still pass if dotProductTransposed were dropped from DistanceTransposedPartialReadsPass. The new test uses EXPLAIN to prove that dotProductTransposed (and its scalarProductTransposed alias, which canonicalizes to dotProductTransposed) read only the requested bit planes vec.1 .. vec.p when the optimization is enabled, and the whole vec column when it is disabled.
  • The Int8 path requested in review is already present (commit Add Int8 support to dotProductTransposed).

The only CI red was the Upgrade check (amd_release) "Error message in clickhouse-server.log" failure (FUNCTION_THROW_IF_VALUE_IS_NON_ZERO from MutatePlainMergeTreeTask). This is unrelated to this QBit function change — it originates from 02597_column_update_and_replication, which deliberately runs ALTER TABLE test UPDATE x = x + throwIf(1) with mutations_sync=0 and then KILLs it; the background mutation logs the throwIf error before it is killed, and the upgrade-check error scan intermittently catches it (a race, hence flaky). The test is not tagged no-upgrade-check.

@groeneai, could you investigate this upgrade-check log-noise flake and provide a fix in a separate PR (or link an existing one if it is already being tracked)? I could not find an open issue for it.

@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov Confirmed. This is the chronic background-mutation upgrade-check log-noise (issue #39174 class), FUNCTION_THROW_IF_VALUE_IS_NON_ZERO sub-pattern. 02597_column_update_and_replication runs ALTER TABLE test UPDATE x = x + throwIf(1) with mutations_sync=0 then KILLs it; MutatePlainMergeTreeTask logs the throwIf error before the kill lands, and the upgrade-check error scan races and catches it. By-design (lazy mutation validation), not an engine defect, and unrelated to this PR (dotProductTransposed touches no mutation/merge path).

CIDB (30d, Upgrade check + FUNCTION_THROW_IF_VALUE_IS_NON_ZERO): 19 hits across 19 distinct PRs, 0 on master.

Already tracked and fixed by #108651 ("Match benign mutation parse errors by class in the Upgrade check"), which you approved. It allow-lists this benign class in tests/docker_scripts/upgrade_runner.sh by error code plus background-mutation executor, covering both the CANNOT_PARSE_TEXT and FUNCTION_THROW_IF_VALUE_IS_NON_ZERO sub-patterns:

grep -avE -e "(MutatePlainMergeTreeTask|MutateFromLogEntryTask|MergeTreeBackgroundExecutor).*(Cannot parse string .* as .*CANNOT_PARSE_TEXT|FUNCTION_THROW_IF_VALUE_IS_NON_ZERO)"

No separate PR needed; #108651 covers it.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108100&sha=1104e5e3797c6893de456305c6c4958c4fd6673e&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Merged the latest master into the branch (clean, no conflicts) to refresh CI; the net diff is unchanged and both changed translation units (src/Functions/array/distanceTransposed.cpp, src/Functions/vectorFunctions.cpp) pass -fsyntax-only.

The three red checks on the previous run are all unrelated flakes, none of which a new QBit distance function can cause:

  • AST fuzzer (amd_debug, targeted): MEMORY_LIMIT_EXCEEDED (phantom 225 GiB allocation) in TCPHandler::receiveHello during SET send_logs_level = 'fatal' — a connection-setup flake. The targeted fuzzer test itself passed.
  • 04240_streaming_partitioned_merge_tree: 600s timeout on a ... STREAM ... query. The harness re-ran it 4 times — all passed — and reported "not reproducible (likely a transient issue)". It also hit the unrelated PR Allow INSERT into regular views #102866.
  • Some queries hung: a consequence of the timeout above.

The fresh CI run triggered by this merge should clear the transient failures.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Merged the latest master into the branch (clean, no conflicts) to refresh CI. The net diff is unchanged (+317/-1 across the same 10 files — the dotProductTransposed/scalarProductTransposed feature only), and master did not touch any of the files this PR depends on (distanceTransposed.cpp, vectorFunctions.cpp, arrayDistance, DistanceTransposedPartialReadsPass.cpp, DataTypeQBit.cpp). Both changed translation units (src/Functions/array/distanceTransposed.cpp, src/Functions/vectorFunctions.cpp) pass -fsyntax-only against the merged tree.

Review status is unchanged: AI Review verdict is ✅ Approve with no required actions, the single inline thread is resolved, and there are no unresolved threads. Still BLOCKED only on the requested human review.

The sole CI red on the previous run was the known transient phantom-memory flake in the AST fuzzer (amd_debug, targeted): a MEMORY_LIMIT_EXCEEDED reporting a 257 GiB allocation while RSS was only 12 GiB, thrown from DB::TCPHandler::receiveHello during SET send_logs_level = 'fatal' at connection handshake — not reachable from a QBit function. The targeted fuzzer test itself passed. The merge re-fires CI to confirm it clears.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

The fresh CI run (commit 1f4cb31a) is clean except for one flaky stateless failure: 02985_dialects_with_distributed_tables in Stateless tests (arm_binary, parallel), which fails at connection setup with:

Code: 102. DB::Exception: Unexpected packet from server 127.0.0.4:9000 (expected TablesStatusResponse, got ProfileInfo): While executing Remote. (UNEXPECTED_PACKET_FROM_SERVER)

thrown from Connection::getTablesStatus via ConnectionEstablisher::run — a pooled connection reused while it still holds undelivered packets (ProfileInfo/EndOfStream) that a previous cancelled distributed query left behind. This is a master-wide connection-establishment flake unrelated to this PR, which only adds the dotProductTransposed QBit function and touches no connection or distributed code path. Over the last 30 days the same expected TablesStatusResponse, got ProfileInfo signature has hit ~20 distinct distributed-table tests across many PRs and master directly (e.g. 04204_global_in_join_max_rows_to_transfer_103333, 03360_bool_remote, 02875_parallel_replicas_cluster_all_replicas, 00009_uniq_distributed); 02985_dialects_with_distributed_tables itself has failed on PRs #105056, #108087, #96886, #106734, never on master.

The root cause and fix are already in progress in #108854, which disconnects out-of-sync pooled connections in RemoteQueryExecutor::finish and treats UNEXPECTED_PACKET_FROM_SERVER as a soft connection-establishment failure (retry on a fresh connection) in ConnectionEstablisher::run. No separate fix is needed here.

Otherwise the PR is in good shape: the branch is 0 commits behind master, MERGEABLE, the AI Review verdict is ✅ Approve, and there are no unresolved review threads. It remains BLOCKED only on the requested human review.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Re-checked the current run (commit 1f4cb31a). No code change needed — the feature is complete and review feedback is addressed:

  • The requested Int8 path is present (commit Add Int8 support to dotProductTransposed): the scalar fallback accumulates in Float64, and max_int8_simd_term = 128 * 128 correctly bounds the dimension before the SimSIMD i8 dot kernel's int32 accumulator could overflow (same scheme as cosineDistanceTransposed).
  • The bot's partial-reads concern is resolved by the plan-level EXPLAIN test 04489_dot_product_transposed_partial_reads_pass.
  • AI Review verdict is ✅ Approve; the single inline thread is resolved; MERGEABLE, 6 commits behind a merge-base from today.

Both CI reds are known flakes, unrelated to this PR (it adds only a QBit distance function — no distributed, mutation, or connection code path):

  • Stateless tests (arm_binary, parallel) → 02985_dialects_with_distributed_tables: Unexpected packet from server (expected TablesStatusResponse, got ProfileInfo) (UNEXPECTED_PACKET_FROM_SERVER) thrown from Connection::getTablesStatus — a pooled connection reused while holding undelivered packets from a previously cancelled distributed query. Tracked by Fix flaky distributed query "Unexpected packet from server (expected TablesStatusResponse, got ProfileInfo)" #108854.
  • Upgrade check (amd_release): FUNCTION_THROW_IF_VALUE_IS_NON_ZERO logged by MutatePlainMergeTreeTask (from 02597_column_update_and_replication's ALTER TABLE ... UPDATE x = x + throwIf(1) killed mid-mutation; the log scan races the kill). This red is new on 1f4cb31a (it ran at ~10:59 UTC, after the previous comment), but it is the same benign background-mutation log noise already confirmed above and allow-listed by the in-flight fix Match benign mutation parse errors by class in the Upgrade check #108651.

The remaining checks (Stateless tests (amd_llvm_coverage …), SQLLogic test, Style check, CH Inc sync) are still in progress.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Continue-PR pass (no code change): independently verified the feature is correct and complete, and confirmed both CI reds are known unrelated flakes.

Implementation review — sound and complete:

  • DotProductTransposed resolves the SimSIMD simsimd_metric_dot_k kernel with a Float64-accumulating scalar fallback. The reference values in 04403_dot_product_transposed are the true (un-negated) inner products (e.g. [0,1,2]·[2,3,4] = 11, Int8 [0..7]·[0..7] = 140, large-dim = 2147483648), confirming the SimSIMD dot result matches the scalar path sign-for-sign.
  • Int8 path is present and the overflow guard is correct: max_int8_simd_term = 128 * 128 (max |(-128)*(-128)| = 16384) falls back to the scalar Float64 path for qbit_size >= 131072, exactly where the SimSIMD i8 int32 accumulator would overflow — and the test exercises that boundary.
  • Wired into DistanceTransposedPartialReadsPass, registered via DotProductTransposedTraits, with the scalarProductTransposed alias. The plan-level 04489_dot_product_transposed_partial_reads_pass proves via EXPLAIN actions=1 that the optimization reads only vec.1..vec.4 when enabled and the whole vec when disabled (and that the alias canonicalizes to dotProductTransposed), resolving the earlier partial-reads bot concern.

Review status: AI Review verdict is ✅ Approve; the single inline thread is resolved; no unresolved threads. The Int8 path requested in review is in place.

CI: both reds on 1f4cb31a are known flakes unrelated to a QBit distance function (it touches no distributed, connection, or mutation path):

I re-ran the failed Stateless tests (arm_binary, parallel) job to try for a clean run. No re-merge: the merge-base is from today (2f479993, <1 day) and the reds are not master-fixable. The PR remains MERGEABLE and BLOCKED only on human review/merge.

@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.50% +0.10%
Functions 92.70% 92.70% +0.00%
Branches 77.60% 77.70% +0.10%

Changed lines: Changed C/C++ lines covered: 69/72 (95.83%) · Uncovered code

Full report · Diff report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Continue-PR pass (no code change). The feature is complete and review feedback is addressed (AI Review verdict ✅ Approve, the single inline thread is resolved, no unresolved threads, MERGEABLE). The merge-base is from today (2f479993, <1 day), so no re-merge.

The fresh run on 1f4cb31a has a single new red, not covered by my earlier comments:

I re-ran the failed Stress test (arm_debug) job to try for a clean run (the specific fuzzer mutation is unlikely to recur).

@groeneai, could you investigate this recurring debug-only Inconsistent KeyCondition behavior stress/fuzzer flake and provide a fix or a tracking issue in a separate PR? I could not find an open issue for it — #90461 (its root-cause class) is closed, so the assertion firing on UInt64-vs-UInt256 comparisons in the 04303 fuzzer mutations looks like a fresh manifestation worth tracking.

Otherwise the PR is in good shape and remains BLOCKED only on the requested human review.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 1, 2026
Merged via the queue into master with commit ed5970b Jul 1, 2026
511 of 514 checks passed
@alexey-milovidov
alexey-milovidov deleted the qbit-dot-product-transposed branch July 1, 2026 06:15
alexey-milovidov added a commit that referenced this pull request Jul 1, 2026
Merging master brought in the just-merged `dotProductTransposed`
(PR #108100). Because all three transposed distance functions
(`L2DistanceTransposed`, `cosineDistanceTransposed`,
`dotProductTransposed`) share the generic `FunctionArrayDistance<Kernel>`
template and the `DistanceTransposedPartialReadsPass`, the optional
fourth `dims` argument for Matryoshka-style reduced-dimension search on a
strided `QBit` now works for `dotProductTransposed` (and its
`scalarProductTransposed` alias) too, with no function-specific code.

Advertise the optional `dims` argument in the `dotProductTransposed`
function documentation (syntax and argument list), matching the other
two transposed functions, and add a focused test
`04494_qbit_stride_dot_product_transposed.sql` that proves value
equality against a non-strided baseline, the `scalarProductTransposed`
alias, nullability propagation, the validation rules, and the
partial-read I/O contract (an 8-bit search over the first 2048 of 4096
dimensions reads 16 of 64 plane streams).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 1, 2026
@groeneai

groeneai commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Investigated the Inconsistent KeyCondition behavior red on 1f4cb31a — it is not caused by this PR, and I have a fix in a separate PR: #109023.

Root cause (not general inaccurate monotonicity — the cast is genuinely strict): the team_id = 1 -> team_id = toUInt256(1) mutation inserts a widening CAST(UInt64 -> UInt256) into the key column's monotonic chain. KeyCondition::matchesExactContinuousRange marks the column an exact POINT because the chain is strict, but checkInRange applies the chain to granule bounds with forced-closed bounds, so a granule straddling the team_id boundary honestly reports can_be_false. That contradicts the POINT exactness promise and markRangesFromPKRange throws the #ifndef NDEBUG canary. Release builds are unaffected (compiled out; the count was already correct, just a couple more granules read).

Deterministic repro on debug (clickhouse-local, table persisted then queried in a separate process):

CREATE TABLE t (team_id UInt64, k UInt8, s String) ENGINE = MergeTree ORDER BY (team_id, k, s) SETTINGS index_granularity = 4;
SYSTEM STOP MERGES t;
INSERT INTO t SELECT 1, number % 5, toString(number) FROM numbers(50);
INSERT INTO t SELECT 2, number % 5, toString(number) FROM numbers(50);
INSERT INTO t SELECT number % 3, number % 5, toString(number) FROM numbers(50);
-- separate process:
SELECT count() FROM t WHERE team_id = toUInt256(1) AND k = 0;   -- aborts pre-fix

Fix in #109023: only promote a key column to POINT when its monotonic-function chain is empty; a non-empty chain (even strict) can't promise exact continuity across boundary granules, so treat it as a RANGE (mirrors how non-strict chains are already handled). This only disables the exact-range fast path for the affected queries; pruning and results are unchanged. Regression test 04493_key_condition_wide_type_exact_range.sh fires without the fix and passes with it, across the UInt256/Int256/UInt128/Int128/IN variants.

Blargian pushed a commit to Blargian/ClickHouse that referenced this pull request Jul 27, 2026
matchesExactContinuousRange gates the exact continuous-range (implicit
count projection) optimization and classifies a key column as an exact
POINT when its monotonic-function chain is strict.

Comparing a key column against a wider-typed constant (e.g. a UInt64 key
vs toUInt256(...)) inserts a widening CAST into that chain. The widening
cast is genuinely strictly monotonic, so the column was marked POINT. But
checkInRange applies the chain to the granule bounds via
applyMonotonicFunctionsChainToRange, which forces the bounds closed. For a
granule that straddles the key boundary, the closed-bound mapped range
only partially matches, so checkInRange honestly reports can_be_false =
true. That contradicts the POINT "exact continuous" promise, and the exact
range computation in markRangesFromPKRange then finds an interior granule
that can_be_false and throws the debug-only "Inconsistent KeyCondition
behavior" logical error (the ClickHouse#90461 monotonicity canary, #ifndef NDEBUG).

Found by the AST fuzzer mutating 04303_key_condition_ifnull_coalesce_boolean.sql
(team_id = 1 -> team_id = toUInt256(1)) in Stress test (arm_debug) on
PR ClickHouse#108100 (STID 5182-2f27).

There is no behavior change in release builds (the branch is compiled out
under NDEBUG); the count result was already correct, the wider-typed
comparison just reads a couple more granules.

Fix: only promote a key column to POINT when its monotonic-function chain
is empty (a native key column). A non-empty chain, even a strict one,
cannot promise exact continuity across boundary granules because the chain
application forces closed bounds; treat such a column as a RANGE. This
mirrors how the function already downgrades non-strict chains and only
disables the exact-range fast path for the affected queries (pruning and
results are unchanged).

Related: ClickHouse#90461

Co-Authored-By: Claude Opus 4.8 <[email protected]>
scanhex12 pushed a commit to scanhex12/ClickHouse that referenced this pull request Jul 29, 2026
matchesExactContinuousRange gates the exact continuous-range (implicit
count projection) optimization and classifies a key column as an exact
POINT when its monotonic-function chain is strict.

Comparing a key column against a wider-typed constant (e.g. a UInt64 key
vs toUInt256(...)) inserts a widening CAST into that chain. The widening
cast is genuinely strictly monotonic, so the column was marked POINT. But
checkInRange applies the chain to the granule bounds via
applyMonotonicFunctionsChainToRange, which forces the bounds closed. For a
granule that straddles the key boundary, the closed-bound mapped range
only partially matches, so checkInRange honestly reports can_be_false =
true. That contradicts the POINT "exact continuous" promise, and the exact
range computation in markRangesFromPKRange then finds an interior granule
that can_be_false and throws the debug-only "Inconsistent KeyCondition
behavior" logical error (the ClickHouse#90461 monotonicity canary, #ifndef NDEBUG).

Found by the AST fuzzer mutating 04303_key_condition_ifnull_coalesce_boolean.sql
(team_id = 1 -> team_id = toUInt256(1)) in Stress test (arm_debug) on
PR ClickHouse#108100 (STID 5182-2f27).

There is no behavior change in release builds (the branch is compiled out
under NDEBUG); the count result was already correct, the wider-typed
comparison just reads a couple more granules.

Fix: only promote a key column to POINT when its monotonic-function chain
is empty (a native key column). A non-empty chain, even a strict one,
cannot promise exact continuity across boundary granules because the chain
application forces closed bounds; treat such a column as a RANGE. This
mirrors how the function already downgrades non-strict chains and only
disables the exact-range fast path for the affected queries (pruning and
results are unchanged).

Related: ClickHouse#90461

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Address the AI review on PR ClickHouse#108100. The existing `04403_dot_product_transposed`
test only compares the returned values with `optimize_qbit_distance_function_reads`
disabled and enabled, so it would still pass if `dotProductTransposed` were dropped
from `DistanceTransposedPartialReadsPass` and the query read the whole `QBit` column.

Add `04489_dot_product_transposed_partial_reads_pass`, the plan-level companion to
`03375_l2_distance_transposed_partial_reads_pass`. It uses `EXPLAIN` to prove that
`dotProductTransposed` (and its `scalarProductTransposed` alias) read only the
requested bit planes `vec.1` .. `vec.p` when the optimization is enabled, and the
whole `vec` column when it is disabled.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-transposed

Add dotProductTransposed distance function for QBit
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Merging master brought in the just-merged `dotProductTransposed`
(PR ClickHouse#108100). Because all three transposed distance functions
(`L2DistanceTransposed`, `cosineDistanceTransposed`,
`dotProductTransposed`) share the generic `FunctionArrayDistance<Kernel>`
template and the `DistanceTransposedPartialReadsPass`, the optional
fourth `dims` argument for Matryoshka-style reduced-dimension search on a
strided `QBit` now works for `dotProductTransposed` (and its
`scalarProductTransposed` alias) too, with no function-specific code.

Advertise the optional `dims` argument in the `dotProductTransposed`
function documentation (syntax and argument list), matching the other
two transposed functions, and add a focused test
`04494_qbit_stride_dot_product_transposed.sql` that proves value
equality against a non-strided baseline, the `scalarProductTransposed`
alias, nullability propagation, the validation rules, and the
partial-read I/O contract (an 8-bit search over the first 2048 of 4096
dimensions reads 16 of 64 plane streams).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature 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