Skip to content

fix(redis): cast vector_distance to float to prevent TypeError on threshold search#4298

Open
NIK-TIGER-BILL wants to merge 1 commit intomem0ai:mainfrom
NIK-TIGER-BILL:fix/redis-vector-distance-str-to-float
Open

fix(redis): cast vector_distance to float to prevent TypeError on threshold search#4298
NIK-TIGER-BILL wants to merge 1 commit intomem0ai:mainfrom
NIK-TIGER-BILL:fix/redis-vector-distance-str-to-float

Conversation

@NIK-TIGER-BILL
Copy link

Problem

redisvl returns vector_distance as a string, not a float. When memory.search() is called with a threshold parameter, mem0 compares the score to the threshold:

score=result["vector_distance"]  # str, e.g. '0.123456'

This causes (closes #4294):

TypeError: '>=' not supported between instances of 'str' and 'float'

Fix

Wrap the vector_distance value in float() before assigning it to score:

score=float(result["vector_distance"])  # ✅

One-line change, no behaviour change for valid distances.

…eshold search

redisvl returns vector_distance as a string, not a float. When memory.search()
is called with a threshold parameter, the comparison:
    score >= threshold
fails with:
    TypeError: '>=' not supported between instances of 'str' and 'float'

Fix: wrap result['vector_distance'] in float() before assigning to score.

Closes mem0ai#4294
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redis vector_distance returned as string causes threshold search to fail

2 participants