diff options
Diffstat (limited to 'personal_agent/memory')
| -rw-r--r-- | personal_agent/memory/models.py | 13 | ||||
| -rw-r--r-- | personal_agent/memory/store.py | 23 |
2 files changed, 26 insertions, 10 deletions
diff --git a/personal_agent/memory/models.py b/personal_agent/memory/models.py index aab2064..957f16e 100644 --- a/personal_agent/memory/models.py +++ b/personal_agent/memory/models.py @@ -15,11 +15,20 @@ class LongTermMemory: content: str category: MemoryCategory created_at: datetime + importance: int @classmethod - def create(cls, content: str, category: MemoryCategory) -> LongTermMemory: + def create( + cls, content: str, category: MemoryCategory, importance: int = 2 + ) -> LongTermMemory: + if importance not in (1, 2, 3): + raise ValueError("importance must be between 1 and 3") return cls( - id=uuid7(), content=content, category=category, created_at=datetime.now(UTC) + id=uuid7(), + content=content, + category=category, + created_at=datetime.now(UTC), + importance=importance, ) diff --git a/personal_agent/memory/store.py b/personal_agent/memory/store.py index 164d11f..5666a73 100644 --- a/personal_agent/memory/store.py +++ b/personal_agent/memory/store.py @@ -15,10 +15,16 @@ class LongTermMemoryStore: with self.database.connect() as connection: connection.execute( """ - INSERT INTO memories (id, content, category, created_at) - VALUES (?, ?, ?, ?) + INSERT INTO memories (id, content, category, created_at, importance) + VALUES (?, ?, ?, ?, ?) """, - (str(memory.id), memory.content, memory.category.value, created_at), + ( + str(memory.id), + memory.content, + memory.category.value, + created_at, + memory.importance, + ), ) connection.execute( @@ -35,7 +41,7 @@ class LongTermMemoryStore: with self.database.connect() as connection: row = connection.execute( """ - SELECT id, content, category, created_at + SELECT id, content, category, created_at, importance FROM memories WHERE id = ? """, @@ -51,7 +57,7 @@ class LongTermMemoryStore: with self.database.connect() as connection: rows = connection.execute( """ - SELECT id, content, category, created_at + SELECT id, content, category, created_at, importance FROM memories ORDER BY id """ @@ -96,7 +102,7 @@ class LongTermMemoryStore: ) sql = """ - SELECT m.id, m.content, m.category, m.created_at + SELECT m.id, m.content, m.category, m.created_at, m.importance FROM memories_fts as f JOIN memories AS m ON m.rowid = f.rowid WHERE memories_fts MATCH ? @@ -116,12 +122,13 @@ class LongTermMemoryStore: return [self._from_row(row) for row in rows] @staticmethod - def _from_row(row: tuple[str, str, str, str]) -> LongTermMemory: - memory_id, content, category, created_at = row + def _from_row(row: tuple[str, str, str, str, int]) -> LongTermMemory: + memory_id, content, category, created_at, importance = row return LongTermMemory( id=UUID(memory_id), content=content, category=MemoryCategory(category), created_at=datetime.fromisoformat(created_at), + importance=importance, ) |
