Skip to content

Commit

Permalink
Update to pinecone-plugin-inference=2.0.0 (#397)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
ssmith-pc authored Oct 17, 2024
1 parent 089c3e3 commit 84068f4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ lz4 = { version = ">=3.1.3", optional = true }
protobuf = { version = "^5.28", optional = true }
protoc-gen-openapiv2 = {version = "^0.0.1", optional = true }
pinecone-plugin-interface = "^0.0.7"
pinecone-plugin-inference = "^1.1.0"
pinecone-plugin-inference = "^2.0.0"
python-dateutil = ">=2.5.3"

[tool.poetry.group.types]
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/inference/test_embed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
from pinecone import Pinecone
from pinecone.grpc import PineconeGRPC
from pinecone.exceptions import PineconeApiException


class TestInferencePlugin:
Expand Down Expand Up @@ -32,3 +34,15 @@ def test_embed_grpc(self, api_key):
assert len(embeddings.get("data")[0]["values"]) == 1024
assert len(embeddings.get("data")[1]["values"]) == 1024
assert embeddings.get("model") == embedding_model

def test_embed_exception(self, api_key):
pc = Pinecone(api_key=api_key)

with pytest.raises(PineconeApiException) as e_info:
embedding_model = "DOES NOT EXIST"
pc.inference.embed(
model=embedding_model,
inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"],
parameters={"input_type": "query", "truncate": "END"},
)
assert e_info.value.status == 404
31 changes: 29 additions & 2 deletions tests/integration/inference/test_rerank.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
from pinecone import Pinecone
from pinecone.grpc import PineconeGRPC
from pinecone.exceptions import PineconeApiException


class TestInferencePluginRerank:
Expand All @@ -10,7 +12,11 @@ def test_rerank(self, api_key):
result = pc.inference.rerank(
model=model,
query="i love dogs",
documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"],
documents=[
"dogs are pretty cool",
"everyone loves dogs",
"I'm a cat person",
],
top_n=1,
return_documents=True,
)
Expand All @@ -28,7 +34,11 @@ def test_rerank_grpc(self, api_key):
result = pc.inference.rerank(
model=model,
query="i love dogs",
documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"],
documents=[
"dogs are pretty cool",
"everyone loves dogs",
"I'm a cat person",
],
top_n=1,
return_documents=True,
)
Expand All @@ -38,3 +48,20 @@ def test_rerank_grpc(self, api_key):
assert result.model == model
assert isinstance(result.usage.rerank_units, int)
assert result.usage.rerank_units == 1

def test_rerank_exception(self, api_key):
pc = Pinecone(api_key=api_key)
with pytest.raises(PineconeApiException) as e_info:
pc.inference.rerank(
model="DOES NOT EXIST",
query="i love dogs",
documents=[
"dogs are pretty cool",
"everyone loves dogs",
"I'm a cat person",
],
rank_fields=["custom-field"],
top_n=1,
return_documents=True,
)
assert e_info.value.status == 404

0 comments on commit 84068f4

Please sign in to comment.