Repository navigation
Description
Follow-up to #200.
Why
CypherEngine.export_graph builds dense CSR arrays from whole relationship types. Many graph-algorithm pipelines need a subgraph instead: select edges with a Cypher query, run an algorithm on just those, then filter by the scores. Today the query result has to be turned into CSR by hand (key-to-dense-id mapping, symmetrising, deduplication, weights), repeating the rules export_graph already implements, and slower.
In a filter → PageRank → filter pipeline on the SNAP Twitter graph (2.4M edge rows), building that CSR in numpy takes 0.13 s of a 0.18 s pipeline. export_graph handles all 2.4M rows, scan included, in 0.066 s, so a Rust build of the subgraph should cut that stage well below half (an estimate until measured).
Proposal
A way to export an arbitrary edge list, such as a Cypher result already in Arrow, as the same GraphExport:
- inputs: the edge table, its source and target key columns, and the options
export_graphhas:directed,weight(a column of the table),default_weight(one per row, which counts repeated rows),combine_edges; - the same semantics as
export_graph: repeated edges combined bycombine_edges, undirecteda -> bandb -> aas one edge, self-loops once, null weights dropped and counted, in-edges built by transposing the out-edge CSR; - reuse the CSR builders in
crates/lance-csr/src/graph_export.rsrather than duplicating them.
Open questions
- Dense ids over only the endpoints present (a subgraph), or an optional list of node keys so isolated nodes are kept?
- A function taking an Arrow table, or a method on
CypherEnginetaking a query string, or both? - Keys from several node labels can collide in a plain edge list: limit it to one key space, or take label columns too?
- Keys are int64 only, as in
export_graph?
Done when
- Rust implementation with unit tests (duplicates, reciprocal pairs, self-loops, weights, nulls);
- Python and TypeScript bindings, docstrings and TSDoc, a section and parameter table on the graph algorithms page, regenerated TypeDoc;
- measured on the Twitter pipeline above: identical arrays and scores to the numpy build, and the stage time before and after.
Activity
feat(export): export the subgraph a cypher query selects (hyperdimens…