fix(ai): expose TurboQuant padding on VectorQuantizeTask and correct its guidance - #762
Merged
sroussey merged 1 commit intoAug 13, 2026
Conversation
…its guidance
`executePreview` hard-rejected every non-power-of-2 dimensionality for
`method: "turbo"` and never exposed `turboQuantizeToTypedArray`'s
`{ padToPowerOf2: true }`, so the accurate option was unreachable from the task.
Worse, the rejection message quoted RMSE figures for the CROPPED variant the util
no longer emits, and used them to steer users to `linear` — advice that is
backwards for the option now on offer.
Re-measured over 40 seeded pairs at int8, padded turbo vs this task's linear
path: 0.00034 vs 0.00269 at d=768, 0.00024 vs 0.00331 at d=1536, 0.00021 vs
0.00263 at d=3072. Padded turbo is 7.8x, 13.8x and 12.8x more accurate at exactly
the three sizes the old message named as reasons to avoid it.
- Adds a `turboPadToPowerOf2` input, DEFAULT FALSE. Enabling it lengthens the
output vector (d -> nextPowerOf2(d)) and a storage column sized to d would
reject the result, so it has to be opted into rather than inferred.
- Rewrites the rejection message to lead with the flag, state the widening and
the column sizing, quote the real measurement, and name `linear` second as the
option that preserves length. Same correction applied to the `method`
description and to the util's JSDoc and throw, where the cropped figures are
now explicitly labelled as the cropped variant's and marked as not to be quoted
as the cost of turbo.
- Folds the duplicated `nextPowerOf2`: the util's copy calls `assertDimensions`
first (rejecting non-integers, n < 1, n > 2**20) and the task's local copy did
neither, so an oversized vector bypassed the task's carefully worded error and
surfaced the low-level one. The util's helper is now exported and the local
copy deleted.
Tests: a 768-dim vector with `turboPadToPowerOf2: true` returns length 1024 and
beats `method: "linear"` on measured RMSE over seeded pairs; the rejection test
additionally asserts the message names `turboPadToPowerOf2` and no longer
contains the stale 0.0164 figure. All three were confirmed RED against the base
branch before the fix.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RomTUtZSTgUbFCYqFs4pcu
sroussey
merged commit Aug 13, 2026
24620bc
into
claude/integrate-arxiv-paper-VF55c
10 of 11 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes on top of #354.
What breaks
packages/ai/src/task/VectorQuantizeTask.tshard-rejected every non-power-of-2 dimensionality formethod: "turbo", never exposedturboQuantizeToTypedArray's{ padToPowerOf2: true }, and — the part that actually misleads — quoted RMSE figures for the cropped variant the util no longer emits, using them to steer users towardlinear:Cropping (keeping the first
dofnextPowerOf2(d)rotated coordinates) really is worse than linear — that is why the util stopped offering it. But those numbers describe a code path that no longer exists, and the message presented them as the cost of turbo. So the task told users that linear was the accurate choice at 768/1536/3072 while the accurate choice, padding, was unreachable from the task at all.Measured
Re-measured myself, 40 seeded pairs, int8, seed 42 — padded turbo vs this task's own linear path, RMSE of the quantized cosine against the exact cosine:
Padded turbo is roughly an order of magnitude more accurate at exactly the three sizes the old message named as reasons to avoid it. (Directionally identical to the figures in the brief; the multiples differ because the draws do.)
The fix
turboPadToPowerOf2input, defaulting tofalse. Enabling it widens the output fromdtonextPowerOf2(d). That is a real consequence — a storage column declared atdwill reject the result — so it is an opt-in, never inferred. When set, the task passes{ seed: turboSeed, padToPowerOf2: true }through to the util.linearsecond as the option that preserves length — which is the honest reason to pick it now.methoddescription ininputSchemaand to the util's JSDoc andthrow. The cropped figures survive in the util's JSDoc, but explicitly labelled as the cropped variant's and marked as not to be quoted as the cost of turbo — they explain why the variant is not offered, which is still worth recording.nextPowerOf2. The util's copy callsassertDimensionsfirst (rejecting non-integers,n < 1,n > 2**20); the task's local copy did neither. An oversized vector therefore bypassed the task's carefully worded error and surfaced the low-level one instead. The util's helper is now exported (with a comment on why callers must not reimplement it) and the local copy deleted.What the new tests catch
All three were confirmed RED against the base branch before the fix, then green after:
turboPadToPowerOf2: truereturns length 1024 (red today: unknown input property).method: "linear"on measured RMSE over seeded pairs at d=768. Asserted asturboRmse < linearRmse / 4— measured gap is 7.8x, so there is headroom, but the direction is precisely what the old message got wrong and must not silently reverse.turboPadToPowerOf2and does not contain the stale0.0164.The comparison uses the file's seeded
makeRandom, notMath.random(): it asserts a ratio between two quantizers, where an unlucky sample and a real regression would otherwise look the same.Verification
Run in a worktree off this PR's base,
bun install+bun run use-source:bun scripts/test.ts rag vitest— 24 files, 233 tests passed, 0 failed.bun run build:types— 40/41 tasks successful. The one failure is pre-existing on the base branch and unrelated to this PR:packages/test/src/test/util/TurboQuantize.test.tsimportsgetTestingLoggerfrom../../binding/TestingLogger, which does not exist. Confirmed by stashing this PR's changes and re-running: identical single error. It is fixed in the companion PR (fix(util): scale the TurboQuant norm, and repair three tests that could not fail #757), which also means that whole test file currently fails to load and none of its tests run. This PR is unaffected either way.prettier --checkclean on all three changed files.Environment note: Node 22.22.2, not the Node 24
CLAUDE.mdasks for. Nothing here touches native deps, but CI on Node 24 is the authority.Follow-ups, deliberately not in this PR
Both are additive API design that deserves its own review:
turboPrepareQuery).method/turboSeedoutputs, but a padded vector is now a third thing a consumer may need to distinguish, since its length no longer matches the source embedding.Generated by Claude Code