← Back to Pull requests

Make alpha loosen the diversity check for negative DOT_PRODUCT scores #860

Closed
unknown closed this pull request without merging on Nov 29, 2026 19:54 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 07:17 UTC
Author

Fixes #859.

The diversity check prunes candidate c of node p when an already-selected neighbor s has sim(c, s) > score(p, c) alpha. Alpha above 1 is meant to loosen the check so some longer edges survive. DOT_PRODUCT scores are (1 + dot) / 2, negative when dot < -1, which happens with vectors that are not unit length. For a negative score, score alpha is below score, so every pass with alpha above 1 is stricter than the alpha = 1 pass, and alpha has no effect on those candidates. Like #714, #814, #820 and #848, this is a fix for negative DOT_PRODUCT scores; it is not a recall change for normalized data.

Change

  • VamanaDiversityProvider.diversityThreshold(score, alpha): score >= 0 ? score alpha : score / alpha. A candidate is pruned when a selected neighbor's similarity to it is above this threshold.

  • VamanaDiversityProvider.isDiverse (graph builder) and CompactVamanaDiversityProvider.isDiverse (compaction) both use it, computed once per candidate instead of a multiply per selected neighbor.

  • For a score of at least 0 (including -0.0) and for NaN the threshold is exactly score alpha, so EUCLIDEAN, COSINE and unit-length DOT_PRODUCT graphs do not change. When the score and the selected neighbor's similarity are both negative it is RobustPrune (Vamana, Algorithm 2) with distance -score. When the candidate's score is negative and the selected neighbor's similarity is not, the threshold stays below 0 and the candidate is pruned at every alpha, as at alpha = 1.

  • The new branch only matters when negative-score candidates reach the check, i.e. when a node has fewer than maxDegree surviving positive-score candidates: data in a half-space with a node opposite it (as in #813), or sparse upper layers.

  • Adds the release note.
  • Tests

    TestDiversityNegativeScores (new):

  • the threshold is bit-identical to score * alpha for scores of at least 0, -0.0 and NaN, at alpha 1.0, 1.2, 1.4 and 2.0;

  • alpha above 1 never tightens the check, for either sign;

  • with base (1, 0), c1 = (-2, -4) and c2 = (-3, 2.2) (scores -0.5 and -1.0; c1-c2 similarity -0.9), both providers prune c2 at alpha 1.0 and keep it at alpha 1.2 (threshold -0.83); the old threshold, -1.2, pruned it at both;

  • with three groups of long vectors 120 degrees apart, a node in group A keeps one edge to each of the other groups at alpha 1.2 and none at alpha 1.0; the old threshold kept none at either;

  • on random 8-d vectors at three length scales, the builder's and the compactor's providers select the same neighbors, and on unit vectors both match the old rule.
  • Full jvector-twenty, jvector-tests and jvector-native suites on Ice Lake (32 cores), JDK 22: 718 tests, 0 failures (main: 713, 0 failures, same skips).

    Results

    Ice Lake (32 cores), JDK 22, degree 32, beam 100, overflow 1.2, alpha 1.2, hierarchy, full-precision vectors.

    Single-threaded 100k builds, index files compared byte for byte (main built twice is identical too):

    | Dataset | Similarity | main | this PR | Edges changed |
    |---|---|---|---|---|
    | sift-128 | EUCLIDEAN | a08c3c64 | a08c3c64 | 0 of 3.2M |
    | cohere-english-v3 | DOT_PRODUCT (unit) | f4629fdb | f4629fdb | 0 of 3.2M |
    | cohere-english-v3 | COSINE | df2316c3 | df2316c3 | 0 of 3.2M |

    cohere-english-v3-1M, DOT_PRODUCT, multithreaded builds, 4 runs each in ABBA order plus a main A/A pair:

    | | main | this PR | Change | main vs main |
    |---|---|---|---|---|
    | Build time | 75.07 s | 74.94 s | -0.2% | 0.3% |
    | Allocated per build | 29.75 GB | 29.77 GB | +0.1% | 0.9% |
    | Peak heap / RSS | 8.12 / 9.36 GB | 8.11 / 9.34 GB | ~0 | |
    | QPS, rerankK 10 / 40 / 100 | 84.7k / 34.8k / 17.1k | 85.1k / 35.0k / 17.2k | +0.4 / +0.8 / +0.2% | 2.1% (rerankK 10) |
    | Recall@10, rerankK 10 / 100 | 0.709 / 0.958 | 0.708 / 0.958 | ~0 | 2% (rerankK 10) |

    JDK 25 (one pair) shows the same. Bytecode sizes: builder isDiverse 87 -> 93, compactor isDiverse 78 -> 84, diversityThreshold 16; no method crosses 35 or 325.

    Non-unit data: Music100 (1M x 100, inner product, vector lengths 0.28-1.87), also with 1,000 added outliers (real vectors negated and scaled by 3): single-threaded builds are byte-identical to main, because every candidate there scores at least 0. The fix only changes graphs with the geometry above.

    Data where it does act: 100k x 32-d vectors in three groups 120 degrees apart (length 4, spread 0.25), so every score between groups is negative, with 10k held-out queries and brute-force ground truth. Single-threaded builds differ at 367 of 100,000 nodes (350 edges removed, 524 added, of 2.0M); edges between groups go from 305 to 283. Recall@10 is unchanged: 0.9875 / 0.9963 / 0.9995 on main and 0.9876 / 0.9963 / 0.9995 here at rerankK 10 / 20 / 100.

    Diff: 595 lines (+446 / -149) across 7 files Reviewer: MarkWolters Review duration: 756m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 595 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.382
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #860"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50% (MEDIUM) · Higher = larger blast radius
    50%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.8% · Safe to merge
    19.8%