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:
@@ -542,6 +542,14 @@ class Database:
|
|||||||
conn = self._connect()
|
conn = self._connect()
|
||||||
try:
|
try:
|
||||||
cursor = conn.cursor()
|
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(
|
cursor.execute(
|
||||||
"""INSERT INTO UserMemory (UserId, Memory, Topics, Importance, ExpiresAt, Source)
|
"""INSERT INTO UserMemory (UserId, Memory, Topics, Importance, ExpiresAt, Source)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)""",
|
VALUES (?, ?, ?, ?, ?, ?)""",
|
||||||
|
|||||||
Reference in New Issue
Block a user