← Back to Pull requests

GraphSearcher: keep negative DOT_PRODUCT scores, and the threshold, across resume() #848

Closed
unknown closed this pull request without merging on Nov 29, 2026 22:32 UTC
View on GitHub
unknown unknown commented on Nov 27, 2026 04:44 UTC
Author

Fixes #847.

As #813 explains, a threshold or rerank floor of 0.0f is meant to accept everything, but DOT_PRODUCT scores are (1 + dot) / 2, negative whenever dot < -1, routinely for vectors that are not unit length. #714, #814 and #820 replaced 0.0f with NEGATIVE_INFINITY in GraphSearcher.internalSearch and GraphIndexBuilder; this PR fixes the five places they missed and the docs, examples and benchmark harnesses that still passed 0.0f. It also makes resume() keep the threshold of the search it continues.

Change

  • GraphSearcher: resume(additionalK, rerankK), the rerank floor of search(scoreProvider, topK, threshold, acceptOrds) and the static search(queryVector, topK, rerankK, ...) use Float.NEGATIVE_INFINITY.

  • OnDiskGraphIndexCompactor: its searches of the other sources (level 0, the upper-layer descent and the level search) use Float.NEGATIVE_INFINITY.

  • GraphSearcher: each layer-0 search saves its threshold and resume(additionalK, rerankK) applies it, for every similarity function. The rerank floor is still not carried over, as the existing comment on searchOneLayer explains.

  • Javadocs: the GraphSearcher threshold parameters no longer describe scores as 0..1 or 0 as "accept everything"; Float.NEGATIVE_INFINITY accepts every node, and 0 does only for exact EUCLIDEAN and COSINE scores. rerankFloor notes that NEGATIVE_INFINITY reranks every candidate, and resume and the threshold parameters say the threshold carries over. VectorSimilarityFunction.DOT_PRODUCT: vectors need not be unit length; scores are then unbounded and can be negative.

  • Docs and examples: the 22 search calls outside the tests that passed 0.0f, 0.0f (docs, tutorials, examples, QueryExecutor, CompactionBench, JMH benchmarks) pass Float.NEGATIVE_INFINITY. tuning.md states the rule and documents rerankFloor; choosing-an-index.md lists each similarity's score range. Tests on unit, COSINE or EUCLIDEAN data keep 0, which is valid there.

  • With exact scoring, COSINE, EUCLIDEAN and unit-length DOT_PRODUCT top-k searches do not change. Compressed (PQ, ASH) approximate scores are unclamped and can fall below 0; those candidates are now reranked, which can only keep or raise recall. Search mode still depends only on threshold > 0, so adaptive stopping and bounded candidates are unaffected.

  • Adds the release note.
  • Tests

  • TestNegativeDotProductScores (new), on a fully connected graph of 2-d vectors and the query (1, 0): resume() returns all 20 nodes including the 9 with negative scores; search(scoreProvider, topK, threshold, acceptOrds) with a reranker returns the 5 best of 9 all-negative nodes; the static search does the same; with a reranker, one resume(5, 5) returns 5 all-negative nodes; a search with a threshold of -2 and of 2, resumed until empty, returns exactly the nodes scoring at least the threshold.

  • TestOnDiskGraphIndexCompactor.testCompactLinksNodeWithOnlyNegativeSimilarities: compacts a 50-node source on an arc of radius 10 with a smaller source holding an odd node at (-10, 0), whose dot product with every node of the larger source is between -54 and -100, and checks that the odd node is linked to its best match.

  • ...Hierarchical (new): the same with hierarchical sources; the odd node and its best match both sit at level 1, and the test checks their level-1 edge (the upper-layer search). At level 0 hierarchical sources use the cell join, which already kept negative scores.
  • Results

    | Test | main | this PR |
    |---|---|---|
    | resume until empty, 20 nodes, 9 negative | 11 of 20 returned | 20 of 20 |
    | search with a reranker, 9 negative nodes, topK 5 | 1 result | 5 |
    | static search, 9 negative nodes, topK 5 | 0 results | 5 |
    | resume with a reranker, 8 negative nodes left, topK 5 | 0 results (1 with only the floor at 0) | 5 |
    | compaction, odd node linked to its best match (level 0) | no | yes |
    | compaction, hierarchical, level-1 edge to its best match | no | yes |
    | resumed search, threshold -2 | returns a node scoring -2.5 | only nodes at or above -2 |

    Each new test fails on main and passes here. Full jvector-twenty, jvector-tests and jvector-native suites with main merged in, Ice Lake (8 cores), JDK 22: 740 tests, 0 failures.

    Normalized data is unaffected. On Ice Lake (32 cores), single-threaded 100k builds are byte-identical to main (cohere-english-v3 DOT_PRODUCT, sift EUCLIDEAN), and cohere-english-v3-1M build time, QPS and recall match main within the A/A spread. On Ice Lake (8 cores), cohere-english-v3-1M with PQ (128 subspaces) or ASH (1,064 bits) reranking returns identical results on main and here for all 10k queries, none with a negative approximate score.

    Callers that pass 0 as the threshold or rerank floor themselves keep dropping negative scores until they pass Float.NEGATIVE_INFINITY.

    Related: #860 (merged) fixed the diversity check for negative scores during graph construction and compaction.

    Diff: 623 lines (+467 / -156) across 7 files Reviewer: MarkWolters Review duration: 3948m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 623 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%
    56%
    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.385
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #848"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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.3% (MEDIUM) · Higher = larger blast radius
    50.3%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 21.8% · Safe to merge
    21.8%