Fix #1448: fix: 添加包含偏好信息的记忆后,使用搜索接口POST /product/search无法检索到任何记忆#1983
Fix #1448: fix: 添加包含偏好信息的记忆后,使用搜索接口POST /product/search无法检索到任何记忆#1983Memtensor-AI wants to merge 1 commit into
Conversation
`/product/search` (fine mode) cannot find memories added through the fast pipeline because `tree_text_memory._graph_recall` filters Neo4j candidates by `n.key IN parsed_goal.keys` and tag overlap >= 2. Fast-mode add stores the raw chat-formatted text as `key` and `["mode:fast"]` as `tags`, while fine-mode search asks the LLM for high-level semantic keys/tags, so the strict candidate set comes back empty and the structured branch silently drops the memory. Extract a lenient `_node_matches_parsed_goal` post-filter that also accepts substring matches and a single tag overlap, and add `_fallback_candidates_by_substring` which uses `graph_store.get_all_memory_items` (bounded to 50) to recover fast-mode memories. Restricted to WorkingMemory / LongTermMemory / UserMemory / OuterMemory so PreferenceMemory and other scopes keep their dedicated retrievers. Regression tests cover the reporter's exact scenario, substring post-filter, single-tag overlap, and graceful empty return.
✅ Automated Test Results: PASSEDNo applicable test scope for the changed files — automated tests skipped. Changed paths do not map to any configured scope (env.yaml source_mapping). Manual review recommended. Branch: |
🤖 Open Code ReviewTarget: PR #1983 🔍 OpenCodeReview found 7 issue(s) in this PR. 1.
|
Description
Fixes #1448 —
/product/search(fine mode) returning empty results for memories added through the fast pipeline. Root cause:tree_text_memory._graph_recallfiltered Neo4j candidates byn.key IN parsed_goal.keysand tag overlap ≥ 2, but fast-mode add stores the raw chat-formatted text askeyand only["mode:fast"]astags, while fine-mode search asks the LLM for high-level semantic keys/tags, so the strict candidate set comes back empty and the structured branch silently dropped the memory.The fix extracts a lenient
_node_matches_parsed_goalpost-filter that accepts substring key matches and a single tag overlap, and adds_fallback_candidates_by_substringwhich uses the existinggraph_store.get_all_memory_itemsAPI (bounded to 50 candidates per call) to substring-matchparsed_goal.keysagainst storedkey + memorytext whenever the strict candidate set is empty. The fallback is scoped to WorkingMemory / LongTermMemory / UserMemory / OuterMemory so PreferenceMemory and other specialized scopes keep their dedicated retrievers. Wrapped in try/except so unexpected backends silently degrade to the previous behavior. No API, schema, or migration impact.Tests: 4 new regression tests in
tests/memories/textual/test_tree_retriever.pycover the reporter's exact scenario, substring post-filter, single-tag overlap, and graceful empty return. All 62 tests undertests/memories/textual/pass after the fix;ruff checkandruff formatboth clean. The 6 unrelated failures undertests/mem_reader/andtests/api/are pre-existing on thedev-20260624-v2.0.22baseline (verified by stashing the fix and re-running).Related Issue (Required): Fixes #1448
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.
Reviewer Checklist