fix: align default limits and parameter names to spec

- get_recent_memories: limit default 10 → 5
- get_memories_by_topics: limit default 10 → 5
- prune_excess_memories: rename 'cap' → 'max_memories'

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 12:50:47 -05:00
parent 75adafefd6
commit 8686f4fdd6

View File

@@ -548,7 +548,7 @@ class Database:
finally:
conn.close()
async def get_recent_memories(self, user_id: int, limit: int = 10) -> list[dict]:
async def get_recent_memories(self, user_id: int, limit: int = 5) -> list[dict]:
"""Get the N most recent non-expired memories for a user."""
if not self._available:
return []
@@ -583,7 +583,7 @@ class Database:
finally:
conn.close()
async def get_memories_by_topics(self, user_id: int, topic_keywords: list[str], limit: int = 10) -> list[dict]:
async def get_memories_by_topics(self, user_id: int, topic_keywords: list[str], limit: int = 5) -> list[dict]:
"""Get non-expired memories matching any of the given topic keywords via LIKE."""
if not self._available:
return []
@@ -655,18 +655,18 @@ class Database:
finally:
conn.close()
async def prune_excess_memories(self, user_id: int, cap: int = 50) -> int:
async def prune_excess_memories(self, user_id: int, max_memories: int = 50) -> int:
"""Delete excess memories for a user beyond the cap, keeping high importance and newest first.
Returns count deleted."""
if not self._available:
return 0
try:
return await asyncio.to_thread(self._prune_excess_memories_sync, user_id, cap)
return await asyncio.to_thread(self._prune_excess_memories_sync, user_id, max_memories)
except Exception:
logger.exception("Failed to prune excess memories")
return 0
def _prune_excess_memories_sync(self, user_id, cap) -> int:
def _prune_excess_memories_sync(self, user_id, max_memories) -> int:
conn = self._connect()
try:
cursor = conn.cursor()
@@ -689,7 +689,7 @@ class Database:
) ranked
WHERE rn > ?
)""",
user_id, cap,
user_id, max_memories,
)
count = cursor.rowcount
cursor.close()