GraphSearcher: skip re-expanding evicted nodes on resume() #867
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 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.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #867"
general
weight: 0.35
MarkWolters
GraphSearcher.resume()pushes the nodes the last call evicted back into the candidate queue, and when one is popped it is expanded again: its neighbor list is read and every neighbor is checked. That call has already expanded it and marked all its neighbors visited, so on a graph whose neighbor lists cannot change the second expansion scores nothing. With Cassandra's pattern (resume(max(1, limit / 2), rerankK)with an overqueriedrerankK), most of a resume's expansions are such repeats: about 90% at limit 10 and 80% at limit 100 on cohere-wiki 1M.Change
ImmutableGraphIndex.View.neighborsAreFixed(), a new default method returning false;OnDiskGraphIndex.Viewreturns true, and its subclasses false unless they override it. In-memory views keep false, since a graph being built can gain edges between calls.GraphSearcheradds the nodes the last call evicted to a set, if that call had no threshold (a threshold search's score tracker can skip expansions) and the view's neighbor lists are fixed. A popped node in the set still goes through the accept and threshold checks and into the results as before; only its expansion is skipped.search()andsetView(). It holds node IDs thatevictedResultsalready held.setView(),search()and the start of each call. After a view switch or a call that throws, the next resume expands them again.expandedCountandexpandedCountBaseLayerdrop on resumes. A search without a resume pays one empty-set check per popped node.searchLayer063 → 150,initializeInternal121 → 133,setView5 → 17,searchOneLayer624 → 661 (already above 325). No Vector API code is touched.Tests
TestResumeSkipsExpandedNodescompares an on-disk graph (skip on) with the same graph searched in memory (skip off):resumeReturnsTheSameResults: every similarity function, flat and hierarchical graphs, filters of 100%, 70% and 10%, topK 1-10, rerankK 1-5× topK, Cassandra's halving pattern and a constant topK, 8 resumes per query. Nodes, scores and visited counts match call for call; the on-disk side never expands more and skips some expansions in every configuration.resumeWithRerankingReturnsTheSameResults: the same with PQ scores reranked exactly, as in Cassandra, with and without a rerank floor.resumeWithAdaptiveTerminationReturnsTheSameResults: the same with adaptive stopping.setViewForgetsExpandedNodes: aftersetView()to an in-memory view, expansion counts match the reference exactly.resumeAfterViewSwitchExpandsEvictedNodes: aftersearch()on the in-memory view andsetView()to the on-disk one, the first resume expands what the reference does.resumeAfterExceptionExpandsEvictedNodesandresumeAfterUpperLayerExceptionExpandsEvictedNodes: after a search that throws at layer 0 or in the upper layers, the next resume expands what the reference does.resumeAfterResumeExceptionExpandsEvictedNodes: after a resume that throws at any score, with and without adaptive stopping, the next resumes return what the reference does and expand no more.noNodeIsExpandedTwice: resuming until no node is left expands each node at most once at layer 0.thresholdSearchesAreUnchanged: with a threshold, results and expansion counts match the in-memory reference exactly.onlyOnDiskViewsReportFixedNeighbors, including that a subclass of the on-disk view must opt in.With the skip disabled,
noNodeIsExpandedTwicefails (3,822 layer-0 expansions for a 500-node graph) andresumeReturnsTheSameResultsreports no skipped expansion. The fulljvector-testssuite passes (781 run, 0 failures, 5 skipped).Results
GNR (48 cores), JDK 22,
numactl --interleave=all. cohere-wiki 1M (1,024 dimensions, DOT_PRODUCT), on-disk graph (degree 32, beam 100, hierarchy) with inline vectors for reranking, PQ (256 subspaces) for search. One thread, one reused searcher, warm page cache. Sides run main, PR, PR, main; means of the two runs. Result hashes were identical on both sides in every case.Cassandra's pattern,
search(limit, rerankK)then 5 ×resume(max(1, limit / 2), rerankK), rerankK 53 at limit 10 and 249 at limit 100 (1,000 queries):| Reader | limit | 5 resumes, main → PR | Whole query, main → PR |
|---|---|---|---|
| mmap (default) | 10 | 293 → 265 µs (−9%) | 698 → 655 µs (−6%) |
| mmap | 100 | 1,858 → 1,697 µs (−9%) | 3,117 → 2,929 µs (−6%) |
|
SimpleReader(a system call per read) | 10 | 3,382 → 672 µs (−80%) | 4,565 → 1,846 µs (−60%) ||
SimpleReader| 100 | 16,997 → 6,027 µs (−65%) | 21,825 → 10,861 µs (−50%) |A deep chain, 50 resumes per query, mmap (200 queries): −10% at limit 10 (2,746 → 2,484 µs of resumes) and −8% at limit 100 (17,786 → 16,306 µs).
search()with no resume, mmap (2,000 queries): 386 → 369 µs at limit 10 and 1,146 → 1,143 µs at limit 100, within run-to-run spread.mpnet 1M (768 dimensions, PQ 192 subspaces) and cap 1M (1,536 dimensions, PQ 384 subspaces), same build and method, mmap, 600 queries, 5 resumes. Expansions are per resume (resumes 2-5). The second pattern has no overquery: rerankK = limit and every resume asks for limit more.
| Dataset | Pattern | limit (rerankK) | Expansions per resume, main → PR | 5 resumes, main → PR | Whole query, main → PR |
|---|---|---|---|---|---|
| mpnet | Cassandra | 1 (12) | 12.1 → 1.0 | 52.5 → 46.6 µs (−11%) | 164 → 158 µs (−4%) |
| mpnet | Cassandra | 10 (53) | 53.2 → 4.9 | 251 → 230 µs (−8%) | 571 → 553 µs (−3%) |
| mpnet | Cassandra | 100 (249) | 249.1 → 50.0 | 1,711 → 1,610 µs (−6%) | 2,856 → 2,786 µs (−2%) |
| cap | Cassandra | 1 (12) | 12.2 → 1.0 | 67.5 → 62.8 µs (−7%) | 250 → 252 µs (+1%) |
| cap | Cassandra | 10 (53) | 53.2 → 5.0 | 342 → 312 µs (−9%) | 862 → 831 µs (−4%) |
| cap | Cassandra | 100 (249) | 249.1 → 50.0 | 2,352 → 2,222 µs (−6%) | 4,137 → 4,007 µs (−3%) |
| mpnet | no overquery | 10 (10) | 10.3 → 9.8 | 276 → 269 µs (−2%) | 391 → 383 µs (−2%) |
| mpnet | no overquery | 100 (100) | 100.1 → 99.8 | 2,252 → 2,257 µs (0%) | 2,787 → 2,796 µs (0%) |
| cap | no overquery | 10 (10) | 10.3 → 9.8 | 548 → 544 µs (−1%) | 778 → 772 µs (−1%) |
| cap | no overquery | 100 (100) | 100.2 → 99.9 | 3,068 → 3,166 µs (+3%) | 3,870 → 3,989 µs (+3%) |
Without overquery a call returns nearly everything it holds, so few nodes are evicted and there is little to skip. The cap limit-10 row is a re-run of three alternating main/PR pairs; its first run showed +11% with the same expansion counts, which was run-to-run variance. The cap limit-100 row was not re-run.
In-memory graphs keep the skip off, so building one is unaffected: mpnet 1M built in 26.8 s on main and 26.5 s with the PR (means of three alternating runs).
In a deployed Cassandra node (CC on JVector 4.1.0-rc.2 plus this change, cohere-wiki 1M with 90% or 99% of rows deleted, so queries resume 8-200 times), the change removed 68-91% of the expansions inside resumes and cut query time by 3-11%, with identical rows in every batch.