Skip to content

fix: make feedback update similarity order-sensitive - #2544

Open
wzxsdf wants to merge 2 commits into
MemTensor:mainfrom
wzxsdf:codex/fix-feedback-update-similarity
Open

wzxsdf wants to merge 2 commits into
MemTensor:mainfrom
wzxsdf:codex/fix-feedback-update-similarity

Conversation

@wzxsdf

@wzxsdf wzxsdf commented Oct 25, 2026

Copy link
Copy Markdown

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

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality not to work as expected)
  • Refactor (does not change functionality, e.g. code style improvements)
  • Documentation update

How Has This Been Tested?

  • Unit Test
  • Test Script Or Test Steps
  • Pipeline Automated API Test

Validation performed:

  • poetry run pytest tests/mem_feedback -q — 21 passed
  • Ruff check passed
  • Ruff format check passed

Checklist

  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective
  • I have linked the issue to this PR
  • I have mentioned the person who will review this PR

Reviewer Checklist

@Memtensor-AI Memtensor-AI added area:memory 记忆存储、检索、更新、召回逻辑 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Oct 25, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2544
Task: 26f91287863d7d24
Base: main
Head: codex/fix-feedback-update-similarity

🔍 OpenCodeReview found 1 issue(s) in this PR.


1. src/memos/mem_feedback/utils.py (L47)

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).

💡 Suggested Change

Before:

        character_similarity = SequenceMatcher(None, text1, text2).ratio()

After:

        character_similarity = SequenceMatcher(None, text1, text2, autojunk=False).ratio()

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

✅ Automated Test Results: PASSED

All tests passed (11/11 executed). memos_python_core/changed-repo-python: 11/11. Duration: 18s

Branch: codex/fix-feedback-update-similarity

@Memtensor-AI Memtensor-AI added status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发 and removed status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:memory 记忆存储、检索、更新、召回逻辑 status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Correcting or restoring one fact in a multi-fact memory rewrites the entire memory text

3 participants