Repository navigation
feat(graph): export graphs as csr arrays and maintain lance datasets - #187
Merged
Merged
Conversation
Add CypherEngine.export_graph, which returns the graph as dense CSR arrays for graph-algorithm libraries such as icebug, and write_node_column (Python), which merges per-node results back into the Lance node tables. Add optimize_datasets, which compacts the engine's Lance datasets, moves the engine onto the result and then deletes old versions. The Node package gets exportGraph, documented for drawing the whole graph, and optimizeDatasets.
Deploying lance-csr with
|
| Latest commit: |
0779829
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://566c9dd6.lance-csr.pages.dev |
| Branch Preview URL: | https://feat-graph-export.lance-csr.pages.dev |
prrao87
marked this pull request as ready for review
November 21, 2026 19:14
prrao87
added a commit
that referenced
this pull request
Nov 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Running a graph algorithm such as PageRank or connected components on lance-csr data meant pulling every edge into Python and handing it to a library like networkx. That's slow, and each user had to rebuild the same node numbering. Libraries such as icebug, igraph and scipy all take a graph as compressed sparse rows (CSR) over dense node ids, so lance-csr can build that form once, in Rust, from the same dataset versions its queries see.
Exporting the graph raises two more problems, and this PR solves both:
write_node_columndoes that in one call and moves the engine onto the new versions, so the next Cypher query can sort or filter by the result.optimize()fail with a commit conflict.optimize_datasetscompacts each dataset from its newest version, moves the engine onto the result, and only then deletes old versions, so neither failure can happen.What changed
CypherEngine.export_graph(rel_types=None, *, directed=True)returns aGraphExportof pyarrow arrays:out_indptr/out_indices,in_indptr/in_indicesfor directed graphs,node_keysmapping dense ids back to keys, andlabel_ranges. It scans only the key and endpoint columns, gives each label its own id range, and deduplicates and sorts edges with a parallel packed-key sort. icebug'sGraph.fromCSRtakes the arrays without copying.CypherEngine.write_node_column(export, column, values, *, overwrite=False)(Python only) splits the values by label, pairs them with the keys and runs Lance'smergeinto each node table, then pins the engine to the new versions. Existing columns needoverwrite=True; key columns and in-memory Arrow tables are refused.CypherEngine.optimize_datasets(*, cleanup_older_than=None)compacts every Lance dataset the engine reads, starting from the newest version, moves the engine onto the result, and only then deletes versions older than the window (7 days by default, as in LanceDB). It works the same for pylance datasets and LanceDB tables and returns per-dataset statistics. Lance indexes aren't updated.exportGraph, documented for drawing the whole graph in a browser (dense ids and link pairs for GPU renderers), andoptimizeDatasets.writeNodeColumnis deliberately left out of Node.Performance
End to end, from reading Lance to a results table, on a 100,000 node, 2.4 million edge graph (FOLLOWS from graph-benchmark), icebug through this PR against networkx 3.7:
On the lance-csr side, opening the engine takes about 0.035 s and
export_graphabout 0.05 s; the rest is icebug. PageRank matches networkx to within 4e-10 and components give the same partition. Louvain compares two different implementations (modularity 0.121 vs 0.122), so its communities aren't identical.At 4 million nodes and 69 million edges (synthetic, hubs in the first rows), networkx wasn't run: at its ~590 bytes per edge above it would need about 40 GB on this 24 GB machine. Against the prototype that built the CSR with numpy:
The export alone drops from about 8 s to 2.1 s. Opening the engine is a one-time cost when the same engine serves queries.
Measured on an Apple M5 (10 cores, 24 GB, load about 1.2 for the 2.4M-edge runs), median of 3 runs after a warm-up, each algorithm and library in its own process, with a release build of this branch, icebug 13.6, pylance 14.0.3 and pyarrow 26.0.1. These measure the new export path, not Cypher queries.
icebug itself has packaging issues reported upstream (Ladybug-Memory/icebug#89, Ladybug-Memory/icebug#90). lance-csr doesn't depend on it.
Validation
cargo test --workspace,cargo fmt --check, workspace clippy and clippy on the Node crate: pass. New Rust tests cover hand-built CSRs, label collisions, Lance vs Arrow input,write_node_columnandoptimize_datasetswith the CSR on.make test(1738 passed, 1 skipped) andmake lint: pass. The icebug test runs when icebug and networkx are installed (PageRank and components checked against networkx in the prototype).npm test(86 passed),npm run lint,native.d.tsand the TypeDoc reference regenerated.check_snippets.py,zensical build --strictandtypos: pass. The example runs end to end with icebug.🤖 Generated with Claude Code