feat: lossless, idempotent export/import round-trip with JSON-LD @id/@type#13
Open
marcdhansen wants to merge 1 commit into
Open
feat: lossless, idempotent export/import round-trip with JSON-LD @id/@type#13marcdhansen wants to merge 1 commit into
marcdhansen wants to merge 1 commit into
Conversation
- add MemoryGraph::add_node_with_id (explicit id, idempotent skip, next_id bump) - import honors id/@id and created_at on nodes and edges, carries access_count/last_accessed/decay_score through, dedupes edges on (source, target, type) - export emits JSON-LD @id/@type alongside legacy keys Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Motivation
Export→import round-trips should preserve all node and edge state to enable:
@id/@typefields for semantic metadataWhat Was Broken
add_node(), making round-trips non-deterministiccreated_at,access_count,last_accessed, anddecay_scorewere discarded on import@id/@typefields; import couldn't read themWhat This Fixes
1. New
add_node_with_id()API (memory_graph.rs)Ok(false)if node already exists (idempotent skip)next_idpast the inserted ID to prevent future collisions2. JSON-LD Export (
cli/commands.rscmd_export)@id: "urn:amem:node:<id>"and@type: "<event_type>"idandevent_typefields still present3. Dual-Format Import (
cli/commands.rscmd_import)event_typefrom eitherevent_type(legacy) or@type(JSON-LD)idor by parsing@id(urn:amem:node:)created_at,access_count,last_accessed,decay_scoreadd_node_with_id()when explicit ID is present4. Idempotent Edge Dedup (
cli/commands.rscmd_import)(source_id, target_id, edge_type)tuple already existscreated_attimestamp on first insertTest Evidence
All 30 repository tests pass (
cargo test):Round-trip proof harness (openloop test-twolayer.sh):
.amem→memory.jsonlwith@idon every line ✓memory.jsonl→ fresh.amem→ re-export is byte-identical ✓.amemadds 0 nodes, 0 edges ✓Files Changed
crates/agentic-memory/src/graph/memory_graph.rs(+32 lines)add_node_with_id()public method with full index updatescrates/agentic-memory/src/cli/commands.rs(+68 lines, -8 lines)cmd_export(): Add@idand@typefieldscmd_import(): Dual-format read, ID preservation, edge dedup, metadata carry-throughBreaking Changes
None. Export now produces
@idand@typein addition to existing fields. Import accepts both old and new formats. Existing consumers are unaffected.