feat(palace): add boost/decay/reinforce/supersede/set_metadata to MemoryProvider (mp-migration 1/8)#19
Merged
Conversation
…oryProvider jcode's MemoryManager exposes 5 per-entry mutation methods that today have no equivalent on the MemoryProvider trait: - boost(&id, amount) — boost_confidence + touch - decay(&id, amount) — decay_confidence + touch - reinforce(&id, sid, idx) — push Reinforcement breadcrumb - supersede(&old, &new) — mark old as superseded_by new - set_metadata(&id, k, v) — typed metadata mutation Add them as default-implemented methods on MemoryProvider. All five use a shared helper (`default_mutate_drawer`) that does an O(n) get-mutate-upsert dance via get_drawers + store.upsert. The `where Self: Sized` bound on each default method is required because the helper takes `&dyn MemoryProvider` (a ?Sized type). Implementers that need ?Sized Self (very rare) override; everyone else gets the default for free. Default impls use the metadata key path (`metadata[access_count]`, `metadata[last_accessed]`, etc.) so this PR does NOT depend on PR #7. When #7 lands, the typed fields become the canonical home and the metadata path becomes a backwards-compat read shim. Performance: O(n) on every mutation. Fine for the embedvec tier (≤5 k drawers). Implementations targeting larger palaces (usearch, lancedb) should override the public methods with a direct `WHERE id = ?` store call — the helper is intentionally private so it can't be called from outside the crate. This is PR 1/8 in the jcode → mempalace Mode C library migration series (the trait methods piece, after the foundational PRs 6+7+8 on docs, fields, and stats). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jun 3, 2026
Merged
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 5 per-entry mutation methods to
MemoryProviderso external consumers (jcode's adapter, third-party agents) have a typed API for evolving drawer state without going throughadd_drawer(destructive) or rawmetadatakeys:boost(&id, amount)MemoryEntry::boost_confidencemetadata["access_count"], updatesmetadata["last_accessed"]decay(&id, amount)MemoryEntry::decay_confidencemetadata["last_accessed"](confidence is computed at read time)reinforce(&id, sid, idx)MemoryEntry::reinforcemetadata["reinforcements"]+ bumps access_countsupersede(&old, &new)MemoryEntry::supersedemetadata["superseded_by"]andmetadata["active"]=falseon oldset_metadata(&id, k, v)Motivation
Required for the jcode → mempalace Mode C library migration (mp-migration 1/8). jcode's
MemoryManagerexposes all 5 of these and they're called pervasively:boost_confidenceon every successful retrieval (memory.rs:339)decay_confidenceon every negative sidecar check (memory.rs:344)reinforceon every dedup hit (memory.rs:371, 382, 406, 420)supersedewhen content changes (memory.rs:381)This is PR 1/8 in the migration series.
Change
crates/core/src/palace.rs— adds 5 default methods toMemoryProvidertrait (aftergraph_stats, beforefingerprint) and 1 private helper functiondefault_mutate_drawer.The
where Self: Sizedbound on each default method is required because the helper takes&dyn MemoryProvider(a?Sizedtype). Implementers that need?SizedSelf (very rare) override; everyone else gets the default for free.Default impls use the metadata key path (
metadata["access_count"],metadata["last_accessed"], etc.) so this PR does NOT depend on PR #7. When #7 lands, the typed fields become the canonical home and the metadata path becomes a backwards-compat read shim.Performance: O(n) on every mutation via
get_drawers(None, None)+store.upsert(...). Fine for the embedvec tier (≤5 k drawers). Implementations targeting larger palaces (usearch, lancedb) should override the public methods with a directWHERE id = ?store call — the helper is intentionally private so it can't be called from outside the crate.Test plan
cargo test -p mempalace-core --lib→ 1127 passed, 0 failed (228s)cargo check -p mempalace-corecleancargo fmt --check -p mempalace-corecleanSeries status
🤖 Generated with Claude Code