pinecone: update pinecone client (#28320)

This PR updates the Pinecone client to `5.4.0`, as well as its
dependencies (`pinecone-plugin-inference` and
`pinecone-plugin-interface`).

Note: `pinecone-client` is now simply called `pinecone`.

**Question for reviewer(s):** should this PR also update the `pinecone`
dep in [the root dir's `poetry.lock`
file](https://github.com/langchain-ai/langchain/blob/master/poetry.lock#L6729)?
Was unsure. (I don't believe so b/c it seems pinned to a lower version
likely based on 3rd-party deps (e.g. Unstructured).)

--
TW: @audrey_sage_


---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1208693659122374
This commit is contained in:
Audrey Sage Lorberfeld
2024-12-02 22:47:09 -08:00
committed by GitHub
parent 000be1f32c
commit 6b7e93d4c7
7 changed files with 1045 additions and 845 deletions

View File

@@ -33,7 +33,7 @@ class PineconeEmbeddings(BaseModel, Embeddings):
# Clients
_client: PineconeClient = PrivateAttr(default=None)
_async_client: aiohttp.ClientSession = PrivateAttr(default=None)
_async_client: Optional[aiohttp.ClientSession] = PrivateAttr(default=None)
model: str
"""Model to use for example 'multilingual-e5-large'."""
# Config
@@ -65,6 +65,19 @@ class PineconeEmbeddings(BaseModel, Embeddings):
protected_namespaces=(),
)
@property
def async_client(self) -> aiohttp.ClientSession:
"""Lazily initialize the async client."""
if self._async_client is None:
self._async_client = aiohttp.ClientSession(
headers={
"Api-Key": self.pinecone_api_key.get_secret_value(),
"Content-Type": "application/json",
"X-Pinecone-API-Version": "2024-07",
}
)
return self._async_client
@model_validator(mode="before")
@classmethod
def set_default_config(cls, values: dict) -> Any:
@@ -92,15 +105,8 @@ class PineconeEmbeddings(BaseModel, Embeddings):
client = PineconeClient(api_key=api_key_str, source_tag="langchain")
self._client = client
# initialize async client
if not self._async_client:
self._async_client = aiohttp.ClientSession(
headers={
"Api-Key": api_key_str,
"Content-Type": "application/json",
"X-Pinecone-API-Version": "2024-07",
}
)
# Ensure async_client is lazily initialized
_ = self.async_client
return self
def _get_batch_iterator(self, texts: List[str]) -> Iterable:
@@ -174,7 +180,7 @@ class PineconeEmbeddings(BaseModel, Embeddings):
"inputs": [{"text": text} for text in texts],
"parameters": parameters,
}
async with self._async_client.post(
async with self.async_client.post(
"https://api.pinecone.io/embed", json=data
) as response:
response_data = await response.json(content_type=None)