← Back to Pull requests

Reconnect nodes left unreachable by cleanup() #863

Closed
unknown closed this pull request without merging on Dec 01, 2026 00:47 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 22:13 UTC
Author

Fixes #804. Supersedes #805, building on its analysis and on tae898's churn program.

Background

A graph index can only return what a search can reach. Pruning — degree enforcement in cleanup() and backlink pruning during builds — can drop a node's last incoming edge and strand it. JVector repaired this with reconnectOrphanedNodes() (#138, tuned in #208, #335 and #359) until #402 removed it with the hierarchy change. Since then nothing checks: on real 1M-vector datasets at degree 32 we find 13 to 739 stranded nodes per graph at the default overflow, about 8,400 at overflow 1.0, up to 11,000 at degree 16, and more after every round of deletes (#804).

There are three ways to fix it. Guarding every prune against dropping a last in-edge puts a cost on the hot path of every insertion. Restoring the old repair, as #805 does, links each stranded node from a nearby reached node and evicts that node's worst edge; an eviction can strand others, so reachability must be recomputed after each one, which grows quadratically (#805's cleanup() passed 500 s on cohere-10M and was cancelled), and it covers layer 0 only. The third is to repair once, after pruning, in a way that cannot strand anything: the spanning-tree idea NSG uses at build time. TSOR takes that route and makes it safe to apply to a finished, degree-capped graph.

TSOR: Tree-Safe Orphan Reconnect

At the end of cleanup(), for each layer from the top down:

1. Walk. A parallel walk from the entry node marks every reachable node and records the edge it was first reached by. These edges form a spanning tree T.
2. *Reinsert each unreached node u.
-
In: edges to u from the reached nodes u already links to (found with the vector it was inserted with), and from the diverse members, by the build's alpha rule, of a search for u among reached nodes.
-
Out: edges from u back to the nodes that now link to it, so a search that enters u's group can leave it.
-
Room: a full list gives up an edge that u makes redundant under the same alpha rule; only u's first link in, and first link out, may fall back to the farthest edge. A reached node never gives up an edge of T.
3. Resume the walk from
u, which reaches its whole group.

Each layer is repaired the same way, with its own tree, so a search for a node in an upper layer descends through layers already repaired, as insertion's does, and no node moves between layers.

The searches for a batch of unreached nodes run in parallel; the edges are added one node at a time.

Guarantees.

  • Reachability. Every node, in every layer, is reachable from the entry node after cleanup(). (A node no reached node can take is logged; it has not occurred in any test, fuzz run or benchmark.)

  • No collateral damage. No reached node loses its path: edges of T are never removed, and an unreached node's own edges lie on no reached node's path.

  • One linear pass. Nothing is recomputed: one walk per layer plus one search per unreached group (1.9 s on cohere-10M, 8 cores).

  • Shape preserved. The degree cap holds, no node changes layer, and new edges follow the build's own diversity rule wherever a full list allows.

  • A way out. Every node the repair links in also links back to the reached region.

  • Any scores.* It uses only the builder's BuildScoreProvider, so full precision, PQ, ASH, BQ and byte vectors, flat or hierarchical, all work the same way. It adds MutableGraphIndex.replaceEdge (fill a free slot, or swap one edge for another).
  • Reachable is not the same as findable: TSOR guarantees the first and, through its diverse links and ways out, makes the second likely; the results below measure both.

    Scope

    The repair runs at the end of cleanup(), after cleanup() has removed the nodes marked deleted, so a graph that is cleaned up after deletes ends with every node reachable. removeDeletedNodes() called on its own, without cleanup(), can still leave nodes unreachable (reported on #805); it also skips cleanup()'s other steps, such as degree enforcement. Repairing that path needs its own policy and is left to a separate change.

    OnDiskGraphIndexCompactor does not go through the builder, so merged indexes are not repaired either.

    Turning it off

    -Djvector.reconnectOrphans=false, or GraphIndexBuilderConfig.getInstance().setReconnectOrphans(false) (also over JMX). The setting is experimental and defaults to true. Each builder reads it once when created.

    Results

    Measured on the TSOR code before the merge with current main (#858, which changes PQ diversity scoring) and the change that followed it ("never hold two diversity score functions"). Repair time and allocation on the final commit, checked on Granite Rapids (48 cores) and Ice Lake (32 cores) with full-precision and PQ build scores, are the same within run-to-run variation (PQ: 440 vs 442 ms on Ice Lake; 340–456 ms either way on Granite Rapids).

    1M vectors, degree 32, beam 100, alpha 1.2, overflow 1.2, hierarchy on unless noted. Each row repairs the graph it just built, so before and after differ only by the repair. Recall@10 over 10k queries with the dataset's ground truth. "Repaired nodes found": a repaired node is returned by a search for its own vector (sampled to 200 where marked); "Ordinary nodes found": the same for 10,000 random nodes. Every row ends with 0 unreachable nodes.

    JDK 25:

    | Hardware | Dataset (dims) | Build scores | Unreachable before (layer 0 / above) | Recall@10 before → after | Repaired nodes found | Ordinary nodes found | Repair (s) |
    | --- | --- | --- | --- | --- | --- | --- | --- |
    | Ice Lake (8 cores) | non-public (384) | full precision | 21 / 0 | 0.9578 → 0.9578 | 21/21 | 99.87% → 99.87% | 0.26 |
    | Ice Lake (8 cores) | non-public (384) | PQ | 150 / 0 | 0.9472 → 0.9472 | 145/150 | 99.69% → 99.71% | 0.51 |
    | Ice Lake (8 cores) | non-public (384) | ASH | 38 / 0 | 0.9552 → 0.9552 | 38/38 | 99.83% → 99.83% | 0.25 |
    | Ice Lake (8 cores) | non-public (384) | int8 | 25 / 0 | 0.9574 → 0.9574 | 25/25 | 99.86% → 99.86% | 0.24 |
    | Ice Lake (8 cores) | non-public (384) | BQ | 1,820 / 3 | 0.8333 → 0.8335 | 64/200 | 92.23% → 92.33% | 1.20 |
    | Ice Lake (8 cores) | non-public (384), flat | full precision | 23 | 0.9575 → 0.9575 | 23/23 | 99.91% → 99.91% | 0.25 |
    | Ice Lake (8 cores) | cohere (1024) | full precision | 43 / 0 | 0.9609 → 0.9609 | 42/43 | 99.75% → 99.77% | 0.27 |
    | Ice Lake (8 cores) | cohere (1024) | PQ | 53 / 0 | 0.9621 → 0.9623 | 52/53 | 99.84% → 99.84% | 0.28 |
    | Ice Lake (8 cores) | cohere (1024) | ASH | 72 / 0 | 0.9555 → 0.9556 | 68/72 | 99.74% → 99.77% | 0.27 |
    | Graviton (16 cores) | ada-002 (1536) | full precision | 63 / 1 | 0.9866 → 0.9866 | 63/63 | 99.95% → 99.96% | 0.20 |
    | Graviton (16 cores) | ada-002 (1536) | PQ | 256 / 6 | 0.9863 → 0.9863 | 113/200 | 99.97% → 99.97% | 0.35 |
    | Graviton (16 cores) | ada-002 (1536) | ASH | 714 / 1 | 0.9812 → 0.9814 | 147/200 | 99.71% → 99.77% | 0.47 |
    | Graviton (16 cores) | cohere (1024) | full precision | 35 / 0 | 0.9597 → 0.9597 | 34/35 | 99.80% → 99.80% | 0.14 |
    | Graviton (16 cores) | cohere (1024) | PQ | 58 / 0 | 0.9615 → 0.9615 | 52/58 | 99.68% → 99.71% | 0.23 |
    | Graviton (16 cores) | cohere (1024) | ASH | 77 / 0 | 0.9561 → 0.9561 | 73/77 | 99.73% → 99.73% | 0.17 |
    | Granite Rapids (48 cores) | non-public (384) | full precision | 14 / 0 | 0.9572 → 0.9572 | 14/14 | 99.95% → 99.95% | 0.34 |
    | Granite Rapids (48 cores) | non-public (384) | PQ | 142 / 0 | 0.9473 → 0.9473 | 139/142 | 99.66% → 99.69% | 0.34 |
    | Granite Rapids (48 cores) | ada-002 (1536) | PQ | 184 / 4 | 0.9859 → 0.9859 | 114/184 | 99.95% → 99.95% | 0.43 |

    JDK 22 gave the same picture (0 unreachable, recall unchanged or +0.0002): non-public set full precision, PQ and ASH on Ice Lake (8 cores), and ada-002 full precision, PQ and ASH on Graviton (16 cores).

    Overflow 1.0 (degree 32, full precision, non-public set):

    | Hardware | Unreachable before | After | Recall@10 before → after | Ordinary nodes found | Repair (s) | cleanup() without repair (s) |
    | --- | --- | --- | --- | --- | --- | --- |
    | Ice Lake (8 cores) | 8,304 / 32 | 0 | 0.9398 → 0.9401 | 98.02% → 98.83% | 5.94 | 5.67 |
    | Granite Rapids (48 cores), 2 runs | 5,101 / 38, 5,057 / 55 | 0 | +0.0001, +0.0002 | 98.39% → 99.06%, 98.99% | 2.47, 2.51 | 1.16, 1.22 |

    At overflow 1.0, most of the repair time is adding edges, which runs on one thread to stay tree-safe; the searches take most of the rest. Choosing evictions in the parallel phase is a possible follow-up.

    10M vectors (cohere, 1024 dims, degree 32, beam 100, hierarchical; Ice Lake (8 cores), JDK 25): insertion 1,969 s, cleanup() without the repair 185 s, and the repair 1.9 s (+1.0%), taking 285 unreachable nodes in layer 0 to 0; 276 of the 285 are found by a search for their own vector, and recall@10 stays at 0.9287.

  • Memory: the repair keeps three bitsets and a parent array while it runs (4.3 MB at 1M) and frees them. Temporary allocation during the repair: 31–66 MB per 1M build (up to 116 MB for ada-002 with PQ on Granite Rapids), 74–147 MB at overflow 1.0, and 467 MB at 10M.

  • Query speed (cohere-1M, degree 32, Ice Lake (8 cores), the same graph before and after repairing its 29 unreachable nodes; 8 pinned threads, 150k unseen queries per JVM, 4 ABBA pairs plus an A/A pair): nodes visited and expanded per query were identical (1,997.92 and 109.25). QPS ranged 5,958–6,764 without the repair and 6,114–6,487 with it, the same run-to-run modes either way; p50 1.20–1.23 ms and 1.20–1.25 ms, p99 1.71–1.75 ms and 1.71–1.80 ms.
  • Delete churn

    tae898's program (from #805): 10,000 live rows of 768-dimensional vectors in 8 tight clusters, 150,000 row versions replaced over 150 rounds, removeDeletedNodes() at 20% marked, cleanup() at each of 16 checkpoints; degrees 32 and 16, beam
    200. "Lost": live rows a search for their own vector does not return (k=10, rerankK=100), right after cleanup(). Median of 3 runs per seed, range in parentheses where the runs differ (the churn path adds random edges, so runs differ; see Known limitations). Ice Lake (8 cores), JDK 25.

    | After cleanup() | | Seed 1 | Seed 2 | Seed 3 |
    |---|---|---|---|---|
    | Worst-checkpoint lost rows | main | 5,475 | 1,351 | 1,042 |
    | | #805 | 618 | 375 (350–387) | 327 (323–327) |
    | | this PR | 376 | 627 (627–702) | 249 |
    | Lowest mean recall@10 | main | 0.446 | 0.861 | 0.845 |
    | | #805 | 0.851 | 0.891 (0.886–0.891) | 0.893 (0.892–0.894) |
    | | this PR | 0.948 | 0.915 (0.910–0.915) | 0.956 |
    | Most nodes unreachable, any layer | main | 1,917 | 996 | 1,574 |
    | | #805 | 68 | 34 | 23 |
    | | this PR | 0 | 0 | 0 |
    | Lost rows, summed over the 16 checkpoints | main | 11,915 | 6,585 | 5,485 |
    | | #805 | 2,656 (2,515–2,832) | 2,674 (2,456–2,720) | 2,508 (2,402–2,525) |
    | | this PR | 1,690 | 1,676 (1,661–1,770) | 1,528 |

    Seed 2's worst checkpoint (14) is where the runs' histories differ most: the graph cleanup() receives there differs between builds and between runs. Repairing the same saved graph with each change compares them directly:

    | Seed 2, same graph | Lost before | Lost after: main / #805 / this PR | Recall@10 after | Unreachable after |
    |---|---|---|---|---|
    | Checkpoint 9 | 652 | 666 / 126 / 97 | 0.905 / 0.920 / 0.962 | — / 9 / 0 |
    | Checkpoint 14 | 996 | 1,265 / 848 / 630 | 0.870 / 0.882 / 0.915 | 995 / 34 / 0 |

    Compared with #805

    #805's builds plus three 1M datasets, with #805 applied to current main. JDK 26.0.2.1, macOS arm64 (12 cores),
    Panama provider. Each graph was built once with the repair off and saved; main is that graph, and #805 and this PR each repair the same saved graph. The small builds insert sequentially, as #804's reproducer does. Counts are summed over seeds.

    1. Nodes unreachable from the entry node after cleanup(), all layers (lower is better)

    | Build | main | #805 | this PR |
    |---|---|---|---|
    | 600 x 32-d uniform, M=8, beam=16, 20 seeds, flat (reproducer in #804) | 188 | 0 | 0 |
    | same, hierarchical | 177 | 2 | 0 |
    | 1600 x 2-d, 8 tight clusters, M=8, beam=30, 6 seeds, flat | 4,663 | 0 | 0 |
    | same, hierarchical | 7,202 | 0 | 0 |
    | 200 x 2-d DOT_PRODUCT around (10, 0) plus one (-10, 0) at positions 25, 50, 100, 150, 200 | 843 | 0 | 0 |
    | 50k x 128-d, cosine, M=32, beam=100, flat | 6 | 0 | 0 |
    | 100k x 1024-d, cosine, M=32, beam=100, flat | 76 | 0 | 0 |
    | same, hierarchical | 88 | 1 | 0 |
    | 100k x 1024-d, cosine, M=16, beam=200, flat | 1,163 | 0 | 0 |
    | non-public dataset (384-d), 1M, DOT_PRODUCT, M=32, beam=100, hierarchical | 18 | 0 | 0 |
    | cohere (1024-d), 1M, same settings | 48 | 0 | 0 |
    | ada-002 (1536-d), 982,790 vectors, same settings | 64 | 2 | 0 |

    #805 repairs layer 0 only; the nodes it leaves are in layer 1.

    2. Nodes unreachable on main that a search for their own vector returns (higher is better)

    | Build | #805 | this PR |
    |---|---|---|
    | 600 x 32-d uniform, 20 seeds, flat | 187 of 188 | 188 of 188 |
    | same, hierarchical | 174 of 175 | 175 of 175 |
    | 1600 x 2-d clusters, 6 seeds, flat | 3,349 of 4,663 | 3,101 of 4,663 |
    | same, hierarchical | 7,199 of 7,202 | 7,202 of 7,202 |
    | 50k x 128-d | 6 of 6 | 6 of 6 |
    | 100k x 1024-d, M=32, flat | 74 of 76 | 76 of 76 |
    | same, hierarchical | 86 of 87 | 86 of 87 |
    | 100k x 1024-d, M=16 | 1,137 of 1,163 | 1,144 of 1,163 |
    | non-public dataset (384-d), 1M | 17 of 18 | 18 of 18 |
    | cohere (1024-d), 1M | 17 of 48 | 47 of 48 |
    | ada-002 (1536-d), 1M | 36 of 62 | 62 of 62 |

    On main, almost none of these nodes is found. The DOT_PRODUCT case is left out: with unnormalized vectors a node is rarely the best match for its own vector, so this count says nothing there. Recall@10 on the 1M sets is the same for all three (0.9576, 0.9608, 0.9864).

    3. Time the repair adds to cleanup() (12-core laptop; small builds summed over seeds, each in a fresh JVM)

    | Build | #805 | this PR |
    |---|---|---|
    | 600 x 32-d uniform, 20 seeds, flat | 91 ms | 100 ms |
    | same, hierarchical | 92 ms | 105 ms |
    | 1600 x 2-d clusters, 6 seeds, flat | 71 ms | 92 ms |
    | same, hierarchical | 37 ms | 234 ms |
    | 200 x 2-d DOT_PRODUCT, 5 positions | 98 ms | 96 ms |
    | 50k x 128-d | 54 ms | 55 ms |
    | 100k x 1024-d, M=32, flat | 1.46 s | 0.16 s |
    | same, hierarchical | 1.29 s | 0.16 s |
    | 100k x 1024-d, M=16 | 8.97 s | 0.90 s |
    | non-public dataset (384-d), 1M | 5.41 s | 0.22 s |
    | cohere (1024-d), 1M | 10.35 s | 0.22 s |
    | ada-002 (1536-d), 1M | 16.92 s | 0.21 s |

    Known limitations:

  • With BQ build scores at 384 dimensions, a repaired node is found by a search for its own vector only 32% of the time. Every node is reachable and recall does not drop, but BQ-scored graphs are weak at this size (ordinary nodes are found 92% of the time, recall 0.83), and the search for a repaired node lands the same way.

  • removeDeletedNodes() adds random edges, unseeded, when every replacement for a node's edges was itself deleted, so delete churn differs from run to run (on main as well); the churn results above are medians.

  • A node the repair links in always gets a way back out; a node reached only through it is not guaranteed its own.
  • Tests

    GraphIndexBuilderTest:

  • Pruning orphans: the same graph built twice with the switch off and on, sequentially so both builds match. Shows pruning leaves nodes unreachable, then that none remain in any layer, also for parallel builds, flat and hierarchical.

  • Separated clusters in 16 dimensions: every node reachable, and a search for each cluster's center lands in it.

  • A group cut off on both sides: reconnected, and every group node an outside node links to has a way back out.

  • The same graph and cut, built twice on one thread: once with ordinary build scores, once through a provider that gives each thread one diversity score function and repoints it on every call (as PQ build scores do since #858). cleanup() must leave identical graphs, which holds only if the repair never holds two such functions at once.

  • Unnormalized dot products with outliers pointing away from the rest: most of the graph is unreachable without the repair, and its hub lists fill with tree edges; with it, every node is reachable.

  • Nodes with all in-edges cut, in layer 0 and in layer 1; a closed cluster under an upper-layer node; full-precision, PQ, ASH and BQ build scores and an ordinal-mapped graph, flat and hierarchical; byte-vector graphs; a graph rescored partway through its build; rounds of deletes; a one-node graph; the switch turned off.
  • TestNeighbors.testReplaceEdge covers replaceEdge. All pass on JDK 22 and 25 (Ice Lake (8 cores), Granite Rapids (48 cores), Graviton (16 cores)), together with TestPQDiversityDecoding.

    Randomized graphs: 20,000 random configurations, each built from the same vectors with the repair off (main) and on: n from 1 to 400, dimension 1 to 70, all three similarity functions (unnormalized vectors in a third of the eligible ones), M from 2 to 33, beam 1 to 120, alpha 1.0 to 1.4, flat and hierarchical, exact duplicates in some, 1 to 4 build threads, and random deletions before cleanup() in some. After cleanup() each graph is checked for structure (live count, entry node, degree cap, no self or duplicate edges, no edges to deleted or missing nodes) and for nodes unreachable in each layer, and 5 searches with rerankK at least the live node count must return exactly the top-k by exact score. JDK 25, Ice Lake (8 cores):

    | Failure | main | this PR |
    |---|---|---|
    | Configurations with any failure | 4,323 | 0 |
    | Nodes unreachable in layer 0 | 4,279 | 0 |
    | Nodes unreachable above layer 0 | 881 | 0 |
    | Exhaustive search not the exact top-k | 2,202 | 0 |
    | Exhaustive search returns too few results | 268 | 0 |
    | Structure violations or exceptions | 0 | 0 |

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: MarkWolters Review duration: 153m
    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 #863"
    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%