Skip to content

fix(embedding): normalize subnormal vectors without losing direction - #724

Merged
rng1995 merged 15 commits into
NVIDIA:mainfrom
Afloat16:fix/subnormal-embedding-normalization
Nov 23, 2026
Merged

rng1995 merged 15 commits into
NVIDIA:mainfrom
Afloat16:fix/subnormal-embedding-normalization

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A nonzero subnormal embedding vector passes validation, but its norm has too few significant bits for direct normalization. For example, [5e-324, 5e-324] becomes [1, 1], and its cosine similarity with [1, 0] is clamped to 1.0 instead of approximately 0.707. A catalog query can consequently report a high-similarity match for a different direction.

When the norm is subnormal, rescale the validated vector by its largest absolute component before computing the unit vector. This preserves direction without changing the ordinary, zero-vector, dimensionality, or invalid-value paths. The change addresses the numerical behavior of extremely small accepted vectors; it does not claim a general accuracy increase for ordinary provider outputs.

Merge and current verification

At 2c478d352ac21ef9c5eaa7fa38fa8745e066952b, merged upstream main 3ecd69bd7fb189df064821ea637f99ba4a2007d7. The only conflict was in CHANGELOG.md; both this PR's release note and the upstream scanner-install note are retained. This PR's production code and tests are byte-for-byte unchanged from 08dc0897f46b971ea63a85d20e89a905a59f560f.

Re-ran the embedding subnormal-vector, client, registry and semantic-clustering test modules listed below: 137 passed on Linux with Python 3.12.14. Also passed python -m ruff check src tests, Ruff formatting for the changed Python files, the OSS boundary check, and python -m build (wheel and sdist). Hosted workflows for this merge commit await maintainer approval.

Original verification

Seven new cases fail on the original code. Regressions cover three directions at three subnormal scales, input immutability, unit length, cosine values, and a catalog query that must not cross the 0.9 matching threshold.

python -m pytest tests/embedding/test_subnormal_vectors.py tests/embedding/test_client.py tests/embedding/test_registry.py tests/deduplication/intra_skill/test_semantic_clustering.py -q — 137 passed.

  • I am familiar with the Contributing Guidelines
  • Added or updated focused tests
  • Updated documentation for user-visible changes (Unreleased changelog)
  • Ran make lint equivalent: python -m ruff check src tests
  • Full make test did not complete successfully in this environment (see below)
  • Ran make build equivalent: python -m build (wheel and sdist)
  • Did not add credentials, private datasets, or proprietary benchmark content

The unchanged base 8fe9723, tested with python -m pytest -x -q, stops after 456 passed and 19 deselected at tests/ci/test_gateway_benchmark_workflows.py::test_gitlab_enriched_tier1_applies_the_keyless_job_baselines[extra0-expected0]. The sandbox has no /tmp, while that workflow fixture explicitly invokes mktemp -d /tmp/skillevaluator-enriched-tier1.XXXXXX. The same test fails for the same reason on the retry branch. No full-suite pass is claimed.

Release Impact

  • No user-visible release note needed
  • Updated CHANGELOG.md

Signed-off-by: Afloat <ShuffleMonkey@163.com>

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, this checks out. I reproduced the problem on main: normalize_embedding_vector([5e-324, 5e-324]) comes back as [1.0, 1.0], so the cosine against [1, 0] clamps to 1.0 instead of 0.707. With the rescale it returns the right direction, the new tests fail without the source hunk (7 of 10) and pass with it, and a few thousand random ordinary vectors normalise bit-for-bit the same before and after, so the normal path is untouched.

One honest note on scope: this only triggers when every component of the vector is below about 2.2e-308, which no embedding provider actually returns, so this is defensive hardening rather than a fix anyone will hit. That is fine given how small and safe the change is.

Nit, not blocking: the changelog line could be plainer, something like 'Similarity scores stay correct for extremely small embedding vectors'.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, @Afloat16, for fixing normalization of subnormal vectors. Rescaling a nonzero subnormal norm preserves direction without changing the ordinary normalization path, and the registry regression covers the false high-similarity match. I found no new actionable issues on this head.

Validation: 116 focused embedding normalization, client and registry tests passed with mocked provider calls.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Afloat16 for this contribution! I reviewed be2289c760. I reproduced the problem on main, confirmed this change fixes it, checked that the new tests fail on main, and ran the new and related tests on this head (all pass). I left 1 inline comment (1 P3); please take a look.

Comment thread CHANGELOG.md Resolved
Merge current main while retaining this change and the published release notes.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
@Afloat16

Copy link
Copy Markdown
Contributor Author

Moved the subnormal-vector fix into Unreleased.

Commit e430e5a resolves the changelog conflict and leaves main's published release notes unchanged. The existing embedding implementation and regression-test blobs are unchanged. Hosted workflows await maintainer approval.

@Afloat16
Afloat16 requested a review from rng1995 November 18, 2026 04:27
Resolve the Unreleased changelog conflict while retaining both entries.
Preserve the reviewed PR implementation and published release history.

Signed-off-by: Afloat <ShuffleMonkey@163.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Afloat16 for this contribution and for addressing the earlier review! I re-checked 08dc0897f4: all 1 earlier comment is resolved in the code, the tests pass, and I found nothing new. Approving.

Resolve the CHANGELOG.md conflict by retaining both the existing PR entry and the upstream scanner-install entry.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
@rng1995

rng1995 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

@Afloat16 - Please resolve merge conflict to merge the PR.

Synchronize with NVIDIA/SkillEvaluator main f867b7f.
Retain this PR's entry under Unreleased and preserve published release history.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
@Afloat16

Copy link
Copy Markdown
Contributor Author

Resolved the merge conflict in 37f3bec353 by merging current main f867b7f311. The PR's release note remains under Unreleased, and published release history is unchanged.

The implementation and regression-test patch has the same stable patch ID before and after synchronization. On the exact merged tree, 63 passed in the focused checks (Linux, Python 3.12.14); full-source Ruff, changed-file formatting, and git diff --check pass.

New hosted workflows require maintainer approval; the full platform matrix has not run on this head.

rng1995 and others added 3 commits November 20, 2026 10:09
Resolve the CHANGELOG.md conflict by keeping main's Unreleased entries unchanged
and the PR's embedding note at the top of the Unreleased ### Fixed list.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
Resolve the CHANGELOG.md conflict by keeping main's entries and this change's entry under Unreleased.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>
Resolve the CHANGELOG.md conflict by keeping main's entries and this change's entry under Unreleased.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Afloat16 for this contribution! I re-checked 410e42a2d: I merged current main into the branch (the only conflict was CHANGELOG.md, resolved by keeping main's entries and this entry under Unreleased), confirmed that every earlier review comment is addressed in the code, and ran this PR's tests and ruff, which pass. I found nothing new. Approving.

@rng1995
rng1995 merged commit eef309e into NVIDIA:main Nov 23, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants