forked from Archives/langchain
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:
parent
7a32cde5ff
commit
d39ab27969
@ -81,8 +81,9 @@ class Pinecone(VectorStore):
|
|||||||
results = self._index.query([query_obj], top_k=k, include_metadata=True)
|
results = self._index.query([query_obj], top_k=k, include_metadata=True)
|
||||||
for res in results["matches"]:
|
for res in results["matches"]:
|
||||||
metadata = res["metadata"]
|
metadata = res["metadata"]
|
||||||
text = metadata.pop(self._text_key)
|
if self._text_key in metadata:
|
||||||
docs.append(Document(page_content=text, metadata=metadata))
|
text = metadata.pop(self._text_key)
|
||||||
|
docs.append(Document(page_content=text, metadata=metadata))
|
||||||
return docs
|
return docs
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user