fix(memory): rescue entity-linked search candidates - #7101
Conversation
dlowzzxx
left a comment
There was a problem hiding this comment.
Correctly fixes Step 7 gap where entityBoosts could never rescue memories absent from semanticResults by point-fetching via vectorStore.get() in mem0/memory/main.py:1713 and mem0-ts/src/oss/src/memory/index.ts:1614 bounded to min(internalLimit,60) and de-duplicated via candidateIds. The fail-closed matchesSimpleRescueFilters rejecting $or/$and/$not and non-scalar filters (*, arrays, objects) is the right boundary — avoids reimplementing backend semantics while still rechecking scope, expiration_date, and data after fetch. Scoring change in mem0/utils/scoring.py:112 properly gates isEntityRescue candidates (require entityBoost>0, allow score=undefined, but still enforce threshold if numeric). Coverage validates deduplication and fetch-failure tolerance. LGTM
Linked Issue
Closes #5742
Description
Hybrid search now keeps entity-linked memories in the candidate pool when semantic retrieval misses them. The change admits only candidates with an active rescue signal, preserves the existing semantic threshold for ordinary results, and applies scope and expiry checks to point-fetched memories.
Root cause
The sync, async, and TypeScript OSS search paths built Step 7 candidates exclusively from semantic results. Entity boosts were calculated separately, so an entity-linked memory could never reach scoring when it was absent from semantic top-k.
Scope
This PR covers entity rescue only. Keyword-only candidate union remains in PR #6378. Simple equality filters and expiry are rechecked after point fetch; complex filter expressions fail closed for rescue and continue through the existing vector-store path. Hosted API search, graph-memory ranking, and vector-store adapter contracts are unchanged.
Type of Change
Breaking Changes
N/A
Test Coverage
Verification:
Checklist
The entity-rescue boundary follows the current hybrid-search contract and preserves the existing scoring, filtering, expiry, and result-shape behavior. PR #5743 is closed prior art; PR #6378 remains the separate keyword-only slice.
Focused validation passed: Python
91 passedacrosstests/test_memory.pyandtests/utils/test_scoring.py, Ruff check, two focused TypeScript Jest suites with14tests, and targeted Prettier.