fix(recall): cap default limit to 30 + relevance-bound OR-broadening
memory_recall was returning almost the entire store instead of a small
set of relevant matches. Two compounding causes, both fixed here:
1. Default limit was 10000 (commit d03a77a "effectively unlimited").
recall_memories/MemoryRecall and the memory_recall MCP tool now
default to 30 (ceiling stays 10000 for callers that opt in).
2. The OR-broadening fallback (fires when the precise AND-match is
sparse) ordered by the importance hybrid and padded up to `limit`,
so with limit=10000 it flooded results with high-importance but
irrelevant memories. It now orders OR-matches by ts_rank(relevance)
DESC and applies a minimum-rank floor (OR_BROADEN_MIN_RANK=0.01) to
drop rows that merely contain a query word incidentally.
Tests: add test_recall_default_limit_is_capped (asserts 30 passed to
fetch) and test_recall_or_broadening_is_relevance_bounded (asserts the
OR query is relevance-ordered + rank-floored). Full suite 176 green,
ruff + mypy clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
1fa6c2031e
commit
1c0193f011
3 changed files with 64 additions and 4 deletions
|
|
@ -17,7 +17,9 @@ class MemoryRecall(BaseModel):
|
|||
expanded_query: str = ""
|
||||
category: Optional[str] = None
|
||||
sort_by: Literal["importance", "relevance", "recency"] = "importance"
|
||||
limit: int = Field(default=10000, ge=1, le=10000)
|
||||
# Default to a small top-N so recall returns the most relevant matches, not
|
||||
# the whole store. Ceiling stays high for callers that explicitly want more.
|
||||
limit: int = Field(default=30, ge=1, le=10000)
|
||||
|
||||
|
||||
class MemoryResponse(BaseModel):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue