Skip to content

Commit 754f3c4

Browse files
cjberccurme
andauthored
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 <[email protected]>
1 parent 3f1d652 commit 754f3c4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

libs/community/langchain_community/retrievers/pinecone_hybrid_search.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ def _get_relevant_documents(
173173
final_result = []
174174
for res in result["matches"]:
175175
context = res["metadata"].pop("context")
176-
final_result.append(
177-
Document(page_content=context, metadata=res["metadata"])
178-
)
176+
metadata = res["metadata"]
177+
if "score" not in metadata and "score" in res:
178+
metadata["score"] = res["score"]
179+
final_result.append(Document(page_content=context, metadata=metadata))
179180
# return search results as json
180181
return final_result

0 commit comments

Comments
 (0)