Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
Don't hardcode PGVector distance strategies (langchain-ai#10265)
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
2 people authored and rsharath committed Sep 7, 2023
1 parent f081b27 commit e220fa9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libs/langchain/langchain/vectorstores/pgvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,16 @@ def similarity_search_with_score(

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

0 comments on commit e220fa9

Please sign in to comment.