Skip to content

Commit ddfa538

Browse files
authored
Add inference plugin and tests (#370)
## Problem We want to ship inference as part of the core SDK ## Solution Add a dependency on v1.0.2 of the inference plugin, which includes a recent fix to plugin installation for use with the GRPC client. ## Usage The plugin should automatically be installed and available for usage. ```python from pinecone import Pinecone pc = Pinecone(api_key='key') embedding_model = "multilingual-e5-large" embeddings = pc.inference.embed( model=embedding_model, inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"], parameters={"input_type": "query", "truncate": "END"}, ) ``` ## Type of Change - [x] New feature (non-breaking change which adds functionality) ## Test Plan See tests passing.
1 parent 8e55a96 commit ddfa538

File tree

6 files changed

+79
-48
lines changed

6 files changed

+79
-48
lines changed

.github/workflows/testing-integration.yaml

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,27 @@ name: "Integration Tests"
33
workflow_call: {}
44

55
jobs:
6-
# setup-index:
7-
# name: Setup proxyconfig test index
8-
# runs-on: ubuntu-latest
9-
# outputs:
10-
# index_name: ${{ steps.create-index.outputs.index_name }}
11-
# steps:
12-
# - uses: actions/checkout@v4
13-
# - name: Create index
14-
# id: create-index
15-
# uses: ./.github/actions/create-index
16-
# with:
17-
# PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
18-
# NAME_PREFIX: 'proxyconfig-'
19-
# REGION: 'us-west-2'
20-
# CLOUD: 'aws'
21-
# DIMENSION: 1536
22-
# METRIC: 'cosine'
23-
24-
# proxy-config:
25-
# name: Proxy config tests
26-
# needs: [setup-index]
27-
# runs-on: ubuntu-latest
28-
# steps:
29-
# - uses: actions/checkout@v4
30-
# - uses: actions/setup-python@v5
31-
# with:
32-
# python-version: 3.9
33-
# - name: Setup Poetry
34-
# uses: ./.github/actions/setup-poetry
35-
# - name: 'Run integration tests (proxy config)'
36-
# run: |
37-
# poetry run pytest tests/integration/proxy_config -s -v
38-
# env:
39-
# PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY }}'
40-
# PINECONE_INDEX_NAME: ${{ needs.setup-index.outputs.index_name }}
41-
# - name: Upload logs
42-
# if: always()
43-
# uses: actions/upload-artifact@v4
44-
# with:
45-
# name: proxy_config_test_logs
46-
# path: tests/integration/proxy_config/logs
47-
# - name: Cleanup index
48-
# if: always()
49-
# uses: ./.github/actions/delete-index
50-
# with:
51-
# PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
52-
# INDEX_NAME: ${{ needs.setup-index.outputs.index_name }}
6+
plugin-inference:
7+
name: Test inference plugin
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python_version: [3.8, 3.12]
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: 'Set up Python ${{ matrix.python_version }}'
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: '${{ matrix.python_version }}'
18+
- name: Setup Poetry
19+
uses: ./.github/actions/setup-poetry
20+
with:
21+
include_grpc: 'true'
22+
- name: 'Run integration tests'
23+
run: poetry run pytest tests/integration/inference -s -vv
24+
env:
25+
PINECONE_DEBUG_CURL: 'true'
26+
PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY }}'
5327

5428
data-plane-serverless:
5529
name: Data plane serverless integration tests

poetry.lock

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

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ lz4 = { version = ">=3.1.3", optional = true }
6868
protobuf = { version = "^4.25", optional = true }
6969
protoc-gen-openapiv2 = {version = "^0.0.1", optional = true }
7070
pinecone-plugin-interface = "^0.0.7"
71+
pinecone-plugin-inference = "1.0.2"
7172

7273
[tool.poetry.group.types]
7374
optional = true

tests/integration/inference/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
from ..helpers import get_environment_var
3+
4+
5+
@pytest.fixture()
6+
def api_key():
7+
return get_environment_var("PINECONE_API_KEY")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from pinecone import Pinecone
2+
from pinecone.grpc import PineconeGRPC
3+
4+
5+
class TestInferencePlugin:
6+
def test_embed(self, api_key):
7+
pc = Pinecone(api_key=api_key)
8+
9+
embedding_model = "multilingual-e5-large"
10+
embeddings = pc.inference.embed(
11+
model=embedding_model,
12+
inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"],
13+
parameters={"input_type": "query", "truncate": "END"},
14+
)
15+
16+
assert len(embeddings.get("data")) == 2
17+
assert len(embeddings.get("data")[0]["values"]) == 1024
18+
assert len(embeddings.get("data")[1]["values"]) == 1024
19+
assert embeddings.get("model") == embedding_model
20+
21+
def test_embed_grpc(self, api_key):
22+
pc = PineconeGRPC(api_key=api_key)
23+
24+
embedding_model = "multilingual-e5-large"
25+
embeddings = pc.inference.embed(
26+
model=embedding_model,
27+
inputs=["The quick brown fox jumps over the lazy dog.", "lorem ipsum"],
28+
parameters={"input_type": "query", "truncate": "END"},
29+
)
30+
31+
assert len(embeddings.get("data")) == 2
32+
assert len(embeddings.get("data")[0]["values"]) == 1024
33+
assert len(embeddings.get("data")[1]["values"]) == 1024
34+
assert embeddings.get("model") == embedding_model

0 commit comments

Comments
 (0)