Skip to content

fix: deterministic search ranking ties by recency - #6626

Open
chakshu-dhannawat wants to merge 1 commit into
mem0ai:mainfrom
chakshu-dhannawat:fix/search-tie-break-recency
Open

fix: deterministic search ranking ties by recency#6626
chakshu-dhannawat wants to merge 1 commit into
mem0ai:mainfrom
chakshu-dhannawat:fix/search-tie-break-recency

Conversation

@chakshu-dhannawat

Copy link
Copy Markdown

Linked Issue

Closes #5205

Description

Adds stable tie-breaking to score_and_rank (Python) and scoreAndRank (TypeScript) so memories with the same hybrid score are ordered deterministically. The tie-break order is:

  1. newer updated_at
  2. newer created_at
  3. stable memory ID

Missing or malformed timestamps are treated as older than valid ones. This removes backend-order randomness without changing the relevance scoring or adding a general recency boost.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Breaking Changes

N/A

Test Coverage

  • I added/updated unit tests
  • Added Python tests in tests/utils/test_scoring.py and TypeScript tests in mem0-ts/src/oss/tests/scoring.test.ts covering equal-score ties, missing/malformed timestamps, and ID stability.
  • Ran MEM0_TELEMETRY=False hatch run pytest tests/utils/test_scoring.py (26 passed) and pnpm run test -- scoring.test (8 passed).
  • Ran hatch run ruff check and pnpm run build successfully.

Checklist

  • My code follows the project style guidelines
  • I have performed a self-review of my code
  • I have added tests that prove my fix works
  • New and existing tests pass locally

Make `score_and_rank` / `scoreAndRank` break equal combined scores by:
1. newer `updated_at`
2. newer `created_at`
3. stable memory ID asc

Missing or malformed timestamps are treated as older than valid ones.
Implemented in both Python and TypeScript OSS with parity tests.

Closes mem0ai#5205
@CLAassistant

CLAassistant commented Jul 28, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added sdk-typescript TypeScript/Node.js SDK specific sdk-python Python SDK specific labels Jul 28, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

similar memories repeat quite frequently

2 participants