← Back to Pull requests

GraphSearcher: skip re-expanding evicted nodes on resume() #867

Closed
unknown closed this pull request without merging on Dec 03, 2026 05:19 UTC
View on GitHub
unknown unknown commented on Dec 02, 2026 06:10 UTC
Author

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 overqueried rerankK), 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.View returns true, and its subclasses false unless they override it. In-memory views keep false, since a graph being built can gain edges between calls.

  • At the start of each layer-0 call, GraphSearcher adds 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.

  • The set is cleared by search() and setView(). It holds node IDs that evictedResults already held.

  • Evicted nodes are added only if the calls that expanded them completed on the current view: a flag is set when a layer-0 call completes and cleared by setView(), search() and the start of each call. After a view switch or a call that throws, the next resume expands them again.

  • The candidate queue, pop order, stopping rules and visited counts are unchanged, so results are identical, ties included. Only expandedCount and expandedCountBaseLayer drop on resumes. A search without a resume pays one empty-set check per popped node.

  • Bytecode sizes stay in their inlining bands: searchLayer0 63 → 150, initializeInternal 121 → 133, setView 5 → 17, searchOneLayer 624 → 661 (already above 325). No Vector API code is touched.
  • Tests

    TestResumeSkipsExpandedNodes compares 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: after setView() to an in-memory view, expansion counts match the reference exactly.

  • resumeAfterViewSwitchExpandsEvictedNodes: after search() on the in-memory view and setView() to the on-disk one, the first resume expands what the reference does.

  • resumeAfterExceptionExpandsEvictedNodes and resumeAfterUpperLayerExceptionExpandsEvictedNodes: 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, noNodeIsExpandedTwice fails (3,822 layer-0 expansions for a 500-node graph) and resumeReturnsTheSameResults reports no skipped expansion. The full jvector-tests suite 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.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: MarkWolters Review duration: 1389m
    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
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #867"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 20.5% · Safe to merge
    20.5%