| 179 | |
| 180 | |
| 181 | async def find_similar_memories(embedding: list[float], deps: Deps) -> list[MemoryNode]: |
| 182 | async with deps.pool.acquire() as conn: |
| 183 | rows = await conn.fetch( |
| 184 | """ |
| 185 | SELECT id, content, summary, importance, access_count, timestamp, embedding |
| 186 | FROM memories |
| 187 | ORDER BY embedding <-> $1 |
| 188 | LIMIT 5 |
| 189 | """, |
| 190 | embedding, |
| 191 | ) |
| 192 | memories = [ |
| 193 | MemoryNode( |
| 194 | id=row["id"], |
| 195 | content=row["content"], |
| 196 | summary=row["summary"], |
| 197 | importance=row["importance"], |
| 198 | access_count=row["access_count"], |
| 199 | timestamp=row["timestamp"], |
| 200 | embedding=row["embedding"], |
| 201 | ) |
| 202 | for row in rows |
| 203 | ] |
| 204 | return memories |
| 205 | |
| 206 | |
| 207 | async def update_importance(user_embedding: list[float], deps: Deps): |