Repository navigation
fix(embedding): normalize subnormal vectors without losing direction - #724
Conversation
Signed-off-by: Afloat <ShuffleMonkey@163.com>
chrisknvidia
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
Merge current main while retaining this change and the published release notes. Signed-off-by: Afloat <ShuffleMonkey@163.com>
|
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. |
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>
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>
|
@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>
|
Resolved the merge conflict in 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 New hosted workflows require maintainer approval; the full platform matrix has not run on this head. |
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
left a comment
There was a problem hiding this comment.
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.
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 main3ecd69bd7fb189df064821ea637f99ba4a2007d7. The only conflict was inCHANGELOG.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 from08dc0897f46b971ea63a85d20e89a905a59f560f.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, andpython -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.make lintequivalent:python -m ruff check src testsmake testdid not complete successfully in this environment (see below)make buildequivalent:python -m build(wheel and sdist)The unchanged base
8fe9723, tested withpython -m pytest -x -q, stops after 456 passed and 19 deselected attests/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 invokesmktemp -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
CHANGELOG.md