Repository navigation
Cap RAPTOR UMAP n_neighbors to prevent OOM on large datasets - #16627
Conversation
n_neighbors = (N-1)**0.8 is unbounded; for dataset-scope RAPTOR over a large KB the first layer sees the full chunk count (e.g. ~93k -> ~9446), so UMAP's kNN graph alone runs to tens of GB and the task executor is OOM-killed inside fit_transform before any clustering runs, then re-queues and loops. Cap at 100 (UMAP's useful range; its own default is 15), matching the existing n_components=min(12, ...) clamp below and the 'Degrade too much ??' note above.
📝 WalkthroughWalkthroughThe UMAP ChangesRAPTOR Clustering Parameter Cap
Estimated code review effort: 1 (Trivial) | ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16627 +/- ##
==========================================
- Coverage 94.56% 93.16% -1.40%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 668 -10
- Misses 25 29 +4
- Partials 14 20 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Problem
raptor.pycomputesn_neighbors = int((len(embeddings) - 1) ** 0.8)andpasses it to
umap.UMAP(...). In a dataset-scope RAPTOR build the firstlayer's
embeddingsis the entire KB's chunk set, so this is effectivelyunbounded: ~93k chunks → n_neighbors ≈ 9,446.
UMAP's k-NN graph is
N × n_neighbors; at these values the raw neighborarrays alone are ~14 GB (93k × 9446 × 16 B), and the symmetrized fuzzy
simplicial set + spectral init push peak well past 30 GB. The task
executor is OOM-killed inside
fit_transformbefore any clustering runs —the log shows "Task has been received" with no "Cluster one layer" line —
after which the unacked task re-queues and OOMs again in a loop.
The line above already flags this:
# Degrade too much ??.Fix
Cap
n_neighborsat 100. UMAP's neighborhood size has stronglydiminishing returns well below this (default 15; a few dozen already
captures global structure), so the ceiling preserves — likely improves —
cluster quality while bounding memory to O(N). Mirrors the existing
n_components=min(12, len(embeddings) - 2)clamp two lines down.```diff
```
Repro
Dataset-scope RAPTOR over a KB with ~90k+ chunks on a box with <~64 GB
available: executor OOM-killed in the first-layer UMAP
fit_transform.With the cap, first-layer UMAP peaks in low single-digit GB and the build
proceeds to completion.
Scope
Only affects large dataset-scope builds; file-scope RAPTOR already had
n_neighbors well under 100. No behavior change beyond the ceiling.