Skip to content

test: anchor cosine boundary regressions to scale invariance - #29175

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-cosine-boundary-oracle
Sep 20, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-cosine-boundary-oracle

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Test and CI

Which issue(s) this PR fixes:

Related to #29083 and #29082. Repairs the deterministic base BVT failure exposed by #29174 after #29143; does not claim to close every vector-index issue.

What this PR does / why we need it:

The cosine boundary golden captured float32 subnormal squared-norm error. After #29143 switched SQL scalar and batch paths to scaled float64 reductions, six assertions still expected 0.05718844756484032 rather than the correct 1 - 4/sqrt(18) = 0.05719095841793653. The same six failures occur in the CI of #29143 and #29174; this is not a timing flake.

  • Correct exactly six expected values; retain all 22 SQL statements, raw scores, result shapes, and comparison rules.
  • Document the independent mathematical oracle rather than regenerating expectations from the implementation.
  • Add non-endpoint cosine scale-invariance tests for float32/float64, independently tiny operands and mixed extreme magnitudes, with negative and zero controls.
  • Exercise actual SQL const/column and materialized column/column execution; assert batch eligibility, DOUBLE result shape, and each path's agreement with the independent oracle at absolute tolerance 1e-14.

No production code, runtime allocations, algorithm dispatch, retries, skips, or comparison tolerances changed. Reuses existing small fixtures.

Validation

  • Go1.26.4 darwin/arm64 CPU, matching stamped native artifacts.
  • Focused new metric and SQL executor tests PASS; owning pkg/vectorindex/metric and pkg/sql/plan/function packages PASS.
  • Clean base service reproduces the original BVT 6/22 failures. Same ready isolated service with corrected test: 22/22 PASS twice (0.203s/0.238s); database cleanup checked between and after runs.
  • Targeted go vet, incremental lint, gofmt and diff checks.
  • Independent GPT-6-astra medium design and final overall review.

Local BVT is standalone; historical failure evidence is Linux multi-CN PROXY CI. No topology/runtime change warrants another full multi-CN run locally. New PR CI remains pending; it has not been claimed green.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PASS — completed full deep review of f42330b..8baeefd.

The six golden corrections match the independent cosine oracle 1−4/√18. The new tests cover float32/float64 scale invariance, negative/zero controls, and actual SQL batch/scalar paths with DOUBLE result assertions. Existing BVT statements and comparison rules remain intact.

Verified exact-head Ubuntu UT success and PROXY BVT execution of vector_hnsw_cosine_boundary.sql: 22/22 passed, zero ignored or failed. Reviewed reusable focused/package and cleanup/rerun evidence. No blockers found; coverage was not used as a gate.

@XuPeng-SH
XuPeng-SH merged commit b2f178d into matrixorigin:main Sep 20, 2026
28 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/fix-cosine-boundary-oracle branch September 20, 2026 21:31
XuPeng-SH added a commit that referenced this pull request Sep 20, 2026
## What type of PR is this?

- [x] BUG
- [x] Test and CI

## Which issue(s) this PR fixes:

Fixes #28852

## What this PR does / why we need it:

Decimal variance and standard-deviation executors accumulate in
`float64`. Their previous final conversion exposed the binary ULP tail
as decimal digits, so the issue's DATETIME/TIMESTAMP `VAR_POP` result
became `680202686800.666624` instead of MySQL-compatible
`680202686800.666600`.

This change converts finite aggregate results through their shortest
round-trip decimal representation before scaling to Decimal128. It is
deliberately limited to the Decimal variance/stddev finalizer: planner
coercion, recurrence, distributed state/wire format, global casts, and
float-returning aggregates are unchanged.

Validation includes:

- exact conversion boundaries, signs, non-finite values, exponent
notation, precision overflow, and adjacent-float cases;
- exact executor results for Decimal64/Decimal128, VAR/STDDEV
population/sample, resident/DISTINCT paths;
- serialized-state restore and merge;
- the original temporal SQL regression and all twelve existing DECIMAL
variance overflow assertions, preserving exact target precision/scale
while allowing approximate numeric payload variation;
- full owning-package tests, `go vet`, scoped golangci-lint, and build;
- current rebased code: native/server build and full aggexec package
tests passed;
- normal BVT comparison twice on one fresh instance: 419/419 each
(VAR_POP/VARIANCE 242, VAR_SAMP 141, temporal regression 14, cosine
boundary 22), with no test schemas left after either run.

The branch includes main through `b2f178defd` (#29175 cosine regression
correction). Current remote SCA/full CI is pending; the earlier revision
passed scoped static checks. The follow-up changes only BVT error
expectations and retains all executable SQL and successful-result
oracles.

GPT-6 Astra medium completed both design review and final overall
review; final verdict: PASS with no material findings.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants