Skip to content

fix(vector_stores/valkey): make search score metric-aware - #7230

Open
ktz03 wants to merge 1 commit into
mem0ai:mainfrom
ktz03:fix/valkey-distance-score
Open

ktz03 wants to merge 1 commit into
mem0ai:mainfrom
ktz03:fix/valkey-distance-score

Conversation

@ktz03

@ktz03 ktz03 commented Sep 5, 2026

Copy link
Copy Markdown

Linked Issue

Closes #7229

Description

Sibling of #6546 / #6547 for the Valkey store.

Search scoring hardcoded max(0.0, 1.0 - raw_distance), which is only correct for cosine. With L2 (already accepted by create_col(distance=...)), unbounded distances collapse almost every hit with d > 1 to 0.0.

This PR:

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. Cosine (the default) is unchanged; only L2 scoring is corrected, and index init now respects the configured metric.

Test Coverage

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

Added regression tests in tests/vector_stores/test_valkey.py:

  • cosine keeps 1 - d
  • L2 uses the bounded map and does not collapse d=4.0 to 0
  • create_col(distance="L2") updates scoring, not only FT.CREATE

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 works
  • New and existing tests pass locally
  • I have updated documentation if needed

Sibling of mem0ai#6546/mem0ai#6547. Hardcoded 1-distance collapses L2 hits.
Closes mem0ai#7229.
@CLAassistant

CLAassistant commented Sep 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Thanks for taking the time to open this.

We only review pull requests that fix an issue we have already agreed to take on, so this one is closed for now.
Closed does not mean rejected. It means it is not in the queue yet, and reopening takes about a minute.

To get it reviewed:

  1. Make sure an issue describes the problem, with the version you are on, a runnable reproduction, and the real output or traceback you saw.
  2. Link it from this pull request description with Closes #<number>.
  3. Ask a maintainer to label that issue accepted. This pull request reopens by itself when they do.

Issue already labeled accepted? Just add Closes #<number> to the description. That reopens this too.

Documentation-only changes skip this gate entirely.

See CONTRIBUTING.md for the full policy.

@github-actions github-actions Bot closed this Sep 5, 2026
@github-actions github-actions Bot added sdk-python Python SDK specific vector-store Vector store backends (Qdrant, PGVector, Redis, etc.) labels Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Hi @ktz03, thanks for opening this pull request.

This is just a soft check: you are not yet in this repo's vouched contributor list (.github/VOUCHED.td). Nothing is blocked and there is nothing you need to do.

A maintainer can vouch for you by commenting !vouch @ktz03 on any issue.

@ktz03

ktz03 commented Sep 5, 2026

Copy link
Copy Markdown
Author

Pending accepted on #7229 (mem0 PR gate). Implementation mirrors #6547. Will auto-reopen once labeled.

@github-actions

Copy link
Copy Markdown

An accepted issue is linked now, so this is open again and ready for review.

This branch has not been deployed

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

Labels

sdk-python Python 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(vector_stores/valkey): search score hardcoded for cosine, breaks L2 ranking

3 participants