Repository navigation
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: ClickHouse#112233
e42f47c to
b8fc861
Compare
|
Workflow [PR], commit [645bf1a] Summary: ❌
AI ReviewSummaryThis PR fixes the Findings
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 12/15 (80.00%) · Uncovered code |
|
The It is the known fleet-wide leak tracked in #114291 - the leaked cluster in this report is the same one described there: indirect leaks reaching This pull request only touches reference-vector extraction in Related: #114291 |
|
@rschu1ze could you take a look when you have a moment? This is a small change to reference-vector extraction in I could not add you as a reviewer directly (no write access on the repository), hence the mention. The only red check is |
Reword the type comments as requested, cover Array(BFloat16) reference vectors, and drop the claim that lossiness starts at a certain magnitude: integer-to-float conversion is lossy in general. Values the column's float type cannot represent exactly, such as 2^53 + 1 against Array(Float64) or an Array(UInt256) literal, are rejected by the distance function with NO_COMMON_TYPE and never reach the optimization, so the test pins down the largest integer reference vectors that do reach it instead.
The previous commit claimed such reference vectors cannot reach the optimization because the distance function resolves a common type first and fails with NO_COMMON_TYPE. That holds for `L2Distance` and `cosineDistance` only. `dotProduct` accepts mismatched argument types, so `ORDER BY dotProduct(vec, [9007199254740993, 2]) DESC` on an `Array(Float32)` column does reach it, with the element rounded down to 2^53. Test that path, including the extremal 64-bit values, and correct the comment about wider integers - `dotProduct` rejects them with ILLEGAL_TYPE_OF_ARGUMENT rather than NO_COMMON_TYPE.
| 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()); | ||
| /// Wider integers are left out: the distance functions reject them, so they never get here. | ||
| if (!which_data_type_array_nested.isFloat() && !which_data_type_array_nested.isNativeInteger()) |
There was a problem hiding this comment.
The new acceptance rule only covers the vector_similarity-index planner. The sibling ANN path in useVectorSearchWithQuantizedCodes.cpp:206-222 still accepts only Array(Float64/Float32/BFloat16) with Float64 Field elements, so ORDER BY L2Distance(vec, [1, 2]) ... SETTINGS vector_search_use_quantized_codes = 1 still falls back to the exact full-vector scan on Quantize(...)-coded tables. If the invariant here is that [1, 2] and [1.0, 2.0] denote the same reference vector, this extraction needs to be mirrored there too or the same performance cliff remains on the other supported ANN planner.
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, 16 s compile time in total, 7 of them have a recent master baseline. |
The comment on why wider integers are excluded was misleading: they are unsupported because such magnitudes are unrealistic for vector search and usearch does not support wide integers, not because the distance functions reject them. The dotProduct test block tested no relevant distance function. ClickHouse#114316
|
Thank for the help. |
|
@hamidr Can you please merge from |
|
Superseded by #115255 |
Closes: #112233
Related: #114291
The reference vector of an ANN query is extracted only when its array type is
Float64,Float32orBFloat16and every element is aFloat64field. An integer literal such as[1, 2]is typedArray(UInt8), sotryUseVectorSearchbails out and the query silently falls back to a brute-force scan over the whole table, although[1, 2]denotes the same point as[1.0, 2.0]andL2Distanceaccepts it.EXPLAIN indexes = 1shows novector_similarityentry and gives no hint why, so a one-character difference in a literal becomes a sharp performance cliff on large tables.Native integer arrays are now accepted as reference vectors and their elements are converted to
Float64, which is the type the reference vector is stored in anyway.Added
02354_vector_search_bug112233, covering unsigned, signed, mixed integer/float, and not-exactly-representable reference vectors, plus an equality check between the integer and float spellings of the same query.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Vector search queries now use the
vector_similarityindex when the reference vector is written as an integer array literal, e.g.ORDER BY L2Distance(vec, [1, 2]). Previously such queries silently fell back to a brute-force scan.