mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 23:54:14 +00:00
community: Opensearch - added score function for similarity_score_threshold (#23928)
This PR resolves the NotImplemented error for the similarity_score_threshold search type for OpenSearch.
This commit is contained in:
parent
b38c83ff93
commit
22f9ae489f
@ -2,7 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
import warnings
|
import warnings
|
||||||
from typing import Any, Dict, Iterable, List, Optional, Tuple
|
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
@ -733,6 +733,23 @@ class OpenSearchVectorSearch(VectorStore):
|
|||||||
item.get("delete", {}).get("error") for item in response["items"]
|
item.get("delete", {}).get("error") for item in response["items"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _identity_fn(score: float) -> float:
|
||||||
|
return score
|
||||||
|
|
||||||
|
def _select_relevance_score_fn(self) -> Callable[[float], float]:
|
||||||
|
"""
|
||||||
|
The 'correct' relevance function
|
||||||
|
may differ depending on a few things, including:
|
||||||
|
- the distance / similarity metric used by the VectorStore
|
||||||
|
- the scale of your embeddings (OpenAI's are unit normed. Many others are not!)
|
||||||
|
- embedding dimensionality
|
||||||
|
- etc.
|
||||||
|
|
||||||
|
Vectorstores should define their own selection based method of relevance.
|
||||||
|
"""
|
||||||
|
return self._identity_fn
|
||||||
|
|
||||||
def similarity_search(
|
def similarity_search(
|
||||||
self,
|
self,
|
||||||
query: str,
|
query: str,
|
||||||
|
Loading…
Reference in New Issue
Block a user