fix: deduplicate memories on save with exact-match check

Prevents inserting a memory if an identical one already exists for the
user. Also cleaned up 30 anonymized and 4 duplicate memories from DB.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 10:53:52 -05:00
parent 3b2de80cac
commit 2525216828

View File

@@ -542,6 +542,14 @@ class Database:
conn = self._connect()
try:
cursor = conn.cursor()
# Skip if an identical memory already exists for this user
cursor.execute(
"SELECT COUNT(*) FROM UserMemory WHERE UserId = ? AND Memory = ?",
user_id, memory[:500],
)
if cursor.fetchone()[0] > 0:
cursor.close()
return
cursor.execute(
"""INSERT INTO UserMemory (UserId, Memory, Topics, Importance, ExpiresAt, Source)
VALUES (?, ?, ?, ?, ?, ?)""",