feat(palace): add MemoryProvider::recent for retention-ranked recall (mp-migration 4/8)#21
Merged
Merged
Conversation
jcode's `recall --mode recent` (no query) and the L1 wake-up
layer in jcode's ambient runner both need the same capability:
"give me the N most retention-relevant drawers" — the drawers
that have been accessed recently AND frequently, with Ebbinghaus-
style decay applied.
Add a default-implemented `recent(limit, scope)` method on
MemoryProvider that returns the top-N `SearchHit`s scored by:
score = (access_count + 1) / (1 + days_since_last_accessed)
The default reads `metadata["access_count"]` and
`metadata["last_accessed"]` (set by the boost/touch path in
PR #1), pulls drawers via `get_drawers`, ranks, and trims to
`limit`. Scope filtering is respected (wing/room constraints
flow through to get_drawers).
Implementations that have a wired KG (mp-020 sub-task) should
override and use `kg.helpfulness_score(id)` — which already
factors in episodic memory feedback — for strictly better
ranking than the metadata-only default.
This is PR 4/8 in the jcode → mempalace Mode C library migration
series. No dependency on PRs 1/2/7 (recent only reads metadata,
doesn't mutate).
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
MemoryProvider::recent(limit, scope)— the retention-ranked recall used by jcode'srecall --mode recentand the L1 wake-up layer.Returns the top-N
SearchHits scored by:Drawers that have never been accessed fall back to "now" with
access_count = 0.Motivation
Required for the jcode → mempalace Mode C library migration (mp-migration 4/8). jcode has two call sites that need this:
MemoryTool::recallwithmode = "recent"(no query) —tool/memory.rs:174-198crates/jcode-base/src/memory.rs:856-880(get_prompt_memories_scoped) — top-N most-relevant memories loaded into every prompt.Both today compute a retention score by walking the full drawer list and sorting. With
recent()on the trait, the adapter can delegate in one call.This is PR 4/8 in the migration series. Independent of PRs 1/2/7 —
recentonly readsmetadata["access_count"]andmetadata["last_accessed"], doesn't require the typed fields or the mutation methods.Change
crates/core/src/palace.rs— adds 1 default method toMemoryProvider(afterget_drawers, before closing}of the trait). ~70 lines of logic + 30 lines of docs.The scoring formula mirrors
crate::retention::calculate_retentionbut operates on metadata fields rather than the typedMemorystruct (which is the consolidate-pipeline'sMemory, not the trait'sDrawer). When the consolidation pipeline is wired to the trait, this default can be replaced with a direct call tokg.helpfulness_score(id).Performance
get_drawerscall + in-memory sort.limit.max(64)when a scope is set), then trims tolimitafter ranking.Test plan
cargo test -p mempalace-core --lib→ 1127 passed, 0 failed (282s)cargo check -p mempalace-corecleancargo fmt --check -p mempalace-corecleanSeries status
🤖 Generated with Claude Code