Skip to content

Commit 2ac7f23

Browse files
committed
Remove silent error handling
1 parent fdcda3e commit 2ac7f23

File tree

1 file changed

+44
-51
lines changed

1 file changed

+44
-51
lines changed

agent_memory_server/long_term_memory.py

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -968,62 +968,55 @@ async def deduplicate_by_hash(
968968
)
969969

970970
# Use vectorstore adapter to search for memories with the same hash
971-
try:
972-
# Build filter objects
973-
namespace_filter = None
974-
if namespace or memory.namespace:
975-
namespace_filter = Namespace(eq=namespace or memory.namespace)
976-
977-
user_id_filter = None
978-
if user_id or memory.user_id:
979-
user_id_filter = UserId(eq=user_id or memory.user_id)
980-
981-
session_id_filter = None
982-
if session_id or memory.session_id:
983-
session_id_filter = SessionId(eq=session_id or memory.session_id)
984-
985-
# Create memory hash filter
986-
memory_hash_filter = MemoryHash(eq=memory_hash)
987-
988-
# Use vectorstore adapter to search for memories with the same hash
989-
adapter = await get_vectorstore_adapter()
990-
991-
# Search for existing memories with the same hash
992-
# Use a dummy query since we're filtering by hash, not doing semantic search
993-
results = await adapter.search_memories(
994-
query="", # Empty query since we're filtering by hash
995-
session_id=session_id_filter,
996-
user_id=user_id_filter,
997-
namespace=namespace_filter,
998-
memory_hash=memory_hash_filter,
999-
limit=1, # We only need to know if one exists
1000-
)
971+
# Build filter objects
972+
namespace_filter = None
973+
if namespace or memory.namespace:
974+
namespace_filter = Namespace(eq=namespace or memory.namespace)
1001975

1002-
if results.memories and len(results.memories) > 0:
1003-
# Found existing memory with the same hash
1004-
logger.info(f"Found existing memory with hash {memory_hash}")
976+
user_id_filter = None
977+
if user_id or memory.user_id:
978+
user_id_filter = UserId(eq=user_id or memory.user_id)
1005979

1006-
# Update the last_accessed timestamp of the existing memory
1007-
existing_memory = results.memories[0]
1008-
if existing_memory.id:
1009-
# Use the memory key format to update last_accessed
1010-
existing_key = Keys.memory_key(
1011-
existing_memory.id, existing_memory.namespace
1012-
)
1013-
await redis_client.hset(
1014-
existing_key,
1015-
"last_accessed",
1016-
str(int(datetime.now(UTC).timestamp())),
1017-
) # type: ignore
980+
session_id_filter = None
981+
if session_id or memory.session_id:
982+
session_id_filter = SessionId(eq=session_id or memory.session_id)
1018983

1019-
# Don't save this memory, it's a duplicate
1020-
return None, True
984+
# Create memory hash filter
985+
memory_hash_filter = MemoryHash(eq=memory_hash)
1021986

1022-
except Exception as e:
1023-
logger.error(f"Error searching for hash duplicates using vectorstore: {e}")
1024-
# If search fails, proceed with the original memory
1025-
pass
987+
# Use vectorstore adapter to search for memories with the same hash
988+
adapter = await get_vectorstore_adapter()
1026989

990+
# Search for existing memories with the same hash
991+
# Use a dummy query since we're filtering by hash, not doing semantic search
992+
results = await adapter.search_memories(
993+
query="", # Empty query since we're filtering by hash
994+
session_id=session_id_filter,
995+
user_id=user_id_filter,
996+
namespace=namespace_filter,
997+
memory_hash=memory_hash_filter,
998+
limit=1, # We only need to know if one exists
999+
)
1000+
1001+
if results.memories and len(results.memories) > 0:
1002+
# Found existing memory with the same hash
1003+
logger.info(f"Found existing memory with hash {memory_hash}")
1004+
1005+
# Update the last_accessed timestamp of the existing memory
1006+
existing_memory = results.memories[0]
1007+
if existing_memory.id:
1008+
# Use the memory key format to update last_accessed
1009+
existing_key = Keys.memory_key(
1010+
existing_memory.id, existing_memory.namespace
1011+
)
1012+
await redis_client.hset(
1013+
existing_key,
1014+
"last_accessed",
1015+
str(int(datetime.now(UTC).timestamp())),
1016+
) # type: ignore
1017+
1018+
# Don't save this memory, it's a duplicate
1019+
return None, True
10271020
# No duplicates found, return the original memory
10281021
return memory, False
10291022

0 commit comments

Comments
 (0)