From 9b31f454819c92ebe9a9b563ed79b0f18918727d Mon Sep 17 00:00:00 2001 From: yangluxin613 Date: Mon, 25 May 2026 09:02:07 +0800 Subject: [PATCH] fix(memory): _search_like ASCII query always returns empty matched_count only counted cjk_words hits; pure ASCII queries had cjk_words=[] so matched_count=0 and all SQL-matched rows were filtered out. Change to count across all tokens (cjk_words + ascii_words) so the LIKE fallback works correctly when FTS5 is unavailable. Co-Authored-By: Claude Sonnet 4.6 --- agent/memory/storage.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/agent/memory/storage.py b/agent/memory/storage.py index e8c6a505..1a004904 100644 --- a/agent/memory/storage.py +++ b/agent/memory/storage.py @@ -741,9 +741,11 @@ class MemoryStorage: results = [] for row in rows: # Dynamic score: reward chunks that contain more of the query words. - # matched_count should always be ≥1 (WHERE uses OR), but guard - # defensively so zero-match rows are never surfaced. - matched_count = sum(1 for w in cjk_words if w in row['text']) + # Use all tokens (CJK + ASCII) so pure-ASCII queries are not skipped. + # matched_count is always ≥1 because the WHERE clause uses OR, but + # guard defensively so unexpected zero-match rows are never surfaced. + text_lower = row['text'].lower() + matched_count = sum(1 for w in words if w.lower() in text_lower) if matched_count == 0: continue score = min(0.85, 0.3 + 0.15 * matched_count)