unstructured2graph: make chunk ingestion idempotent and self-provisioning#242
Merged
Conversation
…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
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.
Summary
from_unstructuredhad two load-bearing TODOs:create_nodes_from_listinsertedChunknodes viaCREATE, 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_listgains an optionalmerge_keyparam: when given, nodes are upserted viaMERGE ... ON CREATE SETinstead of duplicated viaCREATE. Default behavior (nomerge_key) is unchanged.create_unique_constraint, andfrom_unstructurednow calls it idempotently onChunk.hashand passesmerge_key="hash"tocreate_nodes_from_list, so callers no longer need a mandatory setup step.Test plan
create_nodes_from_listunit tests: defaultCREATEpath unchanged;merge_keypath producesMERGE ... ON CREATE SET; single-property edge case doesn't emit a danglingON CREATE SET.create_unique_constraintunit tests: issues the constraint query; a second call (constraint already exists) logs a warning instead of raising.from_unstructuredend-to-end test asserts both the constraint query and theMERGE-based chunk upsert are issued.pytest tests/passes (12 passed/skipped).Closes #233