Skip to content

Commit

Permalink
Upgrade to Inference 1.1.0 (w/ Rerank API) (#389)
Browse files Browse the repository at this point in the history
## Problem

Adopts version `1.1.0` of
[python-plugin-inference](https://pypi.org/project/pinecone-plugin-inference/1.1.0/),
which contains support for Rerank API.

## 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)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [x] 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 Sep 13, 2024
1 parent 9fb0a24 commit 1d6c50a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 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 @@ -68,7 +68,7 @@ lz4 = { version = ">=3.1.3", optional = true }
protobuf = { version = "^4.25", optional = true }
protoc-gen-openapiv2 = {version = "^0.0.1", optional = true }
pinecone-plugin-interface = "^0.0.7"
pinecone-plugin-inference = "^1.0.3"
pinecone-plugin-inference = "^1.1.0"

[tool.poetry.group.types]
optional = true
Expand Down
40 changes: 40 additions & 0 deletions tests/integration/inference/test_rerank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from pinecone import Pinecone
from pinecone.grpc import PineconeGRPC


class TestInferencePluginRerank:
def test_rerank(self, api_key):
pc = Pinecone(api_key=api_key)

model = "bge-reranker-v2-m3"
result = pc.inference.rerank(
model=model,
query="i love dogs",
documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"],
top_n=1,
return_documents=True,
)
assert len(result.data) == 1
assert result.data[0].index == 1
assert result.data[0].document.text == "everyone loves dogs"
assert result.model == model
assert isinstance(result.usage.rerank_units, int)
assert result.usage.rerank_units == 1

def test_rerank_grpc(self, api_key):
pc = PineconeGRPC(api_key=api_key)

model = "bge-reranker-v2-m3"
result = pc.inference.rerank(
model=model,
query="i love dogs",
documents=["dogs are pretty cool", "everyone loves dogs", "I'm a cat person"],
top_n=1,
return_documents=True,
)
assert len(result.data) == 1
assert result.data[0].index == 1
assert result.data[0].document.text == "everyone loves dogs"
assert result.model == model
assert isinstance(result.usage.rerank_units, int)
assert result.usage.rerank_units == 1

0 comments on commit 1d6c50a

Please sign in to comment.