Skip to content

Conversation

@kubaodias
Copy link

Summary

  • Convert cosine distance to similarity score (1 - distance) in PGVector search results
  • Ensures consistency with other vector stores (Qdrant, Weaviate) where higher scores indicate greater similarity
  • Fixes threshold filtering which was broken due to inverted scores (was filtering out best matches instead of worst)

Changes

  • mem0/vector_stores/pgvector.py: Add score conversion with clamping to [0, 1] range
  • tests/vector_stores/test_pgvector.py: Update 14 assertions + add TestPGVectorScoreSemantics class

Test plan

  • Run existing pgvector tests: pytest tests/vector_stores/test_pgvector.py
  • Verify score semantics tests pass (exact match → 1.0, orthogonal → 0.0)
  • Verify threshold filtering works correctly with similarity scores

Related: #3804
Precedent: #3521 (Weaviate score fix)

🤖 Generated with Claude Code

Convert cosine distance to similarity score (1 - distance) to ensure
consistency with other vector stores where higher scores indicate
greater similarity.

- Update pgvector.py search method with score conversion
- Update existing test assertions to expect similarity scores
- Add TestPGVectorScoreSemantics class with semantic tests

Fixes threshold filtering which was broken due to inverted scores.

Related: mem0ai#3804

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@CLAassistant
Copy link

CLAassistant commented Dec 17, 2025

CLA assistant check
All committers have signed the CLA.

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

Labels

None yet

2 participants