← Back to Pull requests

Compaction: find level-0 cross-source candidates by scanning cells instead of searching #740

Closed
unknown closed this pull request without merging on Oct 16, 2026 13:58 UTC
View on GitHub
unknown unknown commented on Oct 02, 2026 18:20 UTC
Author

Compaction: merge graphs with a cell join

Replaces the per-node graph search at level 0 with a scan over cells, so that cross-source candidates are found by streaming contiguous runs of vectors instead of walking each target graph once per node. The main goal is to address larger-than-memory compaction performance.

Scope: Compaction only, additive elsewhere

Nothing outside compaction changes behaviour, and nothing outside compaction has a line removed. Within compaction the merge is substantially rewritten, including a breaking constructor change, which the API section covers.

API change

The compactor now assigns its own output ordinals. Both constructors lose their List<OrdinalMapper> remappers parameter, and the mapping is published after the fact:

// before
new OnDiskGraphIndexCompactor(sources, liveNodes, remappers, similarityFunction, executor);
new OnDiskGraphIndexCompactor(sources, sourceCompressed, liveNodes, remappers, similarityFunction, executor);

// after
new OnDiskGraphIndexCompactor(sources, liveNodes, similarityFunction, executor);
new OnDiskGraphIndexCompactor(sources, sourceCompressed, liveNodes, similarityFunction, executor);

// and, once compact() has run:
List<OrdinalMapper> mappers = compactor.ordinalMappers();

This is a breaking change for callers that supplied their own mapping. It is required rather than cosmetic: the cell join needs output ordinals it chose itself, because locality in the output ordinal space is what makes a cell's members contiguous on disk and therefore readable in one sequential pass. A caller-supplied mapping cannot provide that.

Migration for a caller that previously passed OrdinalMapper.OffsetMapper: drop the argument, and read ordinalMappers() afterwards to learn where each source node landed. oldToNew of a deleted node is OrdinalMapper.OMITTED; live ordinals are dense.

compact(Path) and compact(Path, Path) are unchanged. setRefineAfterCompaction is gone, along with the refinement pass it gated.

Preconditions unchanged. Every source must still carry INLINE_VECTORS. Fused-PQ and PQ-sidecar sources are both supported, through the same entry points as before.

---

What changes inside the merge

Cells. The compactor's own upper-layer merge runs first, and its merged level-1 nodes become the cells. Every live node is assigned to the cell its vector descends to.

Ordinals in cell order. Output ordinals are handed out cell by cell, so one source's members of one cell occupy consecutive rows, and a cell is one sequential read.

A scan instead of a search. Each node names the cells it wants, ranked by a width-64 beam over the merged top layer and cut off at 4,096 vectors per larger source. Those requests are inverted so each cell is read once per group and scored against every node that asked for it.

Exactness. Candidate ordering is exact throughout. Approximation appears in exactly two places: which cells a node asks for, and the pairwise comparisons inside diversity selection, which run on vectors decoded from a wide PQ code. The wide code is measurably better there than exact comparisons, by 0.4 points, because coarse codes collide near-duplicates.

Reverse offers. Sources are processed smallest first; a node scans only larger sources and the reverse direction arrives as bounded offers, so the largest source scans nothing.

No system properties are introduced. Behaviour is fixed at the measured operating point: merged cells, probe beam 64, scan budget 4,096.

---

Results

Three datasets, four partitions each, degree 32, 64 threads, cold page cache per leg, no swap, one run at a time on a 32-physical-core host with 495 GB RAM and NVMe RAID 0. Memory is a cgroup v2 MemoryMax set as a fraction of the on-disk input index S. Ratio is S divided by that limit, so ratio above 1 means the index does not fit.

| dataset | dim | nodes | S (full precision) |
| --- | --- | --- | --- |
| CAP-6M | 1536 | 6,070,488 | 35.53 GiB |
| DPR-10M | 768 | 9,990,988 | 29.89 GiB |
| Cohere-10M | 1024 | 10,000,000 | 39.45 GiB |

Speedup over main

We use the main branch as our baseline. The table shows baseline compaction time divided by Cell Join compaction time.

| dataset | unconstrained | ratio 1.00 | ratio 1.33 | ratio 1.97 |
| --- | --- | --- | --- | --- |
| CAP-6M | 2.10x | 2.54x | est. 16x | est. 47x |
| DPR-10M | 2.58x | 3.05x | est. 28x | est. 76x |
| Cohere-10M | 2.63x | 2.50x | 9.72x | est. 40x |

Cell Join is faster at every setting measured, including with the whole host available. Values marked est. are legs where the baseline was stopped once it had run ten times the Cell Join wall time; their throughput is measured over the nodes completed and extrapolated, so they are lower bounds on the gap. 9.72x is the one above-RAM figure where both sides ran to completion.

Throughput, nodes per second

| dataset | method | unconstrained | 1.00 | 1.33 | 1.97 |
| --- | --- | --- | --- | --- | --- |
| CAP-6M | Cell Join | 7,462 | 6,369 | 6,148 | 6,018 |
| CAP-6M | main | 3,560 | 2,504 | 391 | 128 |
| DPR-10M | Cell Join | 11,836 | 8,978 | 8,995 | 8,527 |
| DPR-10M | main | 4,591 | 2,944 | 317 | 113 |
| Cohere-10M | Cell Join | 10,226 | 8,144 | 7,541 | 7,433 |
| Cohere-10M | main | 3,890 | 3,256 | 776 | 186 |

Cell Join varies by 1.24x to 1.39x across the whole memory range and tracks vector width rather than memory. The baseline falls by 20x to 41x.

Recall@10, and where it costs

Difference is Cell Join minus main, in points. Blank cells are settings where the baseline was stopped, so it produced no graph to measure.

| dataset | unconstrained | 1.00 | 1.33 |
| --- | --- | --- | --- |
| CAP-6M | -0.32 | -0.32 | baseline stopped |
| DPR-10M | -1.00 | -0.60 | baseline stopped |
| Cohere-10M | -0.99 | -0.98 | -0.85 |

Cell Join gives up 0.3 to 1.0 points of recall on full-precision inputs. The baseline's recall is identical to five decimals at every memory setting, so it is deterministic; Cell Join varies about 0.4 points run to run, from thread scheduling and a per-run wide-code retrain, which puts the smallest deficits inside its own noise.

Quantized inputs, ratio 1.33

| layout | dataset | speedup | recall delta |
| --- | --- | --- | --- |
| fused PQ | CAP-6M | 2.34x | +1.54 |
| fused PQ | DPR-10M | 4.58x | +1.00 |
| fused PQ | Cohere-10M | 2.37x | -0.23 |
| PQ sidecar | CAP-6M | est. 24.6x | baseline stopped |
| PQ sidecar | DPR-10M | est. 47.1x | baseline stopped |
| PQ sidecar | Cohere-10M | est. 20.3x | baseline stopped |

On fused inputs the recall deficit disappears, and the speedup shrinks, because the baseline can navigate on codes that are already resident. PQ sidecar is the opposite case and the worst one for the baseline: main only uses codes that are written inline, so a sidecar's codes are retrained and rewritten but never navigated on, and the write pass re-reads and re-encodes every source vector. It pays for them twice and uses them never.

Testing

Gate green, 27 tests, zero failures, zero errors, including a dotProductMulti kernel test against the scalar reference, a sidecar-parity recall assertion, and a near-duplicate merge test.

Requirements

When the cell join engages, cells come from the merged upper layers, so they need at least one source with a hierarchy. If no hierarchy, level 0 falls back to the existing per-node graph search. The merge is correct either way, only the level-0 strategy changes.

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