Repository navigation
export: batched UNWIND push for neo4j/falkordb (--batch-size) - #4
Conversation
The push sinks ran one MERGE query per node and per edge, so pushing a large graph to a non-local server spent nearly all its time on round trips. Rows are now grouped by sanitized node label / relationship type (those are interpolated into the Cypher text and cannot be parameters) and sent in UNWIND batches of --batch-size rows (default 100, ~100x fewer round trips). Each row carries exactly the old per-entry params and UNWIND processes rows in order, so the MERGE/SET upsert semantics - including idempotent re-runs - are unchanged. A non-positive or non-integer --batch-size is rejected on parse, before any connection. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 65a187f9c1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| f"UNWIND $rows AS row " | ||
| f"MATCH (a {{id: row.src}}), (b {{id: row.tgt}}) " | ||
| f"MERGE (a)-[r:{rel}]->(b) SET r += row.props", |
There was a problem hiding this comment.
Preserve deterministic updates for parallel edges
When a loaded nx.MultiDiGraph (as constructed in graphify/multigraph_compat.py:74) contains parallel edges with the same endpoints and sanitized relation but different properties, every row merges the same database relationship. Neo4j does not guarantee the row order produced by UNWIND, so SET r += row.props can leave properties from an arbitrary edge rather than retaining the previous graph-order, last-write-wins behavior; repeated exports can consequently produce different relationship data. Add an explicit ordering field/ORDER BY, or otherwise process colliding edge rows deterministically.
Useful? React with 👍 / 👎.
| ftype = _safe_label(data.get("file_type", "Entity").capitalize()) | ||
| node_rows.setdefault(ftype, []).append({"id": node_id, "props": props}) |
There was a problem hiding this comment.
Bound in-memory buffers by batch size
For large graphs—the case where batched pushing is most valuable—this first copies every node and then every edge into additional dictionaries and lists before opening the connection, so peak client memory grows with the entire graph rather than batch_size and can exhaust memory before any data is sent. Keep at most one batch per sanitized label/relation and flush each buffer when it reaches batch_size; the analogous FalkorDB path has the same unbounded materialization.
Useful? React with 👍 / 👎.
# Conflicts: # CHANGELOG.md
What:
graphify export neo4j|falkordb --pushnow sends nodes and relationships in batchedUNWINDstatements, with a new--batch-sizeflag (default 100), instead of one Cypher statement per node/edge.Why: a remote push spent nearly all its time on network round trips — one per graph element. Batching cuts that by ~100x for the default size. Rows are grouped by sanitized node label / relationship type first (those are baked into the Cypher text and cannot be query parameters), each row's payload is exactly the old per-entry params, and
UNWINDprocesses rows in order, so theMERGE/SETupsert semantics — including idempotent re-runs — are unchanged.Tests:
tests/test_batched_push.py(9 tests) — batch grouping by label/type, batch-size boundaries, ordering, param payload identity with the per-entry form, and idempotent re-push. All offline; the DB driver is mocked.🤖 Generated with Claude Code