Repository navigation
docs(vector): one reference for vector function and distance semantics (inner_product = -dot) - #31896
Conversation
docs/sql/vector-distance-functions.md states, per function, the value, sign, range, result type, accepted vector types and edge cases (zero vector, NULL, dimension mismatch, overflow), and per index the op_type it serves, the metric it computes internally (L2 indexes rank by squared L2) and the value it returns. inner_product returns -dot by design: smaller is nearer. BVT vector_distance_semantics (CPU) and vector_distance_semantics_gpu (CAGRA, IVF-PQ) check every behavior the page states. The InnerProduct definitions point to the page, and four comments that contradicted the code are fixed. Fixes matrixorigin#31895 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Adds the column types each index builds on (CAGRA and IVF-PQ: vecf32 and vecf16 only) and the op_types accepted with each QUANTIZATION: int8/uint8 quantization is L2-only in every index (ip, cosine and l1 rejected), bf16 is rejected by CAGRA and IVF-PQ. On a vecint8/vecuint8 column IVF-FLAT serves every op_type and HNSW all but l1. The BVT cases cover each rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 646365b5a953397113f3cbfbc24a8a2623bd95c9
Assessment: request_changes
Negative inner product is correctly documented as intentional. Three factual corrections remain in the new reference; production behavior is unchanged.
Model: gpt-6-astra / xhigh
Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2
-
P2
docs/sql/vector-distance-functions.md:55: Calling distances on vecbf16, vecf16, vecint8 or vecuint8.
Impact: The blanket float32-rounding guarantee is false for these overloads and can mislead precision-sensitive comparisons.
Evidence: func_binary.go:15211-15232 resolves narrow kernels with float64 results and applies math.Sqrt without RoundDistanceToElemDomain. Thus narrow l2_distance([1,1],[0,0]) follows sqrt(2)=1.4142135623730951, not 1.4142135381698608. Document precision by execution/type family and add a non-integral narrow-distance assertion. -
P2
docs/sql/vector-distance-functions.md:147: An index-served query uses lossy QUANTIZATION, such as IVF-FLAT QUANTIZATION 'bf16'.
Impact: The reference promises the original scalar value and describes only float32 rounding differences, although quantization can substantially change scores.
Evidence: ivfflat/plugin/compile/compile.go:505-541 casts stored entries; ivfflat/search.go:580-585 also quantizes the query; scoreFromQuantized does not reconstruct discarded precision. For example, [1.001,0] and [1.002,0] both encode as [1,0] in bf16, yielding zero indexed distance despite a positive source distance. apply_indices_ivfflat.go:998-1014 substitutes that score into SELECT. Qualify scalar equivalence for unquantized storage and document quantization error separately. -
P3
docs/sql/vector-distance-functions.md:64: cosine_similarity receives differently sized narrow vectors.
Impact: The documented error category and message are incorrect for this function.
Evidence: CosineSimilarityArrayViaF32 delegates through arrayDistanceViaF32 to moarray.CosineSimilarity, whose external.go:282-283 dimension guard returns 'invalid input: vector ops between different dimensions ...', including narrow inputs. Exempt cosine_similarity from this bullet and add a narrow mismatch assertion.
Validation:
-
Complete 14-file delta and relevant consumers reviewed; production hunks contain comments only.
-
Static/arithmetic audit passed: 89 numeric golden cells and ordered alignment of 127 CPU and 47 GPU SQL statements. Receipt checks/1793370365880755660-4.json; log vector-reference-audit.log.
-
git diff --check passed; receipt checks/1793370495439693232-3.json.
-
Discussion coverage 2/2, frozen file hashes, retained evidence and unchanged source verified; receipt checks/1793370495487943005-3.json; log final-audit.log.
Limitations:
-
No independent SQL, Go/native or GPU execution. Counterexamples are established from source and arithmetic.
-
Frozen evidence reports successful CPU CI and author-reported CPU/GPU BVT passes, but contains no retained per-case execution logs.
-
The initial arithmetic probe used an insufficient float32 boundary; its failed receipt and source were retained, then superseded by the corrected passing probe.
…larity mismatch The float32 rounding rule holds for vecf32/vecf64 only: on the narrow types l2_distance and cosine_distance return an unrounded float64, while an index on a narrow column returns a float32 value. An index with QUANTIZATION scores the quantized vectors, not the stored column. cosine_similarity reports a dimension mismatch as invalid input on every type. BVT cases check each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@XuPeng-SH All three mo-bot findings are addressed in 849c61a. I reproduced each one on a running instance first. This is docs and BVT only; no code changed.
Validation: 🤖 Generated with Claude Code |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 849c61a144e9c4c0430de99b6c84316abe7f8ea4
Assessment: approve
All three prior findings are resolved: narrow-vector precision, quantization effects, and cosine_similarity dimension errors. The complete documentation, comment, and BVT delta has no actionable unresolved findings.
Model: gpt-6-astra / xhigh
Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2
Validation:
-
Reviewed all 14 changed files, relevant implementations, six discussion entries, and five linked issues.
-
Static audit passed: 143 CPU and 47 GPU statements align with expected results; 102 numeric cells independently checked. Log: vector-reference-audit.log; receipt: checks/1793470408912615462-4.json.
-
git diff --check passed; receipt: checks/1793470492474169143-4.json.
-
Discussion coverage, frozen source identity, unchanged checkout, and retained evidence verified; log: final-audit.log; receipt: checks/1793470510324372275-4.json.
Limitations:
- No independent SQL, Go/native, or GPU execution. Frozen evidence reports successful CPU CI and author-reported CPU/GPU BVT comparisons, without retained per-case execution logs.
🚫 Left the queue1 min in the queue, with no time running CI. So far
Reason The pull request can't be updated
Hint You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Tick the box to put this pull request back in the merge queue (same as
Times in UTC · dashboard · how the merge queue works |
…ance reference docs/sql/vector-distance-functions.md (matrixorigin#31896) covered six vector types. It now covers vecf8 (MXFP8) and vecf4 (NVFP4): their block layout and quantization, which argument types they pair with, result precision (rounded into the float32 domain except l2_distance_sq), the dimension mismatch error, the result type of every function and operator (subvector/abs/arithmetic return vecf32, sqrt vecf64, normalize_l2 and the copying functions the argument's type), the casts they accept, vecblock_json/vecblock_binary, and that no index or key accepts them. Each statement is checked in vector_distance_semantics.sql; the CAGRA and IVF-PQ rejections are in the GPU case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…vecf4 vector columns (#20567) (#29554) ## What type of PR is this? - [x] API-change - [x] BUG - [x] Improvement - [x] Documentation - [x] Feature - [x] Test and CI - [x] Code Refactoring ## Which issue(s) this PR fixes: Related to #20567. ## What this PR does / why we need it: Introduce scalar `bf16`, `float16`, `float8` (E4M3), `float4` (E2M1), and block-scaled vector columns `vecf8(N)` / `vecf4(N)`, with shared codecs, float32 expression promotion, casts, comparison, storage, import/export and MySQL transport. Existing key/domain restrictions and canonical finite-value contracts remain enforced. `VECTOR_MATMUL` retains bounded configuration/accounting, state merging and CPU execution; GPU execution keeps its documented numerical and device-admission limits. Designs: `docs/design/20260929-low-precision-scalar-floats.md` and `docs/design/20260930-low-precision-vector-storage.md`. SQL reference for the vector types: `docs/sql/vector-distance-functions.md`. ### Rebase and review corrections Rebased the exact cumulative feature tree onto main `3c07fac240311d6f2b706674614ed6034e97ff79`. The original 159 commits, including 32 merges, are preserved in an archive ref and exact raw-object manifest; author attribution is retained in the snapshot commit. All 48 overlapping paths and nine conflicts were reconciled; main-only files are preserved. - Narrow scalar `RowToString` now formats widened numeric values, rather than integer backing codes. This repairs checkpoint SQL-LOAD CSV round trips (for example, `1.5` must remain `1.5`). Normal/constant/NULL handling uses the shared vector owner; raw serialization and ordinary scalar cases are unchanged. - Block-scaled ODKU keeps byte-identical comparison fast, then uses the existing decoded-value comparator. Differently encoded equal cells remain no-ops: no unnecessary write, changed-row count or implicit ON UPDATE change. UPDATE's changed-row predicate (also the guard for automatic ON UPDATE expressions) compares vecf8/vecf4 cells with `<=>` directly, without casting both sides to vecf32. - `ALTER TABLE ... ADD COLUMN c <bf16|float16|float8|float4> NOT NULL` without a `DEFAULT` backfills existing rows with `0`, as `FLOAT` does (COPY and default algorithms); the implicit NOT NULL value previously fell through to `null`. - Main's mixed JSON/numeric comparison covers bf16/float16/float8/float4 as it covers `FLOAT`: a JSON number is rounded and range-checked as CAST to the type does it, and a JSON string, object or array never equals a number (`'"1.5"'` is not `1.5`). Before this, JSON compared with these types kept the old cast-to-float path. - Where `FLOAT` works, bf16/float16/float8/float4 now behave the same (found by running each SQL feature on `FLOAT` and on the new types): a user variable holding one of these values computes in DOUBLE; a constant expression compared with the column (`a = ABS(-0.1)`) is folded and rounded as a literal is; hex and bit literals are unsigned integers; JSON, YEAR and ENUM cast as they cast to `FLOAT`; text that is not a number converts to its numeric prefix with `FLOAT`'s warning in MySQL mode (values outside the type's finite range still error); `SERIAL` encodes the stored bits in tuple elements of their own type, ordered as the values, and `SERIAL_EXTRACT` returns them; `INFORMATION_SCHEMA.COLUMNS.NUMERIC_PRECISION` is the significand bits (8/11/4/2). - `TestTypeSwitchFamilies` also checks `==`/`!=` chains and `[]types.T`/`map[types.T]` literals that name part of a type family; the existing sites were reviewed and baselined. - An empty string or empty `BLOB` is not a vector: a cast, `INSERT … VALUES`, `INSERT … SELECT`, a prepared parameter or an `UPDATE` with it is an error for every vector type, as `''` is for an `INT` column (before, `vecf32` errored on `VALUES ('')` but stored NULL for `INSERT … SELECT ''` and a prepared `''`; vecf8/vecf4 stored NULL on every path). NULL stays NULL; `LOAD` still reads an empty field as NULL. - Upgrade and function identities: MatrixOne upgrades by full-cluster shutdown only (`.agents/skills/mo-dev/references/upgrade-compatibility.md`, main #31287), so the types and functions take no MORPC version and no capability gate; the branch's earlier low-precision protocol gate (remote placement, execution-stream confirmation, persisted-expression floor, column-authoring fence) is removed, and main's existing gates are unchanged. The types are additive persisted state: data written before them reads as before (merges `0bf7ad2bf8`, `3b5ebd55d3`, `0bce000fa2`, `334d14ae91`, `8841673f3e`, `64573711a1`, `ba4f725d19`, `4d5938c30a`, `56ac42ed39`, `9cf7b69221`, `1543470717`, `9a51b315ec` and `6943941198`, main `24c1ac897b`). VECTOR_MATMUL, VECBLOCK_JSON and VECBLOCK_BINARY take the next free function ids after main's, and `aggexec.AggIdOfVectorMatmul` follows VECTOR_MATMUL; main's function ids are unchanged, and only the end marker advances. Main's TIMESTAMPADD SECOND float switch is tagged `typeswitch:partial`: bf16/float16/float8/float4 counts widen to float32 at resolution. Main's in-memory sort-key filter switch (`encodeMemSortKeySpecs`) is tagged `typeswitch:partial`: the four types are rejected as primary and cluster keys. Main's quantileExactWeighted casts these arguments to FLOAT when it resolves, so its switches are tagged; main's indicator window kernels and local ranks read them as float32, which holds them exactly, and return what FLOAT returns. Text converts as main's FLOAT conversion (#31191) does: radix text is its integer value, other text its decimal prefix (`'inf'`/`'nan'` are 0), and truncated text in a strict INSERT/UPDATE is an error. Main now escapes every CSV export value in `formatOutputString`; the vecf8/vecf4 export case passes the raw text instead of escaping it a second time. Main moved the AVX-512 metric loops into `//go:noinline` helpers; the branch's VZEROUPPER clear (`archsimd.ClearAVXUpperBits`) is in each helper. - VECTOR_MATMUL compaction and merge sort one `q` × `topk` index array, allocated through the aggregate's allocation account and counted by `Size`, instead of maps on the Go heap (review P2). Merge preflight allocates that array for every merge target, so a merge that passes preflight cannot fail on it in `BatchMerge` (review P2). - The tuple decoder decodes a bf16/float16/float8/float4 zero of either sign as +0 and rejects NaN and infinite elements, so SERIAL_EXTRACT of a hand-built tuple cannot store -0 or NaN (review P2). - VECTOR_MATMUL fill and flush stay inside the allocation account: a string id is offered from the input vector and a numeric or UUID id from a fixed 36-byte buffer, the CPU scorer reuses one operand per executor, and Flush writes each group's ByteJson straight into the accounted result vector (no JSON text, no reparse) with one accounted `topk` sort scratch; its configuration parse is admitted before it allocates (the account is attached first and a non-allocating bound reserved); a fractional or exponent-form distance is encoded without the integer parsers' error allocation (review P2). - Exact block-cell text keeps a stored negative-zero element: `vecblock_json` prints `-0`, and parsing it now restores the negative-zero code (E4M3 `0x80`, E2M1 `0x08`) instead of code 0, so export/reload no longer changes cell bytes. JSONL `LOAD` writes an object value back with its original number lexemes, so a `-0` element reloads to its negative-zero code in both the object and array formats. The quantizing encoder still stores a computed zero as code 0. A number in the exact text must denote its float32 value without rounding (the exact value, or its shortest float32 or float64 text, in any notation); `1.00000001`, which float32 parsing rounds to `1`, is rejected. - bf16/float16 range: a value just above the largest finite value (`65505` for float16) is out of range although it rounds back to the maximum. Casts and writes reject it and comparisons with it stay wide; the same applies to the vecbf16/vecf16 text parser, the vector narrowing cast and `VECTOR_MATMUL` queries. A bf16 text or wider source is checked by its float32 value, so the printed maximum `3.3895314e+38` loads back. Comparison narrowing of a literal or prepared parameter uses the same admission rule as CAST, so that printed maximum also narrows and matches the row it was inserted as. Narrowing applies only when the other operand is a low-precision column, for literals and prepared parameters alike (`CAST(1.1 AS FLOAT4) = 1.1` and `= ?` both compare wide), and a decimal literal of any width, including a numeral beyond `DECIMAL(38)`, narrows by its exact value. - `VECTOR_MATMUL` rejects a JSON `null` query coordinate or query (`query i: coordinate j is null`) instead of reading it as 0, for every supported column type. A supplied options argument that is empty text or `NULL` (including a NULL user variable) is an error rather than the defaults, and a `NULL` queries argument is an error; an omitted options argument still selects the defaults. - Main's exponentially weighted window statistics (`ewmMean`/`ewmVar`/`ewmStd`/`ewmCov`/`ewmCorr`, #31941) take bf16/float16/float8/float4 samples, alpha/half-life, policy arguments and event-time `ORDER BY` keys as they take `FLOAT`, and return what `FLOAT` returns; main's parallel UNION ALL projection admits these types as IFF conditions as `IffConditionTruthyAt` reads them. Main's new fixed-key hash fast path copies their bytes: a zero of either sign is stored as +0, so the bytes are the key. The two EWM switches that read `plan.Literal` are tagged `typeswitch:partial` (no literal carries these types). Main #31488 removed `pkg/iscp` `copyBytes`; the vecf8/vecf4 row extraction uses `CloneBytesAt` as main's other cases do (merge `cd4d31b4f3`). - `docs/sql/vector-distance-functions.md` (main #31896) covers vecf8/vecf4: the block layout and quantization, the argument types each distance pairs with (vecf8, vecf4, vecf32, vecf64; not the other narrow types), precision (rounded into the float32 domain except `l2_distance_sq`), the dimension-mismatch error, every function's result type (`subvector`/`abs`/arithmetic return vecf32, `sqrt` vecf64, `normalize_l2` and the copying functions the argument's type), the accepted casts (text, vecf32, vecf8↔vecf4), `vecblock_json`/`vecblock_binary`, and that no index or key accepts the types. Each statement has a line in `cases/vector/vector_distance_semantics.sql`; the CAGRA/IVF-PQ rejections are in `gpu_cases/vector/vector_distance_semantics_gpu.sql` (`0b32a9a9f0`). - Shared authoring, feature collection, placement, destination, actual execution stream and receiver checks compose requirements with `max`. Main's charset migration, COPY strict assignment, diagnostics/folding and prepared exact-source behavior are retained. The 16-byte Type layout and existing protobuf fields are unchanged. ### Validation - Local CPU native compilation succeeds through the repository provenance owner; verified thirdparty artifacts were copied into task-owned storage, then CGo rebuilt once. - Focused normal checks pass (9 roots/119 including subtests), along with complete types/vector/keycodec/metric/aggexec owner coverage (1,289 roots/5,555 nodes; the previously covered RowToString test is reused). - Selected integration checks pass across 30 CPU packages (147 roots/569 nodes), including export/LOAD, parser/planner/prepared binding, storage/WAL/zonemap and actual SQL ODKU behavior. - One race pass succeeds for the five owners and the integration closure (155 integration roots/682 nodes). Two allocation-measurement tests intentionally skip under race; their normal-mode passes are retained. - Configured incremental SCA covers 45 CPU packages derived from the delivery diff and build constraints; golangci-lint2.14 reports zero issues. The only new molint advisory, an unsafe import used for a size calculation, is removed using standard type metadata at configuration construction. Existing VECTOR_MATMUL tests pass normally and with race after cleanup; owning-package SCA again reports zero issues. The remaining 47 advisory locations map to unchanged base code. - Parser reproduction, function-identity/main-only preservation, Type-layout comparison, formatting and diff checks pass. Generated metric-kernel consistency is exercised by owner tests. - Required gpt-6.1-sol/xhigh design, complete review and final cleanup review pass. Commands, fingerprints, terminal receipts and model session IDs are retained in the task record. Go1.27.1/darwin-arm64, repository CGo runner. The fixes add no new retained state, locks or execution framework. The size query runs only during block-scaled matmul configuration; decoded equality's extra linear work is limited to differently encoded block vectors. Ordinary scalar DML paths retain their previous code. Author run at `e9fc0a159e` (after merging main `e033d4a587`, GPU build): every `pkg/` test package compiles; the affected Go packages and `TestTypeSwitchFamilies` pass; golangci-lint v2.14.0 reports no issues in the changed packages; BVT `-m run` 0 failures: `cases/dtype` 8856 (32 ignored), `cases/array` 1501/1501, `cases/vector` 3460 (2 ignored), `cases/load_data` 1607 (5 ignored), `cases/function` 22490 (150 ignored), `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `eebad1d1ac` (merge-preflight fix, GPU build): `pkg/sql/colexec/aggexec` and `pkg/sql/colexec/group` pass; the new and related tests pass `-race -count=20`; golangci-lint reports no issues; BVT `-m run` 0 failures: `cases/vector/vector_matmul.sql` 109/109, `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `6943941198` (after merging main `24c1ac897b`, clean GPU rebuild): `TestTemporaryTablePhysicalNameIsSessionScoped` 5/5 (the CI failure on `eebad1d1ac` was the ISCP fixture race main fixed in #31288), `TestTypeSwitchFamilies`, `pkg/container/types`, `pkg/sql/plan/function`, `pkg/sql/colexec/aggexec` and `pkg/sql/colexec/group` pass; every `pkg/` test package compiles; BVT `-m run` 0 failures: `cases/dtype` 8856 (32 ignored), `cases/array` 1501/1501, `cases/vector` 3460 (2 ignored), `cases/load_data` 1607 (5 ignored), `cases/function` 22490 (150 ignored), `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `64b29a2034` (tuple-decoder fix, GPU build): `pkg/container/types` (with `TestTypeSwitchFamilies`), `pkg/sql/plan/function` and `pkg/sql/colexec/...` pass; golangci-lint reports no issues; BVT `-m run` 0 failures: `cases/dtype` 8871 (32 ignored), `cases/function` 22490 (150 ignored). Author run at `c22e8a35d4` (aggregate memory audit, GPU build): `pkg/sql/colexec/aggexec` (with and without the `gpu` tag) and `pkg/sql/colexec/group` pass; the new and accounted fill/merge tests pass `-race -count=10`; golangci-lint reports no issues; BVT `-m run` 0 failures: `cases/vector/vector_matmul.sql` 109/109, `gpu_cases/vector/vector_matmul_gpu.sql` 71/71, `cases/vector` 3460 (2 ignored), `cases/array` 1501/1501. Author run at `c6480649e5` (fractional-distance flush allocation): `pkg/sql/colexec/aggexec` (with and without the `gpu` tag, and under `-race`) and `pkg/sql/colexec/group` pass; the flush allocation tests pass `-race -count=10`; golangci-lint reports no issues; BVT `-m run` 0 failures: `cases/vector/vector_matmul.sql` 109/109, `gpu_cases/vector/vector_matmul_gpu.sql` 71/71, `cases/vector` 3460 (2 ignored). Author run at `af8bbc4f60` (merge of main `802376360c`, no conflicts; function ids unchanged): `pkg/container/types` (incl. `TestTypeSwitchFamilies`), `pkg/sql/plan/function`, `pkg/sql/plan`, `pkg/sql/colexec/aggexec`, `pkg/sql/colexec/group` and `pkg/vectorindex/hnsw/...` pass; BVT `-m run` 0 failures: `cases/dtype` 8895 (32 ignored), `cases/function` 22527 (150 ignored), `cases/vector` 3499 (2 ignored), `gpu_cases/vector/vector_matmul_gpu.sql` 71/71, `pessimistic_transaction/vector/vector_hnsw_delete_insert.sql` 56/56 ×3. Author run at `eead4d0574` (merge of main `d4ffbae43d`; `mysql_sql.go` regenerated from the merged `mysql_sql.y`, 0 grammar conflicts; function ids unchanged): `pkg/container/types` (incl. `TestTypeSwitchFamilies`), `pkg/sql/plan`, `pkg/sql/plan/function`, `pkg/sql/colexec/aggexec` and `pkg/sql/parsers/...` pass; BVT `-m run` 0 failures: `cases/dtype` 8895 (32 ignored), `cases/function` 22550 (150 ignored), `cases/vector` 3499 (2 ignored), `cases/dml/insert` 3090 (22 ignored), `cases/load_data` 1609 (5 ignored), `pessimistic_transaction/vector/vector_hnsw_delete_insert.sql` 58/58, `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `d57e5e560d` (SERIAL_EXTRACT validates vecf8/vecf4 cells, review P2): `pkg/sql/plan/function` and `pkg/container/types` pass; `TestSerialExtractBlockScaledCell` fails on all 12 invalid-input subtests without the check; golangci-lint reports no issues; BVT `-m run` 0 failures: `cases/dtype` 8906 (32 ignored; `dtype/vecblock.sql` 253/253 twice), `cases/function` 22550 (150 ignored), `cases/vector` 3499 (2 ignored). Author run at `4ecd752f61` (merges of main `1fd12d526e` and `7e0c9d94fc`; `array_str.go` conflict resolved keeping exact bf16/f16 element rounding with main's context-aware errors; `mysql_sql.go` regenerated with goyacc, 0 conflicts; `7b55465b2c` classifies the new types in main's sort-rollup type switch, with a ROLLUP BVT under `SORT`/`HASH`/`COST`): `pkg/container/types` (incl. `TestTypeSwitchFamilies`), `pkg/sql/plan`, `pkg/sql/plan/function`, `pkg/sql/colexec/aggexec`, `pkg/vectorindex/...` (metric also with `GOEXPERIMENT=simd`) and `pkg/sql/parsers/...` pass; BVT `-m run` on a fresh data dir: `cases/dtype` 8916 (32 ignored), `cases/function` 22597 (150 ignored), `cases/vector` 3498 + 1 flake (2 ignored; `vector_ivf_membership.sql` row 163 read `table_stats` right after `mo_ctl` flush, 160/160 on 3 reruns), `cases/array` 1501, `cases/hint` 662, `cases/load_data` 1609 (5 ignored), `cases/fulltext` 1978 (3 ignored), `cases/auto_increment` 924, `cases/ddl` 8825 (168 ignored). Author run at `410761af13` (merge of main `23488e1eb2`: conflicts in `export.go`, `func_builtin_jq.go`, `func_cast_test.go` resolved onto main's new helpers, `mysql_sql.go` regenerated with goyacc, usearch rebuilt for main's new tarball; `a3a9dbf506` classifies the new types in seven new main type switches (float text formatting counts the low-precision types; six tagged partial with reasons); `410761af13` follows main's MySQL float text in the low-precision BVTs, matching `FLOAT`/`DOUBLE`/`vecf32`, and checks the bf16 maximum's new six-digit text loads back): `pkg/container/types` (incl. `TestTypeSwitchFamilies`), `pkg/sql/plan`, `pkg/sql/plan/function`, `pkg/sql/colexec/{aggexec,window,table_function,external}`, `pkg/vectorindex/...` (metric also with `GOEXPERIMENT=simd`) and `pkg/sql/parsers/...` pass; golangci-lint reports no issues; BVT `-m run` on a fresh data dir: `cases/dtype` 8916 (32 ignored; `lowprec_float.sql` 431/431, `vecblock.sql` 253/253 after the text update), `cases/function` 22669 (150 ignored), `cases/vector` 3496 + 3 flakes (2 ignored; `vector_ivf_membership.sql` `table_stats` right after `mo_ctl` flush, 160/160 on 3 reruns), `cases/array` 1501, `cases/hint` 671, `cases/load_data` 1609 (5 ignored), `cases/fulltext` 2009 (3 ignored), `cases/window` 2792 (7 ignored), `cases/auto_increment` 924, `cases/ddl` 8825 (168 ignored), `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `ecd90a635f` (review fixes: vecf8/vecf4 sort compares cells in place; hash-key preflight sizes the canonical vecf8/vecf4 key; VECTOR_MATMUL configuration admitted before parsing; volatile/real-time configuration rejected; JSON options accepted): `pkg/sort`, `pkg/common/hashmap/...`, `pkg/sql/colexec/aggexec` (with and without the `gpu` tag), `pkg/sql/colexec/group`, `pkg/sql/plan`, `pkg/sql/plan/function`, `pkg/sql/compile` and `pkg/container/types` pass; admission, shared-configuration and sort tests pass `-race -count=10`; golangci-lint reports no issues; BVT `-m run`: `cases/dtype` 8917 (32 ignored), `cases/function` 22668 + 1 timing flake (`func_datetime_now.test`, 50/50 on rerun), `cases/vector` 3505 (2 ignored), `cases/array` 1501, `cases/window` 2792 (7 ignored), `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `e38b4def66` (CI fix for `TestVectorMatmulParseBoundCoversParse`: JSON queries are decoded once, the row scan finds a null query or coordinate, and the parse bound carries a 2x margin, at least 2.89x over the measured allocation): `pkg/sql/colexec/aggexec` passes 5 times in a row, with the `gpu` tag, under `-race`, and without the simd experiment with coverage. Author run at `96cb007bc9` (review P2: the admission bound reads neither options nor query values; options and JSON queries are parsed in one `sonic/ast` SAX pass, query values rounded once from their text to float32): `pkg/sql/colexec/aggexec` passes 3 times in a row and with the `gpu` tag; the options, rounding, scan and admission tests pass `-race -count=5`; golangci-lint reports no issues; BVT `-m run`: `vector/vector_matmul.sql` 119/119, `dtype/vecblock.sql` 253/253, `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `8bc61f7f3f` (merge of main `b01e952ad1`, `partition.go` keeps main's JSON partitioning and the new types' cases; self-review fixes: the JSON row scan follows at most 8 levels, options and vecblock queries are checked with `encoding/json.Valid` (nesting limit, trailing text), duplicate-key error text, vecblock and binary bound terms, limit checks before options with or without an account, every aggregate factory attaches the account before the configuration): `pkg/container/types` (incl. `TestTypeSwitchFamilies`), `pkg/sql/colexec/aggexec` (with and without the `gpu` tag), `group`, `window`, `timewin`, `compile`, `hashmap`, `function`, `partition`, `sort`, `plan` and the parsers pass; the new and affected tests pass adaptive `-race -count` (N 25 to 100) and the owning packages once under `-race`; golangci-lint reports no issues; BVT `-m run` 0 failures: `cases/vector` 3509 (2 ignored), `cases/dtype` 8991 (32 ignored), `cases/function` 22708 (150 ignored), `cases/window` 2826 (7 ignored), `cases/array` 1501, `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `6e2a82ae52` (sonic v1.15.5, whose native decoder rounds float32 twice (bytedance/sonic#884), so float32 HNSW CDC batches decode with `encoding/json`; vecblock JSON queries validated before their elements are collected; self-review fixes): `pkg/sql/colexec/aggexec` (with and without the `gpu` tag, once under `-race`), `pkg/vectorindex`, `pkg/vectorindex/hnsw/...`, `pkg/iscp`, `pkg/sql/colexec/table_function`, `pkg/sql/plan`, `pkg/catalog` and `pkg/fulltext2/...` pass; new tests pass adaptive `-race -count`; golangci-lint and molint report no issues; BVT `-m run` 0 failures: `cases/vector` 3509 (2 ignored), `pessimistic_transaction/vector` 927 (42 ignored), `cases/dtype` 8991 (32 ignored), `cases/fulltext` 2009 (3 ignored), `pessimistic_transaction/fulltext2` 932/932, `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `daef3c9f06` (GROUP_CONCAT selects its accounted DISTINCT mode from both `SetAllocationAccount` and `SetExtraInformation`, so the Group factory's account-first order keeps `DISTINCT ... ORDER BY` on the ordered representation; regression `TestGroupConcatAccountedDistinctModeIndependentOfOrder` fails without the fix): `pkg/sql/colexec/aggexec` (also once under `-race`), `group`, `window` and `timewin` pass; golangci-lint reports no issues; BVT `-m run` 0 failures: `cases/function` 22708 (150 ignored), `cases/vector/vector_matmul.sql` 119/119. Author run at `820f57e2d5` (merge of main `950e548b5a`; full-PR review fixes: IF/IFF/CASE/COALESCE mixing a low-precision float with another type resolve as with `float32`, Parquet export writes vecf8/vecf4 as the exact cell text, the low-precision scalars format as numbers in tuple and debug printers, `subvector` on vecf8/vecf4 returns `vecf32`): `pkg/container/types`, `pkg/sql/plan/function`, `pkg/sql/plan`, `pkg/frontend`, `pkg/sql/colexec/aggexec`, `group`, `tae/common`, `tae/index` and `logtailreplay` pass; golangci-lint reports no issues; BVT `-m run` 0 failures: `cases/dtype` 8997 (32 ignored), `cases/function` 22924 (150 ignored), `cases/array` 1517, `cases/vector` 3531 (2 ignored); at the merge `ee08413830`, `cases/window` 2826 (7 ignored) and `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `c592c6ac3b` (merge of main `d39d8a4034`: main's DECIMAL UNSIGNED admission took the next function ids, so `vector_matmul`, `vecblock_json` and `vecblock_binary` take the ones after it; DECIMAL UNSIGNED admits bf16/float16/float8/float4 as it admits FLOAT; `subvector` on vecf8/vecf4 documented as returning `vecf32` equal to `subvector` over the `vecf32` cast): `pkg/container/types` (incl. `TestTypeSwitchFamilies`), `pkg/container/vector`, `pkg/sql/plan/function`, `pkg/sql/plan`, `pkg/sql/colexec/aggexec`, `pkg/tools/checkpointtool` and the parsers pass; golangci-lint reports no issues; BVT `-m run` 0 failures: `cases/dtype` 9159 (32 ignored), `cases/function` 22924 (150 ignored), `cases/vector` 3531 (2 ignored), `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `42eeeb2a77` (merge of main `c8534cc3e2`: main kept the previous IF/CASE checkers as the native-mode copies and the branch's low-precision CASE handling had merged into the native copy only, so both modes now carry it and the conditional tests run in both modes; main's new TOP pruning excludes vecf8/vecf4 as it excludes the other float arrays; GPU-tagged static analysis): `TestTypeSwitchFamilies`, `pkg/container/types`, `pkg/common/hashmap/...`, `pkg/sql/util`, `pkg/sql/colexec/top`, `aggexec`, `group`, `pkg/sql/plan/function`, `pkg/sql/plan` and `pkg/vectorindex/...` pass in the GPU build; BVT `-m run` 0 failures: `cases/dtype` 9438 (32 ignored), `cases/function` 22976 (150 ignored), `cases/vector` 3531 (2 ignored), `cases/array` 1517, `cases/window` 2838 (7 ignored), `gpu_cases/vector/vector_matmul_gpu.sql` 71/71, `cases/vector/vector_matmul.sql` 119/119. **GPU-tagged static analysis** (CI's `static-check` passes no build tag, so `//go:build gpu` files are not analyzed there): the configured analyzers with the GPU include paths of `MO_CL_CUDA=1` and the `gpu` tag, over `./...` — `molint check -mod=readonly -tags gpu ./...` and `golangci-lint run -c .golangci.yml --build-tags gpu ./...` (golangci-lint v2.14.0). On the merge they reported two findings in files this PR adds: `checkunsafe` in `pkg/cuvs/blockscaled_matmul.go` and `prealloc` in `pkg/cuvs/blockscaled_matmul_test.go`; `42eeeb2a77` passes the C pointers through `util.UnsafePointer` and preallocates. On `42eeeb2a77` the findings equal those of the same commands on main `c8534cc3e2`: 16 molint `checkunsafe` in GPU files this PR does not change (`pkg/cuvs/{adhoc,brute_force,cagra,device_memory,distance,helper,helper_test,ivf_flat,ivf_pq,kmeans}.go`, `table_function/{filter_helper,ivfpq_create}_gpu.go`, `{cagra,ivfpq}/probe_gpu.go`, `{cagra,ivfpq}/plugin/search/search_gpu.go`) and 1 golangci `ineffassign` in `pkg/cuvs/search_float_test.go` (unchanged); 0 new. Author run at `dbfa3ad95e` (GPU-tagged static-analysis findings fixed, including those main already had: the GPU table functions and the CAGRA/IVF-PQ search and probe files use `util.UnsafeToBytes`, `util.UnsafeSliceCast` and `util.UnsafeSizeOf`; `pkg/cuvs` no longer imports `unsafe`: its cgo calls pass pointers through `util.UnsafePointer`, and the pinned host-memory API and the VRAM reservation token hold the C pointer as `*byte`; a `pkg/cuvs` test no longer assigns a value it overwrites): `molint check -mod=readonly -tags gpu ./...` (the version `Makefile` pins) and `golangci-lint run -c .golangci.yml --build-tags gpu ./...` (v2.14.0), with the GPU include paths of `MO_CL_CUDA=1`, report 0 findings; GPU unit tests pass for `pkg/cuvs/...`, `pkg/vectorindex/...`, `pkg/sql/colexec/table_function` and `pkg/sql/colexec/aggexec`; BVT `-m run` of `test/distributed/gpu_cases` passes 1959/1959 (64 files). Author run at `f5fad15240` (merge of main `c42cf40214`: main's `MO_INDEX_SUB_PART` took the next function id, so `vector_matmul`, `vecblock_json` and `vecblock_binary` move to the ids after it; main's other commits do not touch GPU-tagged files or `pkg/cuvs`, so the GPU-tagged static analysis of `dbfa3ad95e` still applies): `pkg/container/types` (incl. `TestTypeSwitchFamilies`), `pkg/container/vector`, `pkg/sql/plan/function`, `pkg/sql/plan`, `pkg/sql/colexec/aggexec` and `group` pass; BVT `-m run` 0 failures: `cases/vector` 3531 (2 ignored), `cases/dtype` 9438 (32 ignored), `cases/function` 22976 (150 ignored), `gpu_cases/vector/vector_matmul_gpu.sql` 71/71. Author run at `63b315eec7` (main's new `parquet_vector_nonfinite.sql` expects main's message for a `vecf16`/`vecbf16` element above the type's range; this PR rejects such an element as out of range, naming the type and the input value, as the scalar `float16`/`bf16` types do, so the expected result is updated; both inserts are still rejected): `cases/load_data` BVT `-m run` 1730 (5 ignored), 0 failures; the other cases with that message (`dtype/vecblock`, `vector/vector_nonfinite_conversion`, `array/array_nonfinite`) pass. Author run at `0b32a9a9f0` (merge `cd4d31b4f3` of main `0df8dded57`: main's EWM window functions took the next function ids, so `vector_matmul`, `vecblock_json` and `vecblock_binary` move to the ids after them, and `aggexec.AggIdOfVectorMatmul` follows; `mysql_sql.go` regenerated from the merged `mysql_sql.y`; then the vecf8/vecf4 reference doc `0b32a9a9f0`; GPU build): `pkg/container/types` (incl. `TestTypeSwitchFamilies`), `pkg/sql/plan/function` (incl. `TestAggregateExecutorIDs`), `pkg/sql/colexec/aggexec`, `pkg/sql/plan`, `pkg/sql/compile`, `pkg/sql/colexec/window/...`, `pkg/common/hashmap`, `pkg/iscp` and the parsers pass; `go vet` of `./pkg/... ./cmd/...` (gpu tag) reports nothing; BVT `-m run` 0 failures: `cases/vector` 3721 (2 ignored), `cases/dtype` 9476 (32 ignored), `cases/window` 3222 (7 ignored), `cases/function` 23144 (150 ignored), `gpu_cases/vector/vector_matmul_gpu.sql` 71/71, `gpu_cases/vector/vector_distance_semantics_gpu.sql` 50/50. In the `cases/function` directory run, `func_datetime_now.test` row 122 (`timestampdiff` of two `now()` values around `sleep(1)` ≥ 1 s) returned 0 in an overnight run where `func_math_floor.test` took 40793 s and `window.sql` 18395 s; rerun of the three files: 50/50 (6.9 s), 95/95 (3.1 s) and 1106/1106 (55 s). Author run at `1543470717` (after merging main `be66367687`, GPU build): the affected Go packages and `TestTypeSwitchFamilies` pass; every `pkg/` test package compiles; BVT `-m run` 0 failures: `cases/dtype` 8738 (32 ignored), `cases/array` 1501/1501, `cases/vector` 3460 (2 ignored), `cases/load_data` 1607 (5 ignored), `cases/function` 22196 (150 ignored), and the case file the merge changed. JSONLINE keeps main's NULL rule: only JSON `null` is NULL, a JSON string `"\N"` is text, and `$binary` payloads round-trip byte-exact. Author run at `9cf7b69221` (after merging main `5fb586e142`, GPU build): the affected Go packages and `TestTypeSwitchFamilies` pass; BVT `-m run` 0 failures: `cases/dtype` 8738 (32 ignored), `cases/array` 1501/1501, `cases/vector` 3460 (2 ignored), `cases/load_data` 1607 (5 ignored), and the 3 case files the merge changed. Author run at `1575c6a696` (after merging main `e19f698de0`, GPU build): every `pkg/` test package compiles; `TestTypeSwitchFamilies` and the affected Go packages pass; golangci-lint v2.14.0 reports no issue in the PR's packages; BVT `-m run` 0 failures: `cases/dtype` 8738 (32 ignored), `cases/array` 1501/1501, and the 11 case files the merge changed; `cases/vector` 3449 of 3460 (2 ignored) in the run right after the restart, where three HNSW/IVF files missed the index plan, and those three files pass 89/89 when rerun. Author run at `7af7fc1618` (after `b2e09f6b5e`, and `9d4e8b3130`: affected Go packages pass, BVT 0 failures for `cases/vector` 3455, `cases/array` 1501, `cases/dtype` 8738, `gpu_cases/vector` 1360, `cases/function` 22118, `cases/load_data` 1578, `cases/prepare` 4129, `cases/dml` 7936; `TestTypeSwitchFamilies` and the affected Go packages pass; BVT `-m run` 0 failures: `cases/dtype` 8738 (32 ignored), `cases/vector` 3410 (2 ignored), `gpu_cases/vector` 1360/1360, `cases/function` 22118 (150 ignored), `cases/array` 1501/1501, `cases/load_data` 1578 (5 ignored), `cases/ddl` 8610 (168 ignored), `cases/prepare` 4129 (1 ignored), `cases/table` 2019 (19 ignored), `cases/dml` 7936 (120 ignored))) on a real device (GPU build, `MO_CL_CUDA=1`): `TestTypeSwitchFamilies` and the affected Go packages pass (`container/types`, `sql/plan/...`, `sql/compile`, `aggexec`, `external`, `externalwrite`, `frontend`, `pb/plan`, `defines`); each new regression fails with the fix reverted. BVT `-m run`, 0 failures: `cases/dtype` 8672 (32 ignored), `cases/vector` 3398 (2 ignored), `gpu_cases/vector` 1360/1360. GPU-tagged static analysis reports no findings on `dbfa3ad95e` (see the author run at `dbfa3ad95e`). Device-scale performance remains **pending**, not counted as a pass; no current end-to-end speedup claim is made. Rolling deployment does not apply: MatrixOne upgrades by full-cluster shutdown only. CPU evidence does not establish GPU acceptance; the documented approximation/subnormal limits remain in force. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: XuPeng-SH <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: fengttt <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
issue #31895
What this PR does / why we need it:
inner_productreturning a negative value keeps being reported as a sign bug: #29703, #29789 and #31667 were closed as by design, #30475 is open, and code-review agents raise the same finding. The convention is written down only in code comments and a feature design doc. This PR adds one reference and tests every behavior it states.docs/sql/vector-distance-functions.mdinner_product(a, b)returns-Σ aᵢbᵢ, soORDER BY inner_product(v, q) LIMIT kreturns the most similar rows first (pgvector's<#>convention).cosine_similarityis the only "larger is nearer" function, and no index serves it.l2_distance_sq).summation,l1_norm,l2_norm,vector_dims,normalize_l2(int8/uint8 returnvecf32),subvector(keeps the type),abs,sqrt(returnsvecf64), arithmetic, comparisons, conditionals,hex/to_base64, casts (int8/uint8 targets round and saturate) and aggregates.op_typeserves which function.l2/l2sqserve bothl2_distanceandl2_distance_sq;l1is IVF-FLAT only; only ascending order is served.l2_distance.vecf32/vecf16columns.int8/uint8quantization is L2-only in every index (ip,cosineandl1are rejected), and CAGRA/IVF-PQ rejectbf16quantization. On avecint8/vecuint8column, IVF-FLAT serves everyop_typeand HNSW serves all butl1.Tests: every behavior the page states is checked by a BVT.
test/distributed/cases/vector/vector_distance_semantics.sql, CPU: the function values and errors, result types for all six vector types, and IVF-FLAT and HNSW for eachop_type. Each index check asserts the plan with@regex("Vector Index Scan on ix [<function>]")and the returned values.test/distributed/gpu_cases/vector/vector_distance_semantics_gpu.sql, GPU: CAGRA for eachop_typewith values, IVF-PQ index use, and thel1rejection.Code (comments only, no behavior change):
InnerProductdefinitions inpkg/vectorindex/metricandpkg/vectorize/moarraypoint to the page.docs/ai-skills/fulltext-vector.mdlinks it.metric/types.gosaidgpu.gonegates the inner product a second time;gpu.godocuments that this was fixed.metric/types.gosaid HNSW keeps cosine on the exact SQL path; HNSW serves cosine (the BVT asserts the plan).func_binary.gosaid the scalar L2 accumulates in float64 vial2DistanceF64, which no longer exists.cgo/cuvs/index_base.hppsaid the sign flip shows "the true IP"; the result is MO's-dot.Validation on main
c32e75a2b2:-m run:vector_distance_semantics.sql127/127,vector_distance_semantics_gpu.sql47/47 (RTX 5070).pkg/vectorindex/metricandpkg/vectorize/moarrayunit tests pass;go vetonpkg/sql/plan/functionis clean.🤖 Generated with Claude Code