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:
Djordje 2024-08-23 19:30:04 +04:00 committed by GitHub
parent b38c83ff93
commit 22f9ae489f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,7 +2,7 @@ from __future__ import annotations
import uuid
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
from langchain_core.documents import Document
@ -733,6 +733,23 @@ class OpenSearchVectorSearch(VectorStore):
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(
self,
query: str,