Fix KeyError in pinecone wrapper (#568)

Pinecone can return multiple matches with different text keys in the
metadata, and the current behavior will throw a KeyError if one pops up
that isn't the expected text key. This PR only selects the matches with
the correct text key.
This commit is contained in:
Bernie G 2023-01-10 10:43:39 -05:00 committed by GitHub
parent 7a32cde5ff
commit d39ab27969
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,8 +81,9 @@ class Pinecone(VectorStore):
results = self._index.query([query_obj], top_k=k, include_metadata=True)
for res in results["matches"]:
metadata = res["metadata"]
text = metadata.pop(self._text_key)
docs.append(Document(page_content=text, metadata=metadata))
if self._text_key in metadata:
text = metadata.pop(self._text_key)
docs.append(Document(page_content=text, metadata=metadata))
return docs
@classmethod