From 4df101cf77ee972b20a6d24e42f7a93ead17d94f Mon Sep 17 00:00:00 2001 From: Brian Antonelli Date: Wed, 6 Sep 2023 18:20:44 -0400 Subject: [PATCH] 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 --- libs/langchain/langchain/vectorstores/pgvector.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/langchain/langchain/vectorstores/pgvector.py b/libs/langchain/langchain/vectorstores/pgvector.py index 6b02fc19c0..2fc66c0a0e 100644 --- a/libs/langchain/langchain/vectorstores/pgvector.py +++ b/libs/langchain/langchain/vectorstores/pgvector.py @@ -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(