You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: make feedback update similarity order-sensitive - #2544
The feedback update guard used character-set similarity to decide whether a memory update was small enough to keep.
This caused reordered multi-fact memories to be treated as minor changes because the old and new texts contained similar character sets. A destructive rewrite could therefore pass the update guard.
This change uses difflib.SequenceMatcher, which considers character order as well as content. A regression test covers reordered text with the same facts.
SequenceMatcher defaults to autojunk=True, which for sequences of 200+ elements treats any element occurring more than len/100 + 1 times as "popular" and removes it from matching. Memory texts of a few hundred characters are common here, and in them spaces and frequent letters/CJK characters exceed that count, so ratio() under-reports similarity even for near-identical texts (matching blocks break at every popular character). The same applies to the word-level SequenceMatcher below once a text has 200+ words.
Effect on this guard: change_ratio is inflated, so for old_len >= 200 (the 0.2 threshold branch) ordinary small edits — and even identical texts — get should_keep_update() == False and are downgraded from UPDATE to ADD in standard_operations, creating duplicate memories instead of updating the existing one.
Pass autojunk=False explicitly (and be aware ratio() is O(n*m), so very long texts get more expensive than the previous O(n) set check).
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
area:memory记忆存储、检索、更新、召回逻辑status:readyReady for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发
3 participants
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.
Description
The feedback update guard used character-set similarity to decide whether a memory update was small enough to keep.
This caused reordered multi-fact memories to be treated as minor changes because the old and new texts contained similar character sets. A destructive rewrite could therefore pass the update guard.
This change uses
difflib.SequenceMatcher, which considers character order as well as content. A regression test covers reordered text with the same facts.Related Issue: #2527
No new dependencies are required.
Type of change
How Has This Been Tested?
Validation performed:
poetry run pytest tests/mem_feedback -q— 21 passedChecklist
Reviewer Checklist