Memory that Forgets on Purpose
Krish Verma's project caught my attention with its innovative approach to memory management in AI systems. He built a memory system that intentionally forgets information over time, which might sound counterintuitive but is actually a clever way to optimize memory usage.
Krish's system combines two techniques: time-based forgetting and pinning. The first technique involves setting a timer for each piece of information stored in memory. After a certain period (90 days, as specified in Krish's implementation), the information is automatically deleted. This prevents outdated information from accumulating and reduces memory clutter.
The second technique, pinning, allows certain pieces of information to remain in memory indefinitely. However, Krish implemented a clever twist: even pinned information will eventually expire after a year (365 days). This prevents pinned data from becoming a permanent memory leak.
Krish also introduced a "pin that never expires" feature, which allows users to designate certain pieces of information as essential and never delete them. This is useful for critical data that needs to be preserved at all costs.
To demonstrate the basic functionality of his memory system, Krish provided a simple Python example:
pythonimport time from dateutil import relativedelta class Memory: def __init__(self): self.data = {} def store(self, key, value, expires_in): self.data[key] = (value, expires_in + time.time()) def retrieve(self, key): if key in self.data: value, expires_at = self.data[key] if time.time() < expires_at: return value else: del self.data[key] return None # Create a memory instance memory = Memory() # Store some data memory.store('key1', 'value1', time.time() + 90 * 24 * 60 * 60) # Retrieve the data print(memory.retrieve('key1')) # Output: value1 # Wait for 90 days time.sleep(90 * 24 * 60 * 60) # Retrieve the data again print(memory.retrieve('key1')) # Output: None
This example shows how the memory system automatically deletes information after 90 days. You can adjust the expiration time and pin certain pieces of information to suit your needs.
Krish's memory system is a creative solution to the problem of memory management in AI systems. By implementing time-based forgetting and pinning, he has created a system that adapts to changing needs and prevents memory clutter. This approach has potential applications in various areas, such as AI model optimization and data storage and retrieval.
Krish's implementation is available on his blog post [1]. The Python dateutil library [2] is used to handle date and time calculations.
Try this
bash# Install the required libraries pip install python-dateutil # Run the example code python memory_example.py
This will create a memory instance and store some data. You can adjust the expiration time and pin certain pieces of information to see how the system works.
