Julenmendieta/MILAB-6501_handleHugeInputs - #7
Conversation
There was a problem hiding this comment.
Code Review
This pull request optimizes the embedding-clustering workflow to handle large inputs by switching to a streaming approach with IncrementalPCA, which avoids loading the full N x D matrix into RAM. It also replaces the scikit-learn HDBSCAN implementation with the contrib hdbscan package for improved performance and updates various dependencies. A high-severity issue was identified regarding an invalid pyarrow version in requirements.txt that needs to be corrected.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
PaulNewling
left a comment
There was a problem hiding this comment.
LGTM! Thanks for the walkthrough
Greptile Summary
This PR replaces the memory-bound full-SVD PCA + exact-vector deduplication + sklearn HDBSCAN pipeline with a constant-memory streaming architecture: two-pass IncrementalPCA over the parquet stream, contrib
hdbscan(dual-tree Boruvka MST, ~4× faster), and an identitydedup_mapping.tsv(dedup dropped asnp.uniqueover N×D cannot run at scale). A third stream pass populates a refinement store (RAM or disk memmap above 16 GiB) so recursive re-clustering still operates on the original D-dimensional vectors without holding the full matrix.Key touched terms and their changes:
hdbscan0.8.44) — Replacessklearn.cluster.HDBSCAN; enables the dual-tree Boruvka MST algorithm on low-dimensional post-PCA spaces (~4× faster). Cluster assignments shift slightly vs sklearn (both are valid HDBSCAN*).dedup_mapping.tsv— Was a many-to-one mapping (identical-vector deduplication). Now an identity mapping (representativeKey == clonotypeKey).np.uniqueover N×D cannot run at scale; kept for schema compatibility inprocess_results.py.run_clusteringthat re-PCAs a subset (from the refined store), re-clusters with HDBSCAN, assigns fresh global IDs vianext_id[0], and recurses into oversized children up tomax_depth = 3.Confidence Score: 4/5
Safe to merge; the core streaming logic is correct, boundary conditions are well-guarded, and the memmap cleanup uses a try/finally.
The streaming three-pass architecture is correct, the batch-boundary clonotype-split logic handles leftover rows properly, validation in the parquet assembler is thorough (bincount + NaN check + dim-range guard), and the memmap is cleaned up in a finally block even on error. The D naming collision in weighted_medoid and the absent fitted-guard in _reduce_subset's IncrementalPCA path are both practically unreachable under current defaults, but leave the code without defensive safeguards.
software/src/embedding_clustering.py around weighted_medoid and _reduce_subset; software/src/process_results.py line 46 (Python set construction) may matter at very large scale.
Important Files Changed
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant P as Parquet Input participant SR as stream_reduce participant IPCA as IncrementalPCA participant BRS as build_refined_store participant RC as run_clustering participant HDBSCAN as hdbscan.HDBSCAN participant WO as write_outputs P->>SR: Pass 1 - _stream_clonotypes (batch 4M rows) SR->>IPCA: partial_fit(chunk) per batch IPCA-->>SR: PCA basis SR->>SR: "k = pick_k_95(explained_variance_ratio, 95%)" P->>SR: Pass 2 - _stream_clonotypes (transform) SR->>IPCA: transform(chunk)[:, :k] SR-->>RC: Xr (N x k float32), keys (N,) RC->>RC: L2-normalize Xr to Xn RC->>HDBSCAN: fit(Xn[valid]) HDBSCAN-->>RC: labels, probabilities_ RC->>RC: compute oversized_main + refined_mask P->>BRS: Pass 3 - _stream_clonotypes (refined_mask only) BRS-->>RC: store (RAM array or disk memmap), gpos RC->>RC: split_recursive(oversized MAIN clusters) RC->>RC: split_recursive(noise rescue) if rescue-noise Note over RC: memmap freed in finally block RC->>RC: "cluster_medoids(Xn, labels, weights=probs)" RC-->>WO: rep_keys, cluster_id, distance WO->>WO: clusters.tsv (headerless) WO->>WO: dedup_mapping.tsv (identity mapping) WO->>WO: centroid_distances.tsv%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant P as Parquet Input participant SR as stream_reduce participant IPCA as IncrementalPCA participant BRS as build_refined_store participant RC as run_clustering participant HDBSCAN as hdbscan.HDBSCAN participant WO as write_outputs P->>SR: Pass 1 - _stream_clonotypes (batch 4M rows) SR->>IPCA: partial_fit(chunk) per batch IPCA-->>SR: PCA basis SR->>SR: "k = pick_k_95(explained_variance_ratio, 95%)" P->>SR: Pass 2 - _stream_clonotypes (transform) SR->>IPCA: transform(chunk)[:, :k] SR-->>RC: Xr (N x k float32), keys (N,) RC->>RC: L2-normalize Xr to Xn RC->>HDBSCAN: fit(Xn[valid]) HDBSCAN-->>RC: labels, probabilities_ RC->>RC: compute oversized_main + refined_mask P->>BRS: Pass 3 - _stream_clonotypes (refined_mask only) BRS-->>RC: store (RAM array or disk memmap), gpos RC->>RC: split_recursive(oversized MAIN clusters) RC->>RC: split_recursive(noise rescue) if rescue-noise Note over RC: memmap freed in finally block RC->>RC: "cluster_medoids(Xn, labels, weights=probs)" RC-->>WO: rep_keys, cluster_id, distance WO->>WO: clusters.tsv (headerless) WO->>WO: dedup_mapping.tsv (identity mapping) WO->>WO: centroid_distances.tsvPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "Changeset" | Re-trigger Greptile
Context used: