Skip to content

Commit

Permalink
WIP on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamon committed Jan 10, 2024
1 parent 1dd381e commit 1fc6d47
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 1 deletion.
57 changes: 57 additions & 0 deletions .github/actions/test-data-plane/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: 'Test Data Plane'
description: 'Runs tests on the Pinecone data plane'

# - pod vs serverless
# - grpc vs rest
# - metric -> vector vs sparse vector
# - namespace: default vs custom
# - environment: free vs paid
# - with metadata vs without metadata

inputs:
metric:
description: 'The metric of the index'
required: true
default: 'cosine'
spec:
description: 'The deploy spec of the index'
required: false
default: ''
use_grpc:
description: 'Whether to use gRPC or REST'
required: false
default: 'true'
freshness_sleep_seconds:
description: 'The number of seconds to wait for the index to become fresh'
required: false
default: '60'

outputs:
index_name:
description: 'The name of the index, including randomized suffix'
value: ${{ steps.create-index.outputs.index_name }}

runs:
using: 'composite'
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Setup Poetry
uses: ./.github/actions/setup-poetry
with:
include_grpc: ${{ inputs.use_grpc }}
include_dev: 'true'

- name: Run data plane tests
id: data-plane-tests
shell: bash
run: poetry run pytest tests/integration/data
env:
PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }}
USE_GRPC: ${{ inputs.use_grpc }}
METRIC: ${{ inputs.metric }}
SPEC: ${{ inputs.spec }}
FRESHNESS_SLEEP_SECONDS: ${{ inputs.freshness_sleep_seconds }}
21 changes: 21 additions & 0 deletions .github/workflows/testing-grpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ jobs:
# so we don't add new regressions.
poetry run mypy pinecone --exclude pinecone/core
integration-grpc-data-plane:
name: Integration tests (GRPC, data plane)
runs-on: ubuntu-latest
strategy:
matrix:
metric:
- cosine
- dotproduct
spec:
# These need to be json strings
- '{ "serverless": { "region": "us-west-2", "cloud": "aws" }}'
- '{ "pod": { "environment": "us-east1-gcp" }}'

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/test-data-plane
with:
include_grpc: true
metric: ${{ matrix.metric }}
spec: ${{ matrix.spec }}

dependency-matrix-grpc-setup:
name: Deps setup (GRPC)
runs-on: ubuntu-latest
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/testing-rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ jobs:
SERVERLESS_CLOUD: ${{ matrix.testConfig.serverless.cloud }}
SERVERLESS_REGION: ${{ matrix.testConfig.serverless.region }}

integration-rest-data-plane:
name: Integration tests (GRPC, data plane)
runs-on: ubuntu-latest
strategy:
matrix:
metric:
- cosine
- dotproduct
spec:
# These need to be json strings
- '{ "serverless": { "region": "us-west-2", "cloud": "aws" }}'
- '{ "pod": { "environment": "us-east1-gcp" }}'
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/test-data-plane
with:
include_grpc: false
metric: ${{ matrix.metric }}
spec: ${{ matrix.spec }}

dependency-matrix-rest-setup:
name: Deps setup (REST)
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random
import time
from pinecone import Pinecone, NotFoundException, PineconeApiException
from .helpers.helpers import generate_index_name, get_environment_var
from ..helpers import generate_index_name, get_environment_var

@pytest.fixture()
def client():
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions tests/integration/data/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pytest
import os
import json
from ..helpers import get_environment_var, random_string

# Test matrix needs to consider the following dimensions:
# - pod vs serverless
# - grpc vs rest
# - metric -> vector vs sparse vector
# - namespace: default vs custom
# - environment: free vs paid
# - with metadata vs without metadata

@pytest.fixture
def api_key():
return get_environment_var('PINECONE_API_KEY')

@pytest.fixture
def client(api_key):
use_grpc = os.environ.get('USE_GRPC', 'false') == 'true'
if use_grpc:
from pinecone.grpc import PineconeGRPC
return PineconeGRPC(api_key=api_key)
else:
from pinecone import Pinecone
return Pinecone(api_key=api_key)

@pytest.fixture
def metric():
return get_environment_var('METRIC', 'cosine')

@pytest.fixture
def spec():
return json.loads(get_environment_var('SPEC'))

@pytest.fixture
def index_name():
return 'dataplane-' + random_string(20)

@pytest.fixture
def namespace():
return random_string(10)

@pytest.fixture
def index_host(client, index_name, metric, spec):
client.create_index(name=index_name, dimension=2, metric=metric, spec=spec)
description = client.describe_index(name=index_name)
return description.host

def sleep_t():
return int(os.environ.get('FRESHNESS_SLEEP_SECONDS', 60))
54 changes: 54 additions & 0 deletions tests/integration/data/cosine/test_upsert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pytest
import time
from pinecone import Vector

def test_upsert_to_default_namespace(client, index_name, sleep_t):
expected_dimension = 2
desc = client.describe_index(index_name)
assert desc.dimension == expected_dimension
assert desc.metric == 'cosine'

idx = client.Index(index_name)

# Upsert with tuples
idx.upsert(vectors=[
('1', [1.0, 2.0]),
('2', [3.0, 4.0]),
('3', [5.0, 6.0])
])

# Upsert with objects
idx.upsert(vectors=[
Vector('4', [7.0, 8.0]),
Vector('5', [9.0, 10.0]),
Vector('6', [11.0, 12.0])
])

# Upsert with dict
idx.upsert(vectors=[
{'id': '7', 'values': [13.0, 14.0]},
{'id': '8', 'values': [15.0, 16.0]},
{'id': '9', 'values': [17.0, 18.0]}
])

time.sleep(sleep_t)

# Check the vector count reflects some data has been upserted
stats = idx.describe_index_stats()
assert stats.vector_count == 9


def test_upsert_to_custom_namespace(client, index_name, namespace):
expected_dimension = 2
assert client.describe_index(index_name).dimension == expected_dimension

idx = client.Index(index_name)

# Upsert with tuples
idx.upsert(vectors=[
('1', [1.0, 2.0]),
('2', [3.0, 4.0]),
('3', [5.0, 6.0])
],
namespace=namespace
)

0 comments on commit 1fc6d47

Please sign in to comment.