← Back to Pull requests

Reconnect nodes left unreachable by cleanup() #805

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 20, 2026 20:48 UTC
Author

Fixes #804.

What

GraphIndexBuilder.cleanup() now repairs nodes that pruning left unreachable from the entry node in layer 0, as reconnectOrphanedNodes() did before it was removed in #402.

After enforceDegree(), each unreachable node gets an in-edge from the closest reachable neighbor it already links to, or, if none is usable, from the best reachable search result that is not yet a connection target. The edge goes through the existing ConcurrentNeighborMap.insertEdgeNotDiverse(), which evicts the target's worst neighbor, so the degree cap still holds. Because an eviction can orphan another node, this repeats for up to five passes and stops early when a pass reconnects nothing.

Details that matter, several of them found by mutation testing the first version of this PR (PIT, then hand-applied mutants):

  • Fallback search accepts only reachable nodes. With a hierarchy the search enters layer 0 through the upper layers and can return other unreachable nodes; linking from one of those reconnects nothing.

  • Threshold is Float.NEGATIVE_INFINITY, not 0.0f, for the search and its resumes. DOT_PRODUCT scores are (1 + dot) / 2, negative for non-normalized vectors, as GraphSearcher.internalSearch already handles.

  • One repair per partition, not per node. Orphans are processed one at a time and everything a linked orphan reaches is marked reachable, so a large unreachable partition costs one edge instead of one edge per node (which five passes could not get through when few reachable targets existed).
  • insertEdgeNotDiverse is exposed on the package-private MutableGraphIndex interface (one implementor, OnHeapGraphIndex). No public API changes.

    This is a port adapted to the current layer/view API, not a restore of the old code.

    Results

    Nodes unreachable from the entry node after cleanup(), main vs this branch (JDK 26, macOS arm64, Panama provider):

    | Build | main | this branch |
    |---|---|---|
    | 100k x 1024-d, cosine, M=32, beam=100, flat (two runs) | 55, 45 | 0, 0 |
    | 100k x 1024-d, M=16, beam=200 | 856 | 0 |
    | 50k x 128-d | 4 | 0 |
    | 600 x 32-d uniform, M=8, beam=16, 20 seeds, flat and hierarchical (reproducer in #804) | 20 of 20 graphs affected | 0 |
    | 600 x 32-d uniform, 20 seeds, flat: nodes that never return themselves when queried with their own vector (k=10, rerankK=200) | 205 of 12,000 | 20 |
    | same, hierarchical | 193 of 12,000 | 23 |
    | 1600 x 2-d, 8 tight clusters, M=8, 6 seeds, flat: layer-0 reachable / never return themselves | 4,937 / 5,440 of 9,600 | 9,600 / 2,395 |
    | same, hierarchical | 2,398 / 10 of 9,600 | 9,600 / 3 |
    | 200 x 2-d DOT_PRODUCT around (10, 0) plus one (-10, 0) inserted at positions 25, 50, 100, 150, 200 | the odd node unreachable at all five | reachable at all five |

    Cost: cleanup() on the 100k x 1024-d build took 601 and 656 ms on main and 722 and 780 ms on this branch (the machine was busy, so treat as order of magnitude; the repair is a single-threaded reachability walk plus one search per unreachable partition).

    Randomized fuzzer (random dimension, M, beam, overflow, alpha, similarity function, hierarchy, parallel vs sequential build, duplicates, two waves of deletions with cleanup() after each), 300 graphs: no exceptions and no structural violations (degree bound, self or duplicate edges, edges to deleted nodes, entry node validity) on any version. Unreachable nodes: 26,977 in 202 graphs on main, 51 in 11 graphs on this branch; exhaustive-beam searches returning too few or worse results: 292 on main, 5 here. What remains is mostly M=2 graphs.

    Tests

  • testCleanupLeavesEveryNodeReachable: 600 x 32-d uniform, M=8, six seeds, flat and hierarchical.

  • testCleanupReconnectsDisconnectedClusters: 1200 x 2-d points in 8 tight clusters, six seeds, flat and hierarchical.

  • testCleanupReconnectsNodeWithOnlyNegativeSimilarities: the DOT_PRODUCT case above.
  • Each fails without the corresponding change (the cluster test on the previous version of this PR: 296 of 1200 reachable for the hierarchical seed 0; the dot-product test: 200 of 201) and passes with it. The first one fails with reconnectOrphanedNodes() removed (599 of 600).

    Also run on this branch, all green (116 tests, 2 skipped as before): GraphIndexBuilderTest, TestVectorGraph, TestDeletions, OnHeapGraphIndexTest, Test2DThreshold, TestHierarchyDotProductSearch, TestLowCardinalityFiltering, TestConcurrentReadWriteDeletes, TestConcurrentBufferedGraphConstruction, TestOnDiskGraphIndex, TestOnDiskGraphIndexCompactor, TestBufferedGraphCompatibility, TestGraphIndexBuilderConfig, TestNeighbors, TestPruningCompatibility, TestBuildScoreProviderAnchorReads, TestBuildScoreProviderBorrowedVectors, TestFusedGraphIndex. I did not run the full suite or the native module.

    Known limits

  • Layer 0 only; upper layers are not repaired, matching what the original code did.

  • Reachable is not the same as findable. Layer-0 reachability from the entry node is exactly what a flat graph's search sees, but a hierarchical search enters layer 0 from the upper layers, so in the tight-cluster case almost nothing was lost on main (10 of 9,600 nodes never return themselves, despite 7,202 being unreachable in layer 0); and in the flat cluster case, with every node reachable, 2,395 of 9,600 still do not return themselves with k=10, rerankK=200, so reconnecting does not make weakly connected clusters fully searchable, only reachable.

  • Reachability and the repair loop are single-threaded. At 100k nodes this is small next to the rest of cleanup(); a graph with very many separate unreachable partitions would cost one search each. I have not measured 1M+ nodes.

  • With a very small degree (M=2) a few unreachable nodes can remain after five passes.

  • The builder still searches with a threshold of 0.0f in addGraphNode and improveConnections (existing code, not changed here). With non-normalized DOT_PRODUCT data this can leave a graph badly fragmented before cleanup() runs, which this PR then repairs, but it is better not to create the fragmentation; I will file that separately.

  • Measured on one machine, Apple silicon, Panama provider. Not tried on x86 or the native provider.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: MarkWolters Review duration: 2813m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). 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.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #805"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 27.7% · Safe to merge
    27.7%