From 754f3c41f9dd3344b9d79cc9830791bd168422d6 Mon Sep 17 00:00:00 2001 From: Cillian Berragan Date: Wed, 28 Aug 2024 14:11:06 +0100 Subject: [PATCH] community: add score to PineconeHybridSearchRetriever (#25781) **Description:** Adds the 'score' returned by Pinecone to the `PineconeHybridSearchRetriever` list of returned Documents. There is currently no way to return the score when using Pinecone hybrid search, so in this PR I include it by default. --------- Co-authored-by: Chester Curme --- .../retrievers/pinecone_hybrid_search.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/retrievers/pinecone_hybrid_search.py b/libs/community/langchain_community/retrievers/pinecone_hybrid_search.py index 4c51779681..dcbf35e38d 100644 --- a/libs/community/langchain_community/retrievers/pinecone_hybrid_search.py +++ b/libs/community/langchain_community/retrievers/pinecone_hybrid_search.py @@ -173,8 +173,9 @@ class PineconeHybridSearchRetriever(BaseRetriever): final_result = [] for res in result["matches"]: context = res["metadata"].pop("context") - final_result.append( - Document(page_content=context, metadata=res["metadata"]) - ) + metadata = res["metadata"] + if "score" not in metadata and "score" in res: + metadata["score"] = res["score"] + final_result.append(Document(page_content=context, metadata=metadata)) # return search results as json return final_result