Skip to content

feat: low-precision float types bf16/float16/float8/float4 and vecf8/vecf4 vector columns (#20567) - #29554

Merged
fengttt merged 81 commits into
matrixorigin:mainfrom
cpegeric:bug_20567_vector
Nov 4, 2026
Merged

fengttt merged 81 commits into
matrixorigin:mainfrom
cpegeric:bug_20567_vector

Conversation

@cpegeric

@cpegeric cpegeric commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • 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 docs(skills): shutdown-only upgrade contract for agent reviews #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 (Fix decimal rounding and MySQL text-to-float casts #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, feat(sql): add ewmMean/ewmVar/ewmStd/ewmCov/ewmCorr window functions #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 refactor: consolidate unused code and duplicate responsibilities #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 docs(vector): one reference for vector function and distance semantics (inner_product = -dot) #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

@mergify mergify Bot added kind/feature kind/enhancement kind/documentation Improvements or additions to documentation labels Oct 1, 2026
@matrix-meow matrix-meow added the size/XXL Denotes a PR that changes 2000+ lines label Oct 1, 2026
The cuVS cgo bindings imported unsafe directly, which molint's checkunsafe
reports once the gpu-tagged files are analyzed. Every unsafe.Pointer
conversion now goes through util.UnsafePointer, and the two places that
stored an unsafe.Pointer hold the C pointer as *byte instead: the pinned
host memory API (GpuAllocPinned, GpuFreePinned, PinnedPool) and the VRAM
reservation token. pkg/cuvs no longer imports unsafe.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cpegeric

cpegeric commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

@aunjgr Thanks for review 5713126545: the GPU-tagged static analysis is now done, on head dbfa3ad95e. You were right that green CPU CI did not cover it: make static-check passes no build tag, so //go:build gpu files were never analyzed.

Commands (repo root, the GPU include paths that MO_CL_CUDA=1 gives CGO_CFLAGS, GOWORK=off):

  • molint check -mod=readonly -tags gpu ./..., with the molint version Makefile pins (v0.0.0-20261028130237-35bd4d9a4055);
  • golangci-lint run -c .golangci.yml --build-tags gpu ./..., with golangci-lint v2.14.0.

Result on dbfa3ad95e: 0 findings from both.

What it found before the fixes:

  • This PR, 2 findings (fixed in 42eeeb2a77): checkunsafe in the new pkg/cuvs/blockscaled_matmul.go, and prealloc in its test.
  • Already on main, 17 findings (same commands on main c8534cc3e2), fixed here in a022e4a039 and dbfa3ad95e:
    • 16 checkunsafe: the GPU table functions and the CAGRA/IVF-PQ search and probe files now 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.
    • 1 ineffassign in pkg/cuvs/search_float_test.go.

Validation on dbfa3ad95e:

  • GPU unit tests pass for pkg/cuvs/..., pkg/vectorindex/..., pkg/sql/colexec/table_function and pkg/sql/colexec/aggexec.
  • BVT -m run of all of test/distributed/gpu_cases passes 1959/1959 (64 files).

The head also merges main c8534cc3e2. Main's IF/CASE checks now come in a MySQL-mode and a native-mode copy, and both carry the low-precision handling. The PR description lists the merge's test and BVT runs.

@aunjgr, please re-review against dbfa3ad95e. @iamlinjunhong, your change request is on b200d967f2 (Oct 15); please re-review against dbfa3ad95e when you can.

🤖 Generated with Claude Code

cpegeric and others added 5 commits October 30, 2026 18:32
Main's MO_INDEX_SUB_PART (matrixorigin#31489) took the next function id;
VECTOR_MATMUL, VECBLOCK_JSON and VECBLOCK_BINARY move to the ids after it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…error

parquet_vector_nonfinite (main matrixorigin#31831) expects main's message for a vecf16
and a 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; both inserts are still rejected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts and merge fixes:
- function ids: main took 624..628 for EWM_*; VECTOR_MATMUL, VECBLOCK_JSON and
  VECBLOCK_BINARY move to 629..631 (FUNCTION_END_NUMBER 632), and
  aggexec.AggIdOfVectorMatmul to 629 << 32
- mysql_sql.go regenerated with goyacc from the merged grammar
- strhashmap.go: both sides kept; the new fixed-key fast path copies
  bf16/float16/float8/float4 bytes (zeros are stored as +0)
- pkg/iscp: copyBytes was removed by matrixorigin#31488; vecf8/vecf4 use CloneBytesAt
- TestTypeSwitchFamilies: the EWM window functions take bf16/float16/
  float8/float4 samples, decay, policy arguments and event-time ORDER BY
  keys; parallel UNION ALL projection admits them as IFF conditions; the
  two plan.Literal readers are tagged partial
- vector_distance_semantics.result: the vecf16 overflow message follows
  this branch's out-of-range error
- lowprec_ddl_dml: EWM over the low-precision floats against FLOAT

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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]>
# Conflicts:
#	pkg/sql/parsers/dialect/mysql/mysql_sql.go
#	pkg/sql/plan/function/func_cast.go
@cpegeric

cpegeric commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@aunjgr please review it. thanks

@XuPeng-SH

XuPeng-SH commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 0829baa567fe07dca1c13e070357be101e8bcf14

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: 0829baa567fe07dca1c13e070357be101e8bcf14

Assessment: approve

No actionable findings remain. Reviewed changed behavior and merge interactions, qualified reusable evidence, and reconciled all 200 discussion entries. Historical compatibility and JSONL objections are settled by the applicable contracts; the GPU static-analysis request is supported by the author’s report and source comparison.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • Isolation preflight, TestTypeSwitchFamilies and TestVecBlockKernelsGenerated passed; receipts match retained logs and the frozen head.

  • Regenerated SQL parser matches checked-in output apart from its command comment; zero parser conflicts.

  • Frozen CI reports successful unit tests, static analysis, native builds and both multi-CN BVT jobs.

  • Final audit confirmed clean tracked source, coverage of 319 changed files and complete discussion-key accounting. Evidence retained in validation-manifest.json and discussion-assessment.json.

Limitations:

  • No fresh native-package, multi-CN or GPU hardware execution in this attempt. Broader coverage relies on frozen CI and qualified author reports; their raw logs were unavailable locally.

# Conflicts:
#	pkg/sql/plan/function/func_cast.go
@XuPeng-SH

XuPeng-SH commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 6d6b2aac3ba134ff7f4b5d9af59c3dbbfb1ca0a7

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: 6d6b2aac3ba134ff7f4b5d9af59c3dbbfb1ca0a7

Assessment: approve

No actionable findings remain. Qualified prior coverage against all 319 changed files, reviewed merge interactions, and reconciled all 202 discussion entries. Historical compatibility and JSONL objections conflict with the applicable contracts; subsequent correctness, accounting and GPU validation concerns are resolved.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • Isolation preflight, TestTypeSwitchFamilies and TestVecBlockKernelsGenerated passed.

  • Regenerated parser matches after normalizing generated command/source-path comments; zero grammar conflicts.

  • Frozen current-head CI reports successful unit tests, static analysis, native builds and both multi-CN BVT jobs.

  • Final audit verified frozen inputs, clean source, complete discussion coverage and receipts against retained logs. Evidence is recorded in validation-manifest.json.

Limitations:

  • No fresh native-package, race, SQL-server, multi-CN or GPU hardware execution. Broader coverage uses frozen CI and qualified author/prior-review evidence; their raw logs were unavailable locally.

  • Initial parser-comparison and audit failures concerned comparison formatting; both were corrected, with failed and successful evidence retained.

cpegeric and others added 3 commits November 3, 2026 08:57
…#32039

visitEncodedPrimaryKeyVector took over the switch from
EncodePrimaryKeyVector, so its baseline key no longer matched. Low-precision
floats and VECTOR columns are rejected as primary key columns at DDL; tag the
switch and drop the stale baseline entries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@XuPeng-SH

XuPeng-SH commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: c1a2c8dc3d32972dcc3cc7fd011383337eddbc58

"interrupted"

@cpegeric

cpegeric commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@aunjgr The GPU-tagged static analysis you asked for on Oct 30 was already done and is in the PR description: on dbfa3ad95e, molint check -mod=readonly -tags gpu ./... and golangci-lint run -c .golangci.yml --build-tags gpu ./... (v2.14.0, GPU include paths of MO_CL_CUDA=1) report 0 findings. Later merges of main don't touch GPU-tagged files or pkg/cuvs (see the author run at f5fad15240). Please re-review or clear the request. Thanks.

@fengttt @XuPeng-SH if aunjgr isn't available, could one of you dismiss the Oct 30 review? It's the only thing keeping the PR out of the merge queue.

cpegeric and others added 2 commits November 3, 2026 16:26
…loats unrounded

matrixorigin#32092 compares a JSON number outside FLOAT's range by its float64 value
instead of failing. Apply the same to bf16/float16/float8/float4: inside the
type's finite range the JSON number is rounded to the type's grid as before,
outside it compares unrounded. The numeric peer keeps its range check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@XuPeng-SH

XuPeng-SH commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 1e8946a474f8c858cdc9a6f50de8e79091a2be73

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: 1e8946a474f8c858cdc9a6f50de8e79091a2be73

Assessment: approve

No actionable defects remain. The feature reuses existing codec, key, metric and aggregate owners; bounded shared configuration and GPU tiles justify their added state. Current merge interactions are closed. Historical mixed-version objections are superseded by the shutdown-only policy, and restoring the disputed JSONLINE null-marker fallback would regress intentional behavior.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed the complete 320-path change map, qualifying prior coverage for 295 unchanged paths and independently inspecting all 25 changed paths and affected consumers.

  • Read all 206 discussion entries and six linked issue contexts; saved discussion-assessment.json with exact key coverage.

  • Preflight passed; exact-head CPU native prerequisites built successfully and passed repository provenance verification.

  • Full types, vector and metric package tests passed, including type-family completeness and generated-kernel consistency.

  • 112 focused top-level tests passed across function, aggexec, colexec and mysql parser packages.

  • Parser generation reproduced exactly after invocation-header normalization. Final source audit verified frozen inputs, preserved persisted IDs and unchanged source.

  • Reconciled commands, exits and retained logs in validation-report.json. Frozen CI records 22 successful contexts; 14 skipped and two neutral contexts were excluded from passes.

Limitations:

  • Local execution used the CPU build. Historical GPU, race and static-analysis evidence was source-qualified; no fresh GPU or race run is claimed.

  • Accepted GPU approximation and CPU subnormal-grid limits remain; broad device-scale performance was not remeasured.

  • Parser receipt fingerprint capture timed out; the final audit independently verified the exact frozen grammar and reproduced parser hashes.

  • Older scalar-design wording about outside-range JSON errors is stale; current behavior follows main's wider-value ordering contract.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Post-merge follow-up at 1e8946a. This is a focused re-audit of my earlier blockers, not a new approval of the entire low-precision feature.

The substantive CPU decoding and ID-compaction findings are addressed in the current source: NVFP4 full-unit kernels take the At-decoding recovery path when the combined scale is subnormal; the decode-contract tests include amplified smallest-float32 inputs across unit boundaries; and VECTOR_MATMUL compaction/merge identify text by (offset,length), with the empty-ID/"winner" regression covering both operations and allocation-account modes. The function-ID conflict is also removed: FORMAT_BYTES/FORMAT_PICO_TIME remain 596/597, while VECTOR_MATMUL and the block introspection functions use 629..631.

I withdraw my earlier old-peer/MORPC admission objections. The documented deployment contract is full-cluster shutdown upgrades, not mixed-version execution; demanding rolling-upgrade capability negotiation here was the wrong requirement.

No remaining blocker found in this follow-up scope. This pass was source/test inspection; I did not rerun the full feature suite or validate GPU execution.

This branch was previously deployed

1 inactive deployment
ci — 1e8946a4 Deployed Nov 3, 2026 by cpegeric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/api-change kind/bug Something isn't working kind/documentation Improvements or additions to documentation kind/enhancement kind/feature kind/refactor Code refactor kind/test-ci size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants