fix: deterministic search ranking ties by recency - #6626
Open
chakshu-dhannawat wants to merge 1 commit into
Open
fix: deterministic search ranking ties by recency#6626chakshu-dhannawat wants to merge 1 commit into
chakshu-dhannawat wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issue
Closes #5205
Description
Adds stable tie-breaking to
score_and_rank(Python) andscoreAndRank(TypeScript) so memories with the same hybrid score are ordered deterministically. The tie-break order is:updated_atcreated_atMissing 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
Breaking Changes
N/A
Test Coverage
tests/utils/test_scoring.pyand TypeScript tests inmem0-ts/src/oss/tests/scoring.test.tscovering equal-score ties, missing/malformed timestamps, and ID stability.MEM0_TELEMETRY=False hatch run pytest tests/utils/test_scoring.py(26 passed) andpnpm run test -- scoring.test(8 passed).hatch run ruff checkandpnpm run buildsuccessfully.Checklist