Skip to content

Commit 84068f4

Browse files
authored
Update to pinecone-plugin-inference=2.0.0 (#397)
## Problem Updates `pinecone-plugin-inference` to new major version `2.0.0`. From the 2.0.0 release notes: ### Reusing top-level exceptions from `pinecone` client Exceptions in the Pinecone Inference SDK have been reworked to throw the top-level exceptions declared in the Pinecone Python SDK as opposed to plugin-specific duplications of those exceptions, which was confusing to users. #### Old Previously, exceptions in the Python Inference SDK were redeclared/duplicated in an obscure package, leading to a poor user experience when working with what should otherwise be standard Pinecone exceptions. For example, a user who wanted to catch and handle `PineconeApiException` would have to know to enter: ```python from pinecone_plugins.inference.core.client.exceptions import PineconeApiException ``` #### New Now, the Inference SDK reuses exceptions from the top-level Pinecone SDK, allowing the user to simply enter: ```python from pinecone.exceptions import PineconeApiException ``` ## Solution Describe the approach you took. Link to any relevant bugs, issues, docs, or other resources. ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan Describe specific steps for validating this change.
1 parent 089c3e3 commit 84068f4

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

poetry.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ lz4 = { version = ">=3.1.3", optional = true }
5252
protobuf = { version = "^5.28", optional = true }
5353
protoc-gen-openapiv2 = {version = "^0.0.1", optional = true }
5454
pinecone-plugin-interface = "^0.0.7"
55-
pinecone-plugin-inference = "^1.1.0"
55+
pinecone-plugin-inference = "^2.0.0"
5656
python-dateutil = ">=2.5.3"
5757

5858
[tool.poetry.group.types]

tests/integration/inference/test_embed.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import pytest
12
from pinecone import Pinecone
23
from pinecone.grpc import PineconeGRPC
4+
from pinecone.exceptions import PineconeApiException
35

46

57
class TestInferencePlugin:
@@ -32,3 +34,15 @@ def test_embed_grpc(self, api_key):
3234
assert len(embeddings.get("data")[0]["values"]) == 1024
3335
assert len(embeddings.get("data")[1]["values"]) == 1024
3436
assert embeddings.get("model") == embedding_model
37+
38+
def test_embed_exception(self, api_key):
39+
pc = Pinecone(api_key=api_key)
40+
41+
with pytest.raises(PineconeApiException) as e_info:
42+
embedding_model = "DOES NOT EXIST"
43+
pc.inference.embed(
44+
model=embedding_model,
45+
inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"],
46+
parameters={"input_type": "query", "truncate": "END"},
47+
)
48+
assert e_info.value.status == 404

tests/integration/inference/test_rerank.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import pytest
12
from pinecone import Pinecone
23
from pinecone.grpc import PineconeGRPC
4+
from pinecone.exceptions import PineconeApiException
35

46

57
class TestInferencePluginRerank:
@@ -10,7 +12,11 @@ def test_rerank(self, api_key):
1012
result = pc.inference.rerank(
1113
model=model,
1214
query="i love dogs",
13-
documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"],
15+
documents=[
16+
"dogs are pretty cool",
17+
"everyone loves dogs",
18+
"I'm a cat person",
19+
],
1420
top_n=1,
1521
return_documents=True,
1622
)
@@ -28,7 +34,11 @@ def test_rerank_grpc(self, api_key):
2834
result = pc.inference.rerank(
2935
model=model,
3036
query="i love dogs",
31-
documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"],
37+
documents=[
38+
"dogs are pretty cool",
39+
"everyone loves dogs",
40+
"I'm a cat person",
41+
],
3242
top_n=1,
3343
return_documents=True,
3444
)
@@ -38,3 +48,20 @@ def test_rerank_grpc(self, api_key):
3848
assert result.model == model
3949
assert isinstance(result.usage.rerank_units, int)
4050
assert result.usage.rerank_units == 1
51+
52+
def test_rerank_exception(self, api_key):
53+
pc = Pinecone(api_key=api_key)
54+
with pytest.raises(PineconeApiException) as e_info:
55+
pc.inference.rerank(
56+
model="DOES NOT EXIST",
57+
query="i love dogs",
58+
documents=[
59+
"dogs are pretty cool",
60+
"everyone loves dogs",
61+
"I'm a cat person",
62+
],
63+
rank_fields=["custom-field"],
64+
top_n=1,
65+
return_documents=True,
66+
)
67+
assert e_info.value.status == 404

0 commit comments

Comments
 (0)