GraphSearcher: keep negative DOT_PRODUCT scores, and the threshold, across resume() #848
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
MarkWolters
Fixes #847.
As #813 explains, a threshold or rerank floor of
0.0fis meant to accept everything, but DOT_PRODUCT scores are(1 + dot) / 2, negative wheneverdot < -1, routinely for vectors that are not unit length. #714, #814 and #820 replaced0.0fwithNEGATIVE_INFINITYinGraphSearcher.internalSearchandGraphIndexBuilder; this PR fixes the five places they missed and the docs, examples and benchmark harnesses that still passed0.0f. It also makesresume()keep the threshold of the search it continues.Change
GraphSearcher:resume(additionalK, rerankK), the rerank floor ofsearch(scoreProvider, topK, threshold, acceptOrds)and the staticsearch(queryVector, topK, rerankK, ...)useFloat.NEGATIVE_INFINITY.OnDiskGraphIndexCompactor: its searches of the other sources (level 0, the upper-layer descent and the level search) useFloat.NEGATIVE_INFINITY.GraphSearcher: each layer-0 search saves its threshold andresume(additionalK, rerankK)applies it, for every similarity function. The rerank floor is still not carried over, as the existing comment onsearchOneLayerexplains.GraphSearcherthreshold parameters no longer describe scores as 0..1 or 0 as "accept everything";Float.NEGATIVE_INFINITYaccepts every node, and 0 does only for exact EUCLIDEAN and COSINE scores.rerankFloornotes thatNEGATIVE_INFINITYreranks every candidate, andresumeand 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.0.0f, 0.0f(docs, tutorials, examples,QueryExecutor,CompactionBench, JMH benchmarks) passFloat.NEGATIVE_INFINITY.tuning.mdstates the rule and documentsrerankFloor;choosing-an-index.mdlists each similarity's score range. Tests on unit, COSINE or EUCLIDEAN data keep 0, which is valid there.threshold > 0, so adaptive stopping and bounded candidates are unaffected.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 staticsearchdoes the same; with a reranker, oneresume(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-testsandjvector-nativesuites 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
0as the threshold or rerank floor themselves keep dropping negative scores until they passFloat.NEGATIVE_INFINITY.Related: #860 (merged) fixed the diversity check for negative scores during graph construction and compaction.