Add configurable prefetch limit and score threshold #2

Merged
Pakobbix merged 1 commits from mem0-prefetch-improvements into main 2026-04-12 15:13:24 +00:00
Owner

Fixes the issue where simple queries like "hello" returned too much memory information.

Changes

  • Configurable prefetch_limit (default: 3) - Controls max memories returned on prefetch
  • Configurable prefetch_score_threshold (default: 60%) - Filters out low-similarity results
  • Error messages - When Mem0 API is unavailable, AI receives error context to inform user
  • Circuit breaker fix - No longer trips when API succeeds but no memories match threshold

Configuration

Via $HERMES_HOME/mem0-local.json:

{
  "prefetch_limit": 3,
  "prefetch_score_threshold": 60
}

Or via environment variables: MEM0_PREFETCH_LIMIT, MEM0_PREFETCH_SCORE_THRESHOLD

Fixes the issue where simple queries like "hello" returned too much memory information. ## Changes - **Configurable prefetch_limit** (default: 3) - Controls max memories returned on prefetch - **Configurable prefetch_score_threshold** (default: 60%) - Filters out low-similarity results - **Error messages** - When Mem0 API is unavailable, AI receives error context to inform user - **Circuit breaker fix** - No longer trips when API succeeds but no memories match threshold ## Configuration Via `$HERMES_HOME/mem0-local.json`: ```json { "prefetch_limit": 3, "prefetch_score_threshold": 60 } ``` Or via environment variables: `MEM0_PREFETCH_LIMIT`, `MEM0_PREFETCH_SCORE_THRESHOLD`
ARIA added 1 commit 2026-04-12 15:12:12 +00:00
- Add prefetch_limit config (default: 3) to control max memories returned
- Add prefetch_score_threshold config (default: 60%) to filter low-similarity results
- Add error messages when Mem0 API is unavailable
- Fix circuit breaker to not trip on successful API calls with no matching memories
- Properly type-convert config values from JSON
Collaborator

No issues found — changes look consistent with the stated intent.

The implementation correctly reflects the commit message:

  • Configuration: prefetch_limit and prefetch_score_threshold are properly loaded from config/env with defaults (3 and 60).
  • Logic: The filtering logic r.get("score", 0) >= threshold correctly applies the percentage threshold.
  • Error Handling: The circuit breaker behavior is updated to return a specific error string instead of an empty string, and this string is formatted consistently in both sync (queue_prefetch_and_get) and async (queue_prefetch) paths.
  • Circuit Breaker Fix: The code explicitly calls self._record_success() even when filtered is empty (no matches), which aligns with the intent to prevent tripping the breaker on successful API calls that simply return no relevant memories.
  • Thread Safety: The async prefetch path correctly uses self._prefetch_lock when updating self._prefetch_result.
✅ No issues found — changes look consistent with the stated intent. The implementation correctly reflects the commit message: - **Configuration**: `prefetch_limit` and `prefetch_score_threshold` are properly loaded from config/env with defaults (3 and 60). - **Logic**: The filtering logic `r.get("score", 0) >= threshold` correctly applies the percentage threshold. - **Error Handling**: The circuit breaker behavior is updated to return a specific error string instead of an empty string, and this string is formatted consistently in both sync (`queue_prefetch_and_get`) and async (`queue_prefetch`) paths. - **Circuit Breaker Fix**: The code explicitly calls `self._record_success()` even when `filtered` is empty (no matches), which aligns with the intent to prevent tripping the breaker on successful API calls that simply return no relevant memories. - **Thread Safety**: The async prefetch path correctly uses `self._prefetch_lock` when updating `self._prefetch_result`.
Pakobbix merged commit 9aa76093d7 into main 2026-04-12 15:13:24 +00:00
Pakobbix deleted branch mem0-prefetch-improvements 2026-04-12 15:13:24 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ARIA/mem0-local-hermes-plugin#2