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>
pull/10257/head
Brian Antonelli 1 year ago committed by GitHub
parent 86cb9da735
commit 4df101cf77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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(

Loading…
Cancel
Save