From 84068f427fd3ce8a2919656041487fdde04b42fa Mon Sep 17 00:00:00 2001 From: Silas Smith <163026730+ssmith-pc@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:44:14 -0700 Subject: [PATCH] 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. --- poetry.lock | 10 +++---- pyproject.toml | 2 +- tests/integration/inference/test_embed.py | 14 ++++++++++ tests/integration/inference/test_rerank.py | 31 ++++++++++++++++++++-- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/poetry.lock b/poetry.lock index 6f118e8e..758f00d4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "astunparse" @@ -799,13 +799,13 @@ dev = ["hypothesis", "mypy", "pdoc-pyo3-sample-library (==1.0.11)", "pygments (> [[package]] name = "pinecone-plugin-inference" -version = "1.1.0" +version = "2.0.0" description = "Embeddings plugin for Pinecone SDK" optional = false python-versions = "<4.0,>=3.8" files = [ - {file = "pinecone_plugin_inference-1.1.0-py3-none-any.whl", hash = "sha256:32c61aba21c9a28fdcd0e782204c1ca641aeb3fd6e42764fbf0de8186eb657ec"}, - {file = "pinecone_plugin_inference-1.1.0.tar.gz", hash = "sha256:283e5ae4590b901bf2179beb56fc3d1b715e63582f37ec7abb0708cf70912d1f"}, + {file = "pinecone_plugin_inference-2.0.0-py3-none-any.whl", hash = "sha256:260368b5584b12196d9031322c115c2329fb6c948a43952e3534061382f0d522"}, + {file = "pinecone_plugin_inference-2.0.0.tar.gz", hash = "sha256:b29709cd5d82829f8d0361a3f5b51dab622da59533578097be04e73eeecf3ee5"}, ] [package.dependencies] @@ -1312,4 +1312,4 @@ grpc = ["googleapis-common-protos", "grpcio", "grpcio", "lz4", "protobuf", "prot [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "1efcde79e04a6f46b76f3023829bac62698d4afd00469228347c1820dcacf49b" +content-hash = "a82474ddea48c5918581d11b25eb9398e8b6241770245a79101d1a8be9803cd5" diff --git a/pyproject.toml b/pyproject.toml index 5b95c0d7..7b571682 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/tests/integration/inference/test_embed.py b/tests/integration/inference/test_embed.py index 18e30c0c..0e52ec2c 100644 --- a/tests/integration/inference/test_embed.py +++ b/tests/integration/inference/test_embed.py @@ -1,5 +1,7 @@ +import pytest from pinecone import Pinecone from pinecone.grpc import PineconeGRPC +from pinecone.exceptions import PineconeApiException class TestInferencePlugin: @@ -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 diff --git a/tests/integration/inference/test_rerank.py b/tests/integration/inference/test_rerank.py index 84eb40ac..55837b6c 100644 --- a/tests/integration/inference/test_rerank.py +++ b/tests/integration/inference/test_rerank.py @@ -1,5 +1,7 @@ +import pytest from pinecone import Pinecone from pinecone.grpc import PineconeGRPC +from pinecone.exceptions import PineconeApiException class TestInferencePluginRerank: @@ -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, ) @@ -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, ) @@ -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