Skip to content

export: batched UNWIND push for neo4j/falkordb (--batch-size) - #4

Merged
Azeem1985 merged 2 commits into
v8from
feat/batched-db-push
Aug 24, 2026
Merged

Azeem1985 merged 2 commits into
v8from
feat/batched-db-push

Conversation

@Azeem1985

Copy link
Copy Markdown

What: graphify export neo4j|falkordb --push now sends nodes and relationships in batched UNWIND statements, with a new --batch-size flag (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 UNWIND processes rows in order, so the MERGE/SET upsert 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

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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +98 to +100
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",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +69 to +70
ftype = _safe_label(data.get("file_type", "Entity").capitalize())
node_rows.setdefault(ftype, []).append({"id": node_id, "props": props})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@Azeem1985
Azeem1985 merged commit 7538bd8 into v8 Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant