Repository navigation
feat(export): index-driven DB push — shared :GraphifyNode label, pre-write indexes, legacy adoption - #10
Merged
Conversation
…write indexes, legacy adoption
Production measurements on a real 1.87GB graph (1,211,189 nodes / ~1.15M
edges) against FalkorDB, streaming pusher, batch 500:
- node MERGEs without indexes: ~3.6s/batch (~137 entries/sec); ~60x faster
after hand-creating per-label (n:Label) ON (n.id) indexes live (all 1.2M
nodes landed in ~12 min);
- edge phase: ~2 edges/sec - the edge MERGE matched endpoints with NO label
(MATCH (a {id: row.src}), (b {id: row.tgt})), and per-label indexes cannot
serve label-less lookups, so every edge full-scanned 1.2M nodes TWICE;
1.15M edges were days away.
All four writers (push_to_* and stream_push_to_*) now:
1. stamp every node with the shared :GraphifyNode label (SHARED_NODE_LABEL)
on top of its per-type label, merging on the shared label + id and adding
the type label via SET n:<Type> (FalkorDB >= 2.12);
2. create indexes idempotently BEFORE any write - GraphifyNode on (id) plus
one per type label (Neo4j: CREATE INDEX IF NOT EXISTS; FalkorDB has no
IF NOT EXISTS, its 'already indexed' reply is tolerated by message; the
in-memory writers know all labels up front, the streaming writers index
each label at first encounter, still before that label's first batch);
3. MATCH edge endpoints as (:GraphifyNode {id: ...}) so the one shared-label
index serves both phases;
4. adopt-on-push old-container contract: every push first runs the one-scan
MATCH (n) WHERE n.id IS NOT NULL SET n:GraphifyNode, so a container
loaded by the previous unlabeled pusher is adopted in place - a MERGE on
(:GraphifyNode {id}) alone could never match an unlabeled legacy node and
would have duplicated the whole graph on re-push. No fresh container
required; the scan is a no-op on adopted/empty graphs.
Row payloads, batching, --batch-size, URI/auth parsing and MERGE upsert
idempotence are unchanged; tests pin index-before-write ordering, the
shared-label Cypher, payload parity, already-indexed tolerance (real errors
still raise), and the no-duplicates adoption contract against a semantic
fake that executes the emitted Cypher shapes over a legacy container.
Co-Authored-By: Claude Fable 5 <[email protected]>
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.
Evidence (production, real graph)
Measured on a real 1.87GB graph.json — 1,211,189 nodes / ~1.15M edges — against FalkorDB with the streaming pusher (#9), batch 500:
(n:Label) ON (n.id)indexes on the live DB: ~60x faster — all 1.2M nodes landed in ~12 min.MATCH (a {id: row.src}), (b {id: row.tgt})— and per-label indexes cannot serve label-less lookups, so every edge full-scanned 1.2M nodes twice. 1.15M edges would take days.What changes (all four writers:
push_to_*andstream_push_to_*):GraphifyNode(SHARED_NODE_LABEL) on every pushed node, on top of its per-type label. Node MERGEs merge on the shared label +idand add the type label viaSET n:<Type>(FalkorDB >= 2.12).GraphifyNodeon(id)plus one per type label. Neo4j:CREATE INDEX IF NOT EXISTS; FalkorDB has no IF NOT EXISTS — itsalready indexedreply is tolerated by message, anything else still raises. In-memory writers know all labels up front; streaming writers index each label at first encounter, still before that label's first batch.MATCH (a:GraphifyNode {id: row.src}), (b:GraphifyNode {id: row.tgt})— the one shared-label index serves both phases.MATCH (n) WHERE n.id IS NOT NULL SET n:GraphifyNode. A container loaded by the previous unlabeled pusher is adopted in place: a MERGE on(:GraphifyNode {id})alone could never match an unlabeled legacy node and would duplicate the whole graph on re-push. No fresh container required; the scan is a no-op on adopted/empty graphs. A node whosefile_typechanges accumulates type labels; identity is shared label + id.Row payloads, batching,
--batch-size, URI/auth parsing and MERGE upsert idempotence are unchanged.Tests
tests/test_indexed_push.py(14 tests): index-creation-precedes-writes for all four writers, shared-label Cypher, row-payload parity with the unlabeled pusher, already-indexed tolerance (Neo4j + FalkorDB tone) with real errors still propagating, and the no-duplicates adoption contract proven against a semantic fake that executes the emitted Cypher shapes over a pre-seeded legacy (unlabeled) container, plus re-push idempotence over a migrated one.test_indexed_push.py+test_streaming_push.py+test_batched_push.py: 33 passed;test_export.py+test_cli_export.py: 107 passed. Full-suite sweep: zero failures unique to this branch (the flaky terraform/tree-sitter/wheel env failures reproduce identically on cleanv8). ruff + py_compile clean.🤖 Generated with Claude Code