feat(memory): make per-response memory recall count user-configurable (#4948)#5006
feat(memory): make per-response memory recall count user-configurable (#4948)#5006maxmilian wants to merge 2 commits into
Conversation
|
One design question before I flip this out of draft, since the issue (#4948) left the control shape open: The issue proposed two shapes — presets ( I leaned number-input for that consistency, but I'm glad to switch to the preset buttons if you'd prefer. If you do want presets, two sub-questions:
Happy to rework the UI either way before review — just let me know which shape you want. (Backend is the same either way: the count flows through to the recall |
|
Following up on the design question above — going with the number input as implemented, for the consistency reasons noted (it sits beside the existing "Max skills per request" control and reads the same way), and it's minimal + backward-compatible (defaults to the current 3, clamped [1,50]). Flipping out of draft now; happy to switch to the preset buttons during review if a maintainer prefers — the backend is identical either way. |
…odysseus-dev#4948) The number of extended (non-pinned) memories retrieved into context per response was hardcoded to k=3 in build_context_preface. Expose it as a "Max memories per response" setting in Settings → Memory, mirroring the existing skill_max_injected pattern (per-user pref via /api/prefs, global default in settings.py). Defaults to 3 so existing installs are unchanged; the read path clamps to [1,50] so a malformed pref can't silently disable or balloon recall. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ry_recall_count helper (odysseus-dev#4948) Adopts fresh-review nit: the new robustness logic (malformed-pref fallback + [1,50] clamp) had no test coverage. Extracted the inline pref resolution into a pure resolve_memory_recall_count() helper and added cases for None/NaN/string/ negative/oversized/float inputs. Behaviour unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8770405 to
47668e9
Compare
Summary
The number of extended (non-pinned) memories retrieved into the model context per response was hardcoded to
k=3inChatProcessor.build_context_preface, so users had no way to recall more memories (long-running projects where many small facts matter) or fewer (leaner, cheaper prompts) without editing source. This adds a "Max memories per response" control under Settings → Memory, wired through the existing per-user prefs system (/api/prefs/memory_recall_count) with a global default insettings.py. It mirrors the existingskill_max_injectedsetting exactly. Default stays at 3, so existing installs behave identically; the backend read clamps to[1, 50]so a malformed pref can't silently disable recall (k<=0) or balloon the prompt.Target branch
dev, notmain. All PRs land indev;mainis curated by the maintainer at each release. If your PR is onmainby accident, click "Edit" on this PR and change the base.Linked Issue
Fixes #4948
Type of Change
Checklist
devuvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough. (Walkthrough documented in the comment below; screenshot of the rendered control included under "Screenshots / clips".)How to Test
Automated (added with this PR):
test_mem_recall_count_drives_retrieval_k— a non-default count is forwarded to the retrieval step ask.test_mem_recall_count_defaults_to_current_behavior— omitting it preserves the previous hardcodedk=3.Manual (reviewer):
uvicorn app:appordocker compose up) and open Memory → Settings.3).10); it persists to/api/prefs/memory_recall_count(verify withGET /api/prefs/memory_recall_count).Visual / UI changes — REQUIRED if you touched anything that renders
admin-cardlayout,admin-toggle-sublabels, and the same<input type="number">styling as the adjacent Inject Skills control — no new color values, font sizes, spacing units, or classes introduced.syncPrefNumberhelper (added an optional toast-label arg, default unchanged) rather than writing a parallel one.Screenshots / clips