From 74c28df3635668da89f7fa31ae962568bbebf687 Mon Sep 17 00:00:00 2001 From: Pharbie <22204443+Pharbi@users.noreply.github.com> Date: Tue, 11 Jul 2023 21:14:42 -0400 Subject: [PATCH] Update Pinecone Upsert method usage (#7358) Description: Refactor the upsert method in the Pinecone class to allow for additional keyword arguments. This change adds flexibility and extensibility to the method, allowing for future modifications or enhancements. The upsert method now accepts the `**kwargs` parameter, which can be used to pass any additional arguments to the Pinecone index. This change has been made in both the `upsert` method in the `Pinecone` class and the `upsert` method in the `similarity_search_with_score` class method. Falls in line with the usage of the upsert method in [Pinecone-Python-Client](https://github.com/pinecone-io/pinecone-python-client/blob/4640c4cf27b1ab935e76929c46d230dea9fe5506/pinecone/index.py#L73) Issue: [This feature request in Pinecone Repo](https://github.com/pinecone-io/pinecone-python-client/issues/184) Maintainer responsibilities: - General / Misc / if you don't know who to tag: @baskaryan - Memory: @hwchase17 --------- Co-authored-by: kwesi <22204443+yankskwesi@users.noreply.github.com> Co-authored-by: Bagatur Co-authored-by: Lance Martin <122662504+rlancemartin@users.noreply.github.com> --- langchain/vectorstores/pinecone.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/langchain/vectorstores/pinecone.py b/langchain/vectorstores/pinecone.py index a57bf36379..933999049f 100644 --- a/langchain/vectorstores/pinecone.py +++ b/langchain/vectorstores/pinecone.py @@ -94,7 +94,9 @@ class Pinecone(VectorStore): metadata[self._text_key] = text docs.append((ids[i], embedding, metadata)) # upsert to Pinecone - self._index.upsert(vectors=docs, namespace=namespace, batch_size=batch_size) + self._index.upsert( + vectors=docs, namespace=namespace, batch_size=batch_size, **kwargs + ) return ids def similarity_search_with_score( @@ -274,6 +276,7 @@ class Pinecone(VectorStore): text_key: str = "text", index_name: Optional[str] = None, namespace: Optional[str] = None, + upsert_kwargs: Optional[dict] = None, **kwargs: Any, ) -> Pinecone: """Construct Pinecone wrapper from raw documents. @@ -346,8 +349,9 @@ class Pinecone(VectorStore): to_upsert = zip(ids_batch, embeds, metadata) # upsert to Pinecone - index.upsert(vectors=list(to_upsert), namespace=namespace) - return cls(index, embedding.embed_query, text_key, namespace) + _upsert_kwargs = upsert_kwargs or {} + index.upsert(vectors=list(to_upsert), namespace=namespace, **_upsert_kwargs) + return cls(index, embedding.embed_query, text_key, namespace, **kwargs) @classmethod def from_existing_index(