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 <noreply@anthropic.com>
This commit is contained in:
yangluxin613
2026-05-25 09:02:07 +08:00
parent bc9c1691f5
commit 9b31f45481

View File

@@ -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)