Skip to content

fix(memory): rescue entity-linked search candidates - #7101

Open
rodboev wants to merge 5 commits into
mem0ai:mainfrom
rodboev:pr/entity-rescued-search-candidates
Open

fix(memory): rescue entity-linked search candidates#7101
rodboev wants to merge 5 commits into
mem0ai:mainfrom
rodboev:pr/entity-rescued-search-candidates

Conversation

@rodboev

@rodboev rodboev commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

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

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactor (no functional changes)
  • Documentation update

Breaking Changes

N/A

Test Coverage

  • I added/updated unit tests
  • I added/updated integration tests
  • I tested manually (describe below)
  • No tests needed

Verification:

  • Focused Python sync/async search and scoring tests
  • Focused TypeScript OSS search and scoring tests
  • Relevant package suites

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally
  • I have updated documentation if needed

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 passed across tests/test_memory.py and tests/utils/test_scoring.py, Ruff check, two focused TypeScript Jest suites with 14 tests, and targeted Prettier.

@github-actions github-actions Bot added sdk-typescript TypeScript/Node.js SDK specific sdk-python Python SDK specific vector-store Vector store backends (Qdrant, PGVector, Redis, etc.) labels Aug 24, 2026

@dlowzzxx dlowzzxx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk-python Python SDK specific sdk-typescript TypeScript/Node.js SDK specific vector-store Vector store backends (Qdrant, PGVector, Redis, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(oss): hybrid search drops keyword-only and entity-rescued memories

2 participants