[PR #2315] [MERGED] Fix Memory Recall relevance bounds #5533

Closed
opened 2026-10-22 04:17:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/2315
Author: @Xelvanis
Created: 6/5/2026
Status: ✅ Merged
Merged: 6/5/2026
Merged by: @Xelvanis

Base: refactor ← Head: fix/memory-recall-relevance-floor-2287


📝 Commits (3)

  • 2b10978 Fix memory recall relevance bounds
  • 3286469 Address memory recall review findings
  • fc2f953 Fix memory recall review gaps

📊 Changes

7 files changed (+675 additions, -29 deletions)

View changed files

📝 src-tauri/src/commands/storage/chats.rs (+391 -0)
📝 src-tauri/src/commands/storage/commands/chats.rs (+18 -3)
📝 src-tauri/src/http_dispatch.rs (+102 -3)
📝 src/engine/capabilities/storage.ts (+10 -1)
📝 src/engine/generation/prompt-assembly.ts (+127 -13)
📝 src/shared/api/chat-command-api.ts (+23 -1)
📝 src/shared/api/storage-api.ts (+4 -8)

📄 Description

Linked issue

Closes #2286
Closes #2287

Why this change

  • Memory Recall regressed from the legacy relevance floor and admitted weak positive matches.
  • Long chats also scored every stored memory chunk on each generation instead of bounding the working set.
  • The first pass fixed scoring locally, then the command/API boundary was updated so prompt assembly requests a bounded recent memory list from embedded and remote runtimes.

What changed

  • Restored a 0.25 Memory Recall relevance floor while allowing strong exact-token lexical matches to pass when semantic score is just below the floor.
  • Limited Memory Recall scoring to the 500 most-recent chunks before cosine/lexical scoring.
  • Added listChatMemories options on the engine storage port and routed the shared storage adapter through the focused chat command API.
  • Updated embedded Tauri and remote /api/invoke chat_memories_list handling to support limit and order: "recent".
  • Added native coverage for recent limited Memory Recall chunk listing, default stored order, and invalid order rejection.

Refactor impact

Primary owner:

  • Engine generation / Memory Recall prompt assembly

Impact areas reviewed:

  • React-free prompt assembly
  • Shared storage API wrapper and chat command wrapper
  • Embedded Tauri chat memory commands
  • Remote runtime HTTP dispatch for /api/invoke

Boundary notes:

  • Engine code still uses the StorageGateway port and does not import Tauri or shared API adapters.
  • Shared API code owns the Tauri/remote command arguments for memory listing.
  • Rust storage command code owns sorting, limiting, and validation for chat_memories_list.
  • Remote-capable behavior stays on the existing allowlisted chat_memories_list command path.

Pressure points touched:

  • src/engine/generation/prompt-assembly.ts
  • src-tauri/src/http_dispatch.rs
  • No src-tauri/src/lib.rs command registration changes.

Validation

  • Matching validation command passes locally (for example pnpm typecheck, pnpm build, pnpm check:architecture, pnpm check:docs, or full pnpm check when warranted)
  • Full pnpm check passes before PR push/handoff
  • Human/manual validation completed by contributor or reviewer

Manual verification notes

  • pnpm exec vitest run src/engine/generation/prompt-assembly.test.ts
  • pnpm typecheck
  • pnpm check:architecture
  • cargo test --manifest-path src-tauri/Cargo.toml list_chat_memories_can_return_recent_limited_chunks
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace
  • pnpm check
  • Local temporary harnesses, not committed, reproduced and verified weak semantic matches, recent-500 chunk capping, and the blue umbrella strong lexical match case.
  • Manual Tauri UI QA was not run because this changes prompt assembly and command/API behavior without visible UI changes.

Feature Discoverability

Check exactly one:

  • Updated src/features/shell/discovery/ because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool.
  • N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find.

Reason:

  • This fixes Memory Recall scoring and command boundary behavior for an existing feature.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

UI evidence

  • N/A; no visible UI changes.

Remaining risk

  • Memory chunks are still embedded on the chat record as chat.memories, so the Rust command still materializes the chat record internally before applying the bounded command response. Moving chunks to a dedicated collection or sidecar storage path is a larger storage migration and is left for follow-up.

Summary by CodeRabbit

  • New Features

    • Chat memory listing now supports optional pagination via limit parameter and sorting options: retrieve memories in stored insertion order (default) or sorted by recency.
  • Improvements

    • Enhanced memory recall with improved relevance filtering and recency-based chunk scoring for more accurate context retrieval.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/2315 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 6/5/2026 **Status:** ✅ Merged **Merged:** 6/5/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `fix/memory-recall-relevance-floor-2287` --- ### 📝 Commits (3) - [`2b10978`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2b10978b1282eef8a51d4d953109048d8c310d3b) Fix memory recall relevance bounds - [`3286469`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3286469235f2c45362ebe943cd170b6ec398a332) Address memory recall review findings - [`fc2f953`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fc2f953eb873d31d22108fa9620a2f0357c339bb) Fix memory recall review gaps ### 📊 Changes **7 files changed** (+675 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/chats.rs` (+391 -0) 📝 `src-tauri/src/commands/storage/commands/chats.rs` (+18 -3) 📝 `src-tauri/src/http_dispatch.rs` (+102 -3) 📝 `src/engine/capabilities/storage.ts` (+10 -1) 📝 `src/engine/generation/prompt-assembly.ts` (+127 -13) 📝 `src/shared/api/chat-command-api.ts` (+23 -1) 📝 `src/shared/api/storage-api.ts` (+4 -8) </details> ### 📄 Description ## Linked issue Closes #2286 Closes #2287 ## Why this change - Memory Recall regressed from the legacy relevance floor and admitted weak positive matches. - Long chats also scored every stored memory chunk on each generation instead of bounding the working set. - The first pass fixed scoring locally, then the command/API boundary was updated so prompt assembly requests a bounded recent memory list from embedded and remote runtimes. ## What changed - Restored a `0.25` Memory Recall relevance floor while allowing strong exact-token lexical matches to pass when semantic score is just below the floor. - Limited Memory Recall scoring to the 500 most-recent chunks before cosine/lexical scoring. - Added `listChatMemories` options on the engine storage port and routed the shared storage adapter through the focused chat command API. - Updated embedded Tauri and remote `/api/invoke` `chat_memories_list` handling to support `limit` and `order: "recent"`. - Added native coverage for recent limited Memory Recall chunk listing, default stored order, and invalid order rejection. ## Refactor impact Primary owner: - Engine generation / Memory Recall prompt assembly Impact areas reviewed: - React-free prompt assembly - Shared storage API wrapper and chat command wrapper - Embedded Tauri chat memory commands - Remote runtime HTTP dispatch for `/api/invoke` Boundary notes: - Engine code still uses the `StorageGateway` port and does not import Tauri or shared API adapters. - Shared API code owns the Tauri/remote command arguments for memory listing. - Rust storage command code owns sorting, limiting, and validation for `chat_memories_list`. - Remote-capable behavior stays on the existing allowlisted `chat_memories_list` command path. Pressure points touched: - `src/engine/generation/prompt-assembly.ts` - `src-tauri/src/http_dispatch.rs` - No `src-tauri/src/lib.rs` command registration changes. ## Validation - [x] Matching validation command passes locally (for example `pnpm typecheck`, `pnpm build`, `pnpm check:architecture`, `pnpm check:docs`, or full `pnpm check` when warranted) - [x] Full `pnpm check` passes before PR push/handoff - [ ] Human/manual validation completed by contributor or reviewer ### Manual verification notes - `pnpm exec vitest run src/engine/generation/prompt-assembly.test.ts` - `pnpm typecheck` - `pnpm check:architecture` - `cargo test --manifest-path src-tauri/Cargo.toml list_chat_memories_can_return_recent_limited_chunks` - `cargo check --manifest-path src-tauri/Cargo.toml --workspace` - `pnpm check` - Local temporary harnesses, not committed, reproduced and verified weak semantic matches, recent-500 chunk capping, and the `blue umbrella` strong lexical match case. - Manual Tauri UI QA was not run because this changes prompt assembly and command/API behavior without visible UI changes. ## Feature Discoverability Check exactly one: - [ ] Updated `src/features/shell/discovery/` because this PR adds or materially changes a user-discoverable feature, workflow, setting, mode, panel, import path, agent, media capability, or advanced tool. - [x] N/A because this PR is only a bugfix, refactor, test, docs, internal wiring, visual polish, copy edit, or compatibility fix and does not add a new thing users need to find. Reason: - This fixes Memory Recall scoring and command boundary behavior for an existing feature. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims ## UI evidence - N/A; no visible UI changes. ## Remaining risk - Memory chunks are still embedded on the chat record as `chat.memories`, so the Rust command still materializes the chat record internally before applying the bounded command response. Moving chunks to a dedicated collection or sidecar storage path is a larger storage migration and is left for follow-up. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Chat memory listing now supports optional pagination via `limit` parameter and sorting options: retrieve memories in stored insertion order (default) or sorted by recency. * **Improvements** * Enhanced memory recall with improved relevance filtering and recency-based chunk scoring for more accurate context retrieval. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:17:08 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5533
No description provided.