From a5ad7ab26116db899616e7aa2a34147af8911bc4 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 15 Jun 2026 22:54:25 +0200 Subject: [PATCH] Improve hit deduplication by enforcing a minimum score threshold --- backend/chat_memory.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/chat_memory.py b/backend/chat_memory.py index 5dccb50..34d7431 100644 --- a/backend/chat_memory.py +++ b/backend/chat_memory.py @@ -539,11 +539,13 @@ def _trim(value: Any, limit: int) -> str: return text_value[:limit].rstrip() + "..." -def _dedupe_hits(candidates: Sequence[Dict[str, Any]], top_k: int) -> List[Dict[str, Any]]: +def _dedupe_hits(candidates: Sequence[Dict[str, Any]], top_k: int, *, minimum_score: float) -> List[Dict[str, Any]]: seen = set() ordered = sorted(candidates, key=lambda item: (float(item.get("_score") or 0), int(item.get("assistant_message_row_id") or 0)), reverse=True) hits: List[Dict[str, Any]] = [] for item in ordered: + if float(item.get("_score") or 0) < minimum_score: + continue key = item.get("turn_key") or (item.get("session_id"), item.get("assistant_message_id")) if key in seen: continue