Don't hardcode PGVector distance strategies (#10265)

- Description: Remove hardcoded/duplicated distance strategies in the
PGVector store.
- Issue: NA
- Dependencies: NA
- Tag maintainer: for a quicker response, tag the relevant maintainer
(see below),
- Twitter handle: @archmonkeymojo

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
Brian Antonelli 2023-09-06 18:20:44 -04:00 committed by GitHub
parent 86cb9da735
commit 4df101cf77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -349,16 +349,16 @@ class PGVector(VectorStore):
@property
def distance_strategy(self) -> Any:
if self._distance_strategy == "l2":
if self._distance_strategy == DistanceStrategy.EUCLIDEAN:
return self.EmbeddingStore.embedding.l2_distance
elif self._distance_strategy == "cosine":
elif self._distance_strategy == DistanceStrategy.COSINE:
return self.EmbeddingStore.embedding.cosine_distance
elif self._distance_strategy == "inner":
elif self._distance_strategy == DistanceStrategy.MAX_INNER_PRODUCT:
return self.EmbeddingStore.embedding.max_inner_product
else:
raise ValueError(
f"Got unexpected value for distance: {self._distance_strategy}. "
f"Should be one of `l2`, `cosine`, `inner`."
f"Should be one of {', '.join([ds.value for ds in DistanceStrategy])}."
)
def similarity_search_with_score_by_vector(