From 84cd825a0e77687b0eb76a26d2cf4c5928aa3726 Mon Sep 17 00:00:00 2001 From: Abhinav Upadhyay Date: Tue, 14 Mar 2023 22:10:22 +0530 Subject: [PATCH] Add a batch_size param to the add_texts API of pinecone wrapper (#1658) A safe default value of batch_size is required by the pinecone python client otherwise if the user of add_texts passes too many documents in a single call, they would get a 400 error from pinecone. --- langchain/vectorstores/pinecone.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/langchain/vectorstores/pinecone.py b/langchain/vectorstores/pinecone.py index 1f0d09a3..6dfef7b7 100644 --- a/langchain/vectorstores/pinecone.py +++ b/langchain/vectorstores/pinecone.py @@ -56,6 +56,7 @@ class Pinecone(VectorStore): metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, namespace: Optional[str] = None, + batch_size: int = 32, **kwargs: Any, ) -> List[str]: """Run more texts through the embeddings and add to the vectorstore. @@ -79,7 +80,7 @@ class Pinecone(VectorStore): metadata[self._text_key] = text docs.append((ids[i], embedding, metadata)) # upsert to Pinecone - self._index.upsert(vectors=docs, namespace=namespace) + self._index.upsert(vectors=docs, namespace=namespace, batch_size=batch_size) return ids def similarity_search_with_score(