Skip to content

feat(export): index-driven DB push — shared :GraphifyNode label, pre-write indexes, legacy adoption - #10

Merged
Azeem1985 merged 1 commit into
v8from
feat/indexed-db-push
Aug 24, 2026
Merged

Azeem1985 merged 1 commit into
v8from
feat/indexed-db-push

Conversation

@Azeem1985

Copy link
Copy Markdown

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:

  • Node MERGEs without indexes: ~3.6s/batch (~137 entries/sec). After hand-creating per-label (n:Label) ON (n.id) indexes on the live DB: ~60x faster — 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 would take days.

What changes (all four writers: push_to_* and stream_push_to_*)

  1. Shared label :GraphifyNode (SHARED_NODE_LABEL) on every pushed node, on top of its per-type label. Node MERGEs merge on the shared label + id and add the type label via SET n:<Type> (FalkorDB >= 2.12).
  2. Indexes created 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, 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.
  3. Edge endpoints MATCH via the shared label: MATCH (a:GraphifyNode {id: row.src}), (b:GraphifyNode {id: row.tgt}) — the one shared-label index serves both phases.
  4. Old-container contract — adopt-on-push: every push first runs the one-scan 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 whose file_type changes accumulates type labels; identity is shared label + id.

Row payloads, batching, --batch-size, URI/auth parsing and MERGE upsert idempotence are unchanged.

Tests

  • New 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 clean v8). ruff + py_compile clean.

🤖 Generated with Claude Code

…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]>
@Azeem1985
Azeem1985 merged commit cddb6e6 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