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,6 +81,7 @@ 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"]
|
||||||
|
if self._text_key in metadata:
|
||||||
text = metadata.pop(self._text_key)
|
text = metadata.pop(self._text_key)
|
||||||
docs.append(Document(page_content=text, metadata=metadata))
|
docs.append(Document(page_content=text, metadata=metadata))
|
||||||
return docs
|
return docs
|
||||||
|
Loading…
Reference in New Issue
Block a user