1+ import pytest
12from pinecone import Pinecone
23from pinecone .grpc import PineconeGRPC
4+ from pinecone .exceptions import PineconeApiException
35
46
57class 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