Repository navigation
Allow using integer reference vectors for approximate nearest neighbor search - #115255
Conversation
The reference vector of an ANN query is extracted only when its array type is Float64, Float32 or BFloat16 and every element is a Float64 field. An integer literal such as [1, 2] is typed Array(UInt8), so the optimization bailed out and the query silently fell back to a brute-force scan over the whole table, even though [1, 2] denotes the same point as [1.0, 2.0] and L2Distance accepts it. Nothing in EXPLAIN told the user why the index was gone, which turns a one-character difference in a literal into a sharp performance cliff. Accept native integer arrays as well and convert the elements to Float64, which is the type the reference vector is stored in anyway. Closes: #112233
|
Workflow [PR], commit [a66b020] Summary: ✅
AI ReviewSummaryThis PR teaches Findings
Final VerdictChanges requested: propagate the integer-literal handling to the LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 12/15 (80.00%) · Uncovered code |
| const auto * data_type_nested_bfloat16 = typeid_cast<const DataTypeBFloat16 *>(data_type_array_nested.get()); | ||
| if (data_type_nested_float64 == nullptr && data_type_nested_float32 == nullptr && data_type_nested_bfloat16 == nullptr) | ||
| WhichDataType which_data_type_array_nested(data_type_array->getNestedType()); | ||
| if (!which_data_type_array_nested.isFloat() && !which_data_type_array_nested.isNativeInteger()) |
There was a problem hiding this comment.
This widens the constant handling only for the vector-similarity-index path. The sibling ANN rewrite in src/Processors/QueryPlan/Optimizations/useVectorSearchWithQuantizedCodes.cpp still requires Array(Float32|Float64|BFloat16) and Field::Types::Float64, so ORDER BY L2Distance(vec, [1, 2]) LIMIT k still silently loses the approximate rewrite on Quantized(...) columns when vector_search_use_quantized_codes = 1.
Since the PR is framed as allowing integer reference vectors for ANN queries generally, I think this needs the same isNativeInteger + FieldVisitorConvertToNumber<Float64> handling there as well, or the scope/title/tests should be narrowed to the indexed-only path.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline. |
|
I reviewed the original PR already, it's fine! |
A query flagged in `report.html` was dropped when `all-query-metrics.tsv` had no `client_time` row for it, and a shard whose TSV could not be read dropped all of its flagged queries. With every flagged query dropped the run ended with "the comparison ran and was clean" - a non-empty CI report turned into an all-clear. The cause is deliberate on CI's side: `compare.sh` retracts a query from the TSV when its confirmation rerun demoted it, while the report still lists it under both "Changes in Performance" and "Unconfirmed Changes". On PR #115255 that is `round_down` #2 and #3 and `and_compare_chain_derived` #2. Those rows carry their own numbers, so they are now read from `report.html` and marked `*` in the report - CI's verdict on them was already in doubt, which makes them the most interesting queries to rerun, not the ones to discard. A flagged query readable from neither source is reported as unresolved, and if that leaves nothing to rerun the run fails instead of reporting a clean comparison. The commit under test drove only the report and binary lookup; the XMLs, `perf.py`, its `stat_threshold`, and the configs still came from the working tree. Query indices are positional and substitutions expand them, so a tree that differs from the measured commit silently reruns a different query - on a checkout one commit behind master, `and_compare_chain_derived.xml` has no query #2 at all while CI flagged exactly that, and a `refs/pull/<n>/merge` checkout is never the commit CI measured. `tests/performance`, `programs/server` and `tests/config/top_level_domains` are now extracted from that commit into the work dir and everything runs from there, fetching the commit when the clone lacks it. `--use-working-tree-tests` opts out for iterating on a local test. Verified: all six flagged queries of PR #115255 are now kept, the three the TSV retracts carrying the report's numbers and flagged as unconfirmed; a dry run of PR #112688 recovers `date_time_64` #5, which had been dropped the same way, and runs against the extracted tree. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115278&sha=baefff6dcc4dbb3201337a52b5ca54453fb34562&name_0=PR&name_1=Style%20check Pull request: #115278 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01GYYbBbrQpmi2zkYJ8LQw5Z
…to .git `report.py` writes cell values into `<td>` raw - it does not import `html`, let alone escape - so a query containing `<` and `>` puts them into the markup directly, and stripping tags inside a cell ate the text between them: `SELECT a < b AND c > d` became `SELECT a d`. That name is half the key of the historical-threshold lookup, so such a query missed its learned threshold and was judged by a weaker bar. 90 distinct queries measured in the last two weeks contain both characters. The name is now derived from the pinned test tree instead, where it has an exact source: perf.py builds `query_display_name` as `query_display(item)` trimmed to 1000 characters, which is what `--print-queries` prints and what reaches `query_metrics_v2`. Checked against CIDB, the derived name matches the recorded one byte for byte, including the leading newline the query text starts with. The report's query cell is no longer tag-stripped either, so the displayed text stays intact. Fetching a missing commit wrote to `.git` (`FETCH_HEAD` at least), which some sandboxes mount read-only - and a historical PR is exactly when the commit is missing. When the fetch into the clone fails, the commit is now fetched into a scratch repository under the work dir, which needs nothing from `.git` but the origin URL and yields the same archive. Verified: against a clone with a read-only `.git` and without the commit, the tree for PR #115255's head is still materialized - 558 perf XMLs plus `tests/benchmarks` and the configs - and the clone is left untouched, with no `FETCH_HEAD` created. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115278&sha=baefff6dcc4dbb3201337a52b5ca54453fb34562&name_0=PR&name_1=Style%20check Pull request: #115278 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01GYYbBbrQpmi2zkYJ8LQw5Z
Closes: #112233
This PR is a continuation of #114316. I get a permission denied error when pushing to the PR.
Courtesy to @hamidr
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Vector search queries can now use the vector similarity index when the reference vector is an integer array literal, e.g.
ORDER BY L2Distance(vec, [1, 2]). Previously, such queries silently fell back to a brute-force scan.