Skip to content

unstructured2graph: make chunk ingestion idempotent and self-provisioning#242

Merged
antejavor merged 2 commits into
mainfrom
fix/233-idempotent-chunk-ingestion
Jul 24, 2026
Merged

unstructured2graph: make chunk ingestion idempotent and self-provisioning#242
antejavor merged 2 commits into
mainfrom
fix/233-idempotent-chunk-ingestion

Conversation

@antejavor

Copy link
Copy Markdown
Contributor

Summary

from_unstructured had two load-bearing TODOs:

  • create_nodes_from_list inserted Chunk nodes via CREATE, so re-running over the same sources (retry, re-ingesting an updated doc) duplicated every Chunk node with the same hash.
  • create_index(memgraph, "Chunk", "hash") was a non-unique index the caller had to remember to call themselves -- nothing in the graph actually prevented hash collisions.

Changes:

  • create_nodes_from_list gains an optional merge_key param: when given, nodes are upserted via MERGE ... ON CREATE SET instead of duplicated via CREATE. Default behavior (no merge_key) is unchanged.
  • Added create_unique_constraint, and from_unstructured now calls it idempotently on Chunk.hash and passes merge_key="hash" to create_nodes_from_list, so callers no longer need a mandatory setup step.

Test plan

  • create_nodes_from_list unit tests: default CREATE path unchanged; merge_key path produces MERGE ... ON CREATE SET; single-property edge case doesn't emit a dangling ON CREATE SET.
  • create_unique_constraint unit tests: issues the constraint query; a second call (constraint already exists) logs a warning instead of raising.
  • from_unstructured end-to-end test asserts both the constraint query and the MERGE-based chunk upsert are issued.
  • pytest tests/ passes (12 passed/skipped).

Closes #233

…ning

from_unstructured had two load-bearing TODOs: Chunk nodes were inserted
via CREATE (duplicating on every re-run) and a non-unique index on
Chunk.hash was left for the caller to create themselves, so nothing
actually prevented hash collisions.

- create_nodes_from_list gains an optional merge_key: when given, nodes
  are upserted via MERGE ... ON CREATE SET instead of duplicated via
  CREATE.
- Add create_unique_constraint, and have from_unstructured call it
  idempotently on Chunk.hash instead of requiring the caller to call
  create_index first.

Ingestion is now safe to retry/rerun over the same sources without
manual dedup or a mandatory setup step.

Fixes #233
…unk-ingestion

# Conflicts:
#	unstructured2graph/src/unstructured2graph/__init__.py
#	unstructured2graph/src/unstructured2graph/loaders.py
#	unstructured2graph/tests/test_loaders.py
@antejavor
antejavor merged commit 9774940 into main Jul 24, 2026
13 checks passed
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.

unstructured2graph: make chunk ingestion idempotent and self-provisioning

1 participant