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:
+6
-6
@@ -548,7 +548,7 @@ class Database:
|
|||||||
finally:
|
finally:
|
||||||
conn.close()
|
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."""
|
"""Get the N most recent non-expired memories for a user."""
|
||||||
if not self._available:
|
if not self._available:
|
||||||
return []
|
return []
|
||||||
@@ -583,7 +583,7 @@ class Database:
|
|||||||
finally:
|
finally:
|
||||||
conn.close()
|
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."""
|
"""Get non-expired memories matching any of the given topic keywords via LIKE."""
|
||||||
if not self._available:
|
if not self._available:
|
||||||
return []
|
return []
|
||||||
@@ -655,18 +655,18 @@ class Database:
|
|||||||
finally:
|
finally:
|
||||||
conn.close()
|
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.
|
"""Delete excess memories for a user beyond the cap, keeping high importance and newest first.
|
||||||
Returns count deleted."""
|
Returns count deleted."""
|
||||||
if not self._available:
|
if not self._available:
|
||||||
return 0
|
return 0
|
||||||
try:
|
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:
|
except Exception:
|
||||||
logger.exception("Failed to prune excess memories")
|
logger.exception("Failed to prune excess memories")
|
||||||
return 0
|
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()
|
conn = self._connect()
|
||||||
try:
|
try:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
@@ -689,7 +689,7 @@ class Database:
|
|||||||
) ranked
|
) ranked
|
||||||
WHERE rn > ?
|
WHERE rn > ?
|
||||||
)""",
|
)""",
|
||||||
user_id, cap,
|
user_id, max_memories,
|
||||||
)
|
)
|
||||||
count = cursor.rowcount
|
count = cursor.rowcount
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user