fix: normalize vector store scores to similarity (higher = better)
The threshold parameter in Memory.search() was silently broken for 11 vector stores because they returned raw distance scores (lower = better) while the threshold check assumed similarity scores (higher = better). This caused threshold filtering to be inverted — good matches got dropped and bad matches passed through. Convert all affected vector stores to return similarity scores: - Cosine distance stores: score = max(0.0, 1.0 - distance) - L2 distance stores: score = 1.0 / (1.0 + distance) - Stores computing similarity then discarding it: return similarity directly Fixes #4453 Related: #3283 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
431cba20e9
commit
224fd6c7d8
@@ -135,7 +135,8 @@ class Supabase(VectorStoreBase):
|
||||
data=vectors, limit=limit, filters=filters, include_metadata=True, include_value=True
|
||||
)
|
||||
|
||||
return [OutputData(id=str(result[0]), score=float(result[1]), payload=result[2]) for result in results]
|
||||
# Convert cosine distance to similarity score (higher = more similar)
|
||||
return [OutputData(id=str(result[0]), score=max(0.0, 1.0 - float(result[1])), payload=result[2]) for result in results]
|
||||
|
||||
def delete(self, vector_id: str):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user