@@ -84,7 +84,7 @@ def encode(self, texts: List[str]) -> np.ndarray:
8484 embeddings = []
8585 for text in texts :
8686 # Generate deterministic mock embedding from text hash
87- hash_obj = hashlib .md5 (text .encode ())
87+ hash_obj = hashlib .blake2b (text .encode (), digest_size = 16 )
8888 hash_bytes = hash_obj .digest ()
8989
9090 # Convert to floats
@@ -201,8 +201,9 @@ async def store(self, memory_data: Dict[str, Any]) -> str:
201201 """Store a memory"""
202202
203203 # Generate ID
204- memory_id = hashlib .md5 (
205- f"{ memory_data .get ('content' , '' )} { time .time ()} " .encode ()
204+ memory_id = hashlib .blake2b (
205+ f"{ memory_data .get ('content' , '' )} { time .time ()} " .encode (),
206+ digest_size = 16
206207 ).hexdigest ()
207208
208209 # Extract content
@@ -275,7 +276,7 @@ async def search(self, query: str, limit: Optional[int] = None) -> List[Memory]:
275276 self .logger .debug ("Searching for: %s..." , query [:100 ])
276277
277278 # Check cache first
278- cache_key = hashlib .md5 (f"{ query } { limit } " .encode ()).hexdigest ()
279+ cache_key = hashlib .blake2b (f"{ query } { limit } " .encode (), digest_size = 16 ).hexdigest ()
279280 if cache_key in self .memory_cache :
280281 self .cache_hits += 1
281282 self .logger .debug ("Cache hit for query" )
@@ -437,7 +438,7 @@ async def consolidate(self):
437438 summary = f"Consolidated { len (old_memories )} memories from before { cutoff_date } "
438439
439440 # Store consolidation
440- consolidation_id = hashlib .md5 (f"{ summary } { time .time ()} " .encode ()).hexdigest ()
441+ consolidation_id = hashlib .blake2b (f"{ summary } { time .time ()} " .encode (), digest_size = 16 ).hexdigest ()
441442
442443 cursor .execute ('''
443444 INSERT INTO consolidations (id, summary, memory_ids, timestamp)
@@ -450,9 +451,10 @@ async def consolidate(self):
450451 ))
451452
452453 # Delete old memories
453- cursor .execute ('''
454+ placeholders = ',' .join ('?' * len (memory_ids ))
455+ cursor .execute (f'''
454456 DELETE FROM memories
455- WHERE id IN ({','.join(['?'] * len(memory_ids)) })
457+ WHERE id IN ({ placeholders } )
456458 ''' , memory_ids )
457459
458460 conn .commit ()
0 commit comments