feat(palace): add tag/untag/link/list_tags to MemoryProvider (mp-migration 2/8)#20
Merged
Conversation
This was referenced Jun 3, 2026
Merged
jcode's MemoryManager exposes 4 graph-mutation methods that today
have no equivalent on the MemoryProvider trait:
- tag(&id, tag) — MemoryManager::tag_memory
- untag(&id, tag) — MemoryManager::untag_memory
- link(&from, &to, w) — MemoryManager::link_memories (with weight)
- list_tags() — closest jcode equiv: graph_stats.1
Add them as default-implemented methods on MemoryProvider. The
defaults use the metadata path (so this PR does NOT depend on the
KG being wired into Palace), mirroring the values in shapes that
match the eventual KG triples:
tag → metadata["tags"] (Vec<String>) + metadata["tag:<n>"] = true
untag → metadata["tags"] (minus removed) + remove metadata["tag:<n>"]
link → metadata["links"] = Vec<{target, weight}>
list → aggregate metadata["tags"] across get_drawers(None, None)
Implementations that have a wired KG (mp-020 sub-task) should
override and use KnowledgeGraph::add_triple / query_relationship
directly:
tag → add_triple { subject: drawer_id, predicate: "has_tag",
object: tag, current: true }
link → add_triple { subject: from, predicate: "relates_to",
object: to, confidence: Some(weight) }
list → query_relationship(predicate="has_tag") then group-by
Includes a cherry-pick of PR #1 (the boost/decay/reinforce/
supersede/set_metadata additions) so the trait has all 9 mutation
methods together. Both can be reviewed independently because the
cherry-pick commit is its own clean diff in the series.
This is PR 2/8 in the jcode → mempalace Mode C library migration
series.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
49980ff to
6af3f0b
Compare
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
Add 4 graph-mutation methods to
MemoryProvidercovering jcode's tag/link surface:tag(&id, tag)MemoryManager::tag_memorymetadata["tags"]+metadata["tag:<n>"] = trueuntag(&id, tag)MemoryManager::untag_memorymetadata["tags"]andmetadata["tag:<n>"]link(&from, &to, w)MemoryManager::link_memoriesmetadata["links"] = Vec<{target, weight}>list_tags()graph_stats.1metadata["tags"]across drawersMotivation
Required for the jcode → mempalace Mode C library migration (mp-migration 2/8). jcode's
MemoryManagercallstag_memoryandlink_memoriespervasively (memory.rs:1657, 1676) and the tool'stagandlinkactions (tool/memory.rs:328, 355) call them too. Without trait methods, the adapter would have to either re-implement or expose rawmetadatawrites.This is PR 2/8 in the migration series. Includes a cherry-pick of PR #1 (boost/decay/reinforce/supersede/set_metadata) so this branch has all 9 mutation methods in one place. The two commits are independent in the series and can be reviewed/rebased independently.
Change
crates/core/src/palace.rs— adds 4 default methods toMemoryProvidertrait (afterset_metadata, beforefingerprint):All four have the
where Self: Sizedbound required by the default-implementation helper.The defaults use the metadata path so they don't depend on the KG being wired into Palace. The metadata shapes (
Vec<String>,Vec<{target, weight}>) are designed to match the eventual KG triples:tag→kg.add_triple(subject: drawer_id, predicate: "has_tag", object: tag)link→kg.add_triple(subject: from, predicate: "relates_to", object: to, confidence: Some(weight))list_tags→kg.query_relationship(predicate: "has_tag")then group-byImplementations that have a wired KG should override and use the KG API directly. The metadata path stays as a fallback for the jcode adapter's get-or-default usage.
Performance
tag/untag/link: O(n) via the shareddefault_mutate_drawerhelper (get_drawers + store.upsert).list_tags: O(n × m) where n is drawer count and m is avg tags per drawer. The KG-backed override can be O(1).Both are fine for the embedvec tier (≤5 k drawers). Override for larger palaces.
Test plan
cargo test -p mempalace-core --lib→ 1127 passed, 0 failed (251s)cargo check -p mempalace-corecleancargo fmt --check -p mempalace-corecleanSeries status
🤖 Generated with Claude Code