Skip to content

Commit

Permalink
Update Pinecone Upsert method usage (langchain-ai#7358)
Browse files Browse the repository at this point in the history
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](pinecone-io/pinecone-python-client#184)

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - Memory: @hwchase17

---------

Co-authored-by: kwesi <[email protected]>
Co-authored-by: Bagatur <[email protected]>
Co-authored-by: Lance Martin <[email protected]>
  • Loading branch information
4 people authored Jul 12, 2023
1 parent 5c3fe8b commit 74c28df
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions langchain/vectorstores/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def add_texts(
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(
Expand Down Expand Up @@ -274,6 +276,7 @@ def from_texts(
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.
Expand Down Expand Up @@ -346,8 +349,9 @@ def from_texts(
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(
Expand Down

0 comments on commit 74c28df

Please sign in to comment.