Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Cosine Similarity #109

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

enzofrnt
Copy link

@enzofrnt enzofrnt commented Dec 7, 2024

This pull request introduces a new CosineSimilarity function to the pgvector Django integration and updates the corresponding tests. The most important changes include adding the CosineSimilarity function, updating imports, and adding a new test case for CosineSimilarity.

CosineSimilarity must be useful for people who are wondering to use similarity instead of distance.

New feature addition:

  • pgvector/django/functions.py: Added a new class CosineSimilarity that inherits from DistanceBase and overrides the as_sql method to compute cosine similarity.

Import updates:

Test updates:

  • tests/test_django.py: Added
    This pull request introduces a new CosineSimilarity function to the pgvector Django package, along with corresponding tests. The changes primarily involve adding this new function and ensuring it is properly tested across different vector types.

Key Changes:

New Functionality:

  • Added CosineSimilarity class to pgvector/django/functions.py to calculate cosine similarity.

Import Adjustments:

  • Updated imports in pgvector/django/__init__.py to include CosineSimilarity.
  • Updated imports in tests/test_django.py to include CosineSimilarity.

Testing Enhancements:

  • Added test_vector_cosine_similarity method to test cosine similarity for regular vectors in tests/test_django.py.
  • Added test_halfvec_cosine_similarity method to test cosine similarity for half vectors in tests/test_django.py.
  • Added test_sparsevec_cosine_similarity method to test cosine similarity for sparse vectors in tests/test_django.py.

@enzofrnt enzofrnt changed the title Add support for Consine Similarity Add support for Cosine Similarity Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant