You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An HNSW index created with OP_TYPE 'vector_ip_ops' returns the correct nearest row but exposes an incorrect INNER_PRODUCT value. The HNSW plan returns a score that is exactly 1 greater than the scalar/full-scan result in the minimal case below.
The issue affects both VECF32 and VECF64.
Environment
Branch: main
Commit: 3046f14d94b3f1a25839eeeb65729b64f85ac647
Local standalone CN/TN/logservice cluster
Reproduction
SET experimental_hnsw_index =1;
CREATETABLEt (
id BIGINTPRIMARY KEY,
v VECF64(3)
);
INSERT INTO t VALUES
(1, '[1,1,1]'),
(2, '[2,2,2]'),
(3, '[-3,-3,-3]'),
(4, '[4,4,4]');
CREATEINDEXidx_v USING HNSW ON t(v)
M=4 EF_CONSTRUCTION=32 EF_SEARCH=16
OP_TYPE 'vector_ip_ops' MAX_INDEX_CAPACITY 1000000;
-- Scalar value.SELECT id, INNER_PRODUCT(v, '[1,1,1]') AS d
FROM t
WHERE id =4;
-- Secondary key prevents the HNSW rewrite.SELECT id, INNER_PRODUCT(v, '[1,1,1]') AS d
FROM t
ORDER BY d, id
LIMIT1;
-- Uses hnsw_search.SELECT id, INNER_PRODUCT(v, '[1,1,1]') AS d
FROM t
ORDER BY d
LIMIT1;
Actual result
Scalar WHERE id=4: 4 -12
Full table scan: 4 -12
HNSW index plan: 4 -11
The same difference reproduced 3/3 times with VECF32(3) and 3/3 times with VECF64(3).
Expected result
The HNSW rewrite must preserve the SQL value of INNER_PRODUCT. The indexed query should return 4, -12, matching direct scalar evaluation and the full table scan.
White-box evidence
The indexed plan replaces the ORDER BY expression with the score emitted by hnsw_search.
pkg/vectorindex/hnsw/search.go calls metric.DistanceTransformHnsw before returning that score.
DistanceTransformHnsw currently transforms only the L2sq-to-L2 case and otherwise returns the underlying USearch distance unchanged.
This is consistent with the observed fixed offset, but the issue is reported based on the SQL-level result mismatch rather than assuming a specific implementation fix.
Related fix: 99d03a52f78b9b42243c169e6d554fafd32f73c4 / PR #27044, fix: vector_l1_ops and vector_l2sq_ops indexes were unusable and hnsw inner product score transform (#27044).
Client protocol: MOTR SQL runner using PyMySQL/MySQL text protocol.
What Was Covered
OK — scalar INNER_PRODUCT result for the known row is -12.
OK — secondary-sort full-scan control returns id=4 and -12.
OK — HNSW vector_ip_ops top-k query returns id=4 and -12.
OK — Proxy MOTR record and replay passed with 11/11 statements.
OK — CN1 and CN2 replay passed with 11/11 statements each.
Not covered — VECF32 parity, larger vector dimensions, concurrent build/query stress, and other index algorithms.
Findings
The old HNSW score exposed USearch's 1 - a·b value, while SQL INNER_PRODUCT uses -a·b; this caused a fixed +1 error. The current implementation transforms the HNSW score correctly and preserves SQL semantics.
Large-data regression is not required: the defect is a metric-value transformation error, independent of rows, block boundaries, memory, spill, concurrency, or resource scale.
MOTR / BVT Coverage
MOTR branch: test/issue-25965-hnsw-inner-product.
MOTR commit: bc668a0 test: add MOTR regression for #25965.
Activity
cpegeric commentedon Aug 12, 2026
The value is round off from usearch. We will not recompute the score again and use directly from HNSW usearch. So, nothing to fix here.
cpegeric commentedon Aug 19, 2026
please verify
slyunnn commentedon Aug 20, 2026
Regression and extended verification for #25965 (2026-08-20)
Verification Environment
MatrixOne
origin/main:621782d4634a36865bdb18c9fe3853bf70f43f1c—fix variables (#26762).Related fix:
99d03a52f78b9b42243c169e6d554fafd32f73c4/ PR #27044,fix: vector_l1_ops and vector_l2sq_ops indexes were unusable and hnsw inner product score transform (#27044).Topology:
1 Log + 1 TN + 2 CN + 1 Proxy.Endpoints: CN1
127.0.0.1:16001, CN2127.0.0.1:16002, Proxy127.0.0.1:6009.Client protocol: MOTR SQL runner using PyMySQL/MySQL text protocol.
What Was Covered
INNER_PRODUCTresult for the known row is-12.id=4and-12.vector_ip_opstop-k query returnsid=4and-12.11/11statements.11/11statements each.VECF32parity, larger vector dimensions, concurrent build/query stress, and other index algorithms.Findings
The old HNSW score exposed USearch's
1 - a·bvalue, while SQLINNER_PRODUCTuses-a·b; this caused a fixed+1error. The current implementation transforms the HNSW score correctly and preserves SQL semantics.Large-data regression is not required: the defect is a metric-value transformation error, independent of rows, block boundaries, memory, spill, concurrency, or resource scale.
MOTR / BVT Coverage
MOTR branch:
test/issue-25965-hnsw-inner-product.MOTR commit:
bc668a0 test: add MOTR regression for #25965.Covered files:
suites/14_issue_regression/t/issue_25965_hnsw_inner_product.testsuites/14_issue_regression/r/issue_25965_hnsw_inner_product.resultThe independent MOTR branch has been pushed. No issue-specific PR was created.
Final Conclusion
Fixed. HNSW
vector_ip_opsnow returns the exact SQLINNER_PRODUCTscore on Proxy, CN1, and CN2.fix(sql): return mathematical dot product from INNER_PRODUCT (#29711)
Ariznawlll commentedon Nov 29, 2026
结论
测试通过。本轮“HNSW inner_product 分数与精确计算一致”已完成下列原始复现、相关扩展及对应 Linux CI;回归已提交至现有 MOTR PR,按授权关闭。
关键证据
版本与修复范围
6540533196711f09e6b1279066063cb90043ebd8,独立目录编译、独立端口/数据目录;两个 CN 的SELECT git_version()与完整 SHA 一致。99d03a52f78b9b42243c169e6d554fafd32f73c4。实际执行步骤与结果
Vector Index Scan on idx_v [inner_product],没有把未走索引的成功当作 HNSW 通过。TestDistanceTransformHnsw三轮通过。最初 Go 测试遇到本机 libmo 动态库路径问题,增加绝对 rpath 后重跑通过,未修改产品代码。回归与 CI
e75a4d2ca470b35c2bf254cfcf5e3069f51be90a,不是仅依据分支名称。六组正式 MOTR × 3 轮,共 18/18(0 SKIP);plan、blockio、fulltext、vector metric 定向源码测试,以及 frontend native prepared SHOW 和 sqlintegration 角色规则测试均-count=3通过。待解决点
本 Issue 所列验收范围内无待解决的产品失败。MOTR PR 尚待合入;已获得“回归提交后可先关闭”的授权。本结论不外推到未涉及的性能、大数据或其他 Issue。
最终结论:测试通过。上述原始与扩展场景、对应分支回归及 Linux CI 均通过;未通过项:无。回归已提交现有 MOTR PR,本次关闭 #25965。