mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-19 11:08:55 +00:00
add reranking to azuresearch (#12454)
-**Description** Adds returning the reranking score when using semantic search -**Issue:* #12317 --------- Co-authored-by: Adam Law <adamlaw@microsoft.com> Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
389459af8f
commit
df4960a6d8
@ -474,14 +474,32 @@ class AzureSearch(VectorStore):
|
||||
Returns:
|
||||
List[Document]: A list of documents that are most similar to the query text.
|
||||
"""
|
||||
docs_and_scores = self.semantic_hybrid_search_with_score(
|
||||
docs_and_scores = self.semantic_hybrid_search_with_score_and_rerank(
|
||||
query, k=k, filters=kwargs.get("filters", None)
|
||||
)
|
||||
return [doc for doc, _ in docs_and_scores]
|
||||
return [doc for doc, _, _ in docs_and_scores]
|
||||
|
||||
def semantic_hybrid_search_with_score(
|
||||
self, query: str, k: int = 4, filters: Optional[str] = None
|
||||
self, query: str, k: int = 4, **kwargs: Any
|
||||
) -> List[Tuple[Document, float]]:
|
||||
"""
|
||||
Returns the most similar indexed documents to the query text.
|
||||
|
||||
Args:
|
||||
query (str): The query text for which to find similar documents.
|
||||
k (int): The number of documents to return. Default is 4.
|
||||
|
||||
Returns:
|
||||
List[Document]: A list of documents that are most similar to the query text.
|
||||
"""
|
||||
docs_and_scores = self.semantic_hybrid_search_with_score_and_rerank(
|
||||
query, k=k, filters=kwargs.get("filters", None)
|
||||
)
|
||||
return [(doc, score) for doc, score, _ in docs_and_scores]
|
||||
|
||||
def semantic_hybrid_search_with_score_and_rerank(
|
||||
self, query: str, k: int = 4, filters: Optional[str] = None
|
||||
) -> List[Tuple[Document, float, float]]:
|
||||
"""Return docs most similar to query with an hybrid query.
|
||||
|
||||
Args:
|
||||
@ -551,6 +569,7 @@ class AzureSearch(VectorStore):
|
||||
},
|
||||
),
|
||||
float(result["@search.score"]),
|
||||
float(result["@search.reranker_score"]),
|
||||
)
|
||||
for result in results
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user