Skip to content

The agent engineering platform.

fix: pgvector search_type of similarity_score_threshold not working (#7771)

王斌(Bin Wang)b65102bdb23e
diff --git a/langchain/vectorstores/base.py b/langchain/vectorstores/base.py
index d529e253ab..a09ee25759 100644
--- a/langchain/vectorstores/base.py
+++ b/langchain/vectorstores/base.py
@@ -234,6 +234,8 @@ class VectorStore(ABC):
Returns:
List of Tuples of (doc, similarity_score)
"""
+ score_threshold = kwargs.pop("score_threshold", None)
+
docs_and_similarities = self._similarity_search_with_relevance_scores(
query, k=k, **kwargs
)
@@ -246,7 +248,6 @@ class VectorStore(ABC):
f" 0 and 1, got {docs_and_similarities}"
)
- score_threshold = kwargs.get("score_threshold")
if score_threshold is not None:
docs_and_similarities = [
(doc, similarity)
diff --git a/langchain/vectorstores/pgvector.py b/langchain/vectorstores/pgvector.py
index b0958b78fa..a2969b9fa0 100644
--- a/langchain/vectorstores/pgvector.py
+++ b/langchain/vectorstores/pgvector.py
@@ -593,15 +593,15 @@ class PGVector(VectorStore):
# Default strategy is to rely on distance strategy provided
# in vectorstore constructor
- if self.distance_strategy == DistanceStrategy.COSINE:
+ if self._distance_strategy == DistanceStrategy.COSINE:
return self._cosine_relevance_score_fn
- elif self.distance_strategy == DistanceStrategy.EUCLIDEAN:
+ elif self._distance_strategy == DistanceStrategy.EUCLIDEAN:
return self._euclidean_relevance_score_fn
- elif self.distance_strategy == DistanceStrategy.MAX_INNER_PRODUCT:
+ elif self._distance_strategy == DistanceStrategy.MAX_INNER_PRODUCT:
return self._max_inner_product_relevance_score_fn
else:
raise ValueError(
"No supported normalization function"
- f" for distance_strategy of {self.distance_strategy}."
+ f" for distance_strategy of {self._distance_strategy}."
"Consider providing relevance_score_fn to PGVector constructor."
)