mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-02 13:08:57 +00:00
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:
parent
000be1f32c
commit
6b7e93d4c7
@ -32,7 +32,7 @@ For a more detailed walkthrough of the Pinecone vectorstore, see [this notebook]
|
|||||||
### Pinecone Hybrid Search
|
### Pinecone Hybrid Search
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install pinecone-client pinecone-text
|
pip install pinecone pinecone-text
|
||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%pip install --upgrade --quiet pinecone-client pinecone-text pinecone-notebooks"
|
"%pip install --upgrade --quiet pinecone pinecone-text pinecone-notebooks"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,7 @@ def _import_pinecone() -> Any:
|
|||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Could not import pinecone python package. "
|
"Could not import pinecone python package. "
|
||||||
"Please install it with `pip install pinecone-client`."
|
"Please install it with `pip3 install pinecone`."
|
||||||
) from e
|
) from e
|
||||||
return pinecone
|
return pinecone
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ def _is_pinecone_v3() -> bool:
|
|||||||
class Pinecone(VectorStore):
|
class Pinecone(VectorStore):
|
||||||
"""`Pinecone` vector store.
|
"""`Pinecone` vector store.
|
||||||
|
|
||||||
To use, you should have the ``pinecone-client`` python package installed.
|
To use, you should have the ``pinecone`` python package installed.
|
||||||
|
|
||||||
This version of Pinecone is deprecated. Please use `langchain_pinecone.Pinecone`
|
This version of Pinecone is deprecated. Please use `langchain_pinecone.Pinecone`
|
||||||
instead.
|
instead.
|
||||||
|
@ -33,7 +33,7 @@ class PineconeEmbeddings(BaseModel, Embeddings):
|
|||||||
|
|
||||||
# Clients
|
# Clients
|
||||||
_client: PineconeClient = PrivateAttr(default=None)
|
_client: PineconeClient = PrivateAttr(default=None)
|
||||||
_async_client: aiohttp.ClientSession = PrivateAttr(default=None)
|
_async_client: Optional[aiohttp.ClientSession] = PrivateAttr(default=None)
|
||||||
model: str
|
model: str
|
||||||
"""Model to use for example 'multilingual-e5-large'."""
|
"""Model to use for example 'multilingual-e5-large'."""
|
||||||
# Config
|
# Config
|
||||||
@ -65,6 +65,19 @@ class PineconeEmbeddings(BaseModel, Embeddings):
|
|||||||
protected_namespaces=(),
|
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")
|
@model_validator(mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_default_config(cls, values: dict) -> Any:
|
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")
|
client = PineconeClient(api_key=api_key_str, source_tag="langchain")
|
||||||
self._client = client
|
self._client = client
|
||||||
|
|
||||||
# initialize async client
|
# Ensure async_client is lazily initialized
|
||||||
if not self._async_client:
|
_ = self.async_client
|
||||||
self._async_client = aiohttp.ClientSession(
|
|
||||||
headers={
|
|
||||||
"Api-Key": api_key_str,
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"X-Pinecone-API-Version": "2024-07",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def _get_batch_iterator(self, texts: List[str]) -> Iterable:
|
def _get_batch_iterator(self, texts: List[str]) -> Iterable:
|
||||||
@ -174,7 +180,7 @@ class PineconeEmbeddings(BaseModel, Embeddings):
|
|||||||
"inputs": [{"text": text} for text in texts],
|
"inputs": [{"text": text} for text in texts],
|
||||||
"parameters": parameters,
|
"parameters": parameters,
|
||||||
}
|
}
|
||||||
async with self._async_client.post(
|
async with self.async_client.post(
|
||||||
"https://api.pinecone.io/embed", json=data
|
"https://api.pinecone.io/embed", json=data
|
||||||
) as response:
|
) as response:
|
||||||
response_data = await response.json(content_type=None)
|
response_data = await response.json(content_type=None)
|
||||||
|
@ -74,6 +74,7 @@ class PineconeVectorStore(VectorStore):
|
|||||||
dimension=1536,
|
dimension=1536,
|
||||||
metric="cosine",
|
metric="cosine",
|
||||||
spec=ServerlessSpec(cloud="aws", region="us-east-1"),
|
spec=ServerlessSpec(cloud="aws", region="us-east-1"),
|
||||||
|
deletion_protection="enabled", # Defaults to "disabled"
|
||||||
)
|
)
|
||||||
while not pc.describe_index(index_name).status["ready"]:
|
while not pc.describe_index(index_name).status["ready"]:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
1843
libs/partners/pinecone/poetry.lock
generated
1843
libs/partners/pinecone/poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -21,15 +21,9 @@ disallow_untyped_defs = "True"
|
|||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = ">=3.9,<3.13"
|
python = ">=3.9,<3.13"
|
||||||
langchain-core = "^0.3.15"
|
langchain-core = "^0.3.15"
|
||||||
pinecone-client = "^5.0.0"
|
pinecone = "^5.4.0"
|
||||||
aiohttp = ">=3.9.5,<3.10"
|
aiohttp = ">=3.9.5,<3.10"
|
||||||
[[tool.poetry.dependencies.numpy]]
|
numpy = ">=1.26.0,<2.0.0"
|
||||||
version = "^1"
|
|
||||||
python = "<3.12"
|
|
||||||
|
|
||||||
[[tool.poetry.dependencies.numpy]]
|
|
||||||
version = "^1.26.0"
|
|
||||||
python = ">=3.12"
|
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
select = [ "E", "F", "I", "T201",]
|
select = [ "E", "F", "I", "T201",]
|
||||||
|
Loading…
Reference in New Issue
Block a user