Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ jobs:
strategy:
matrix:
python-version: [3.8, 3.11]
pineconeEnv: ['prod', 'staging']
pineconeEnv:
- prod
# - staging
max-parallel: 1
fail-fast: false
steps:
Expand All @@ -58,8 +60,6 @@ jobs:
env:
PINECONE_CONTROLLER_HOST: 'https://api.pinecone.io'
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
TEST_CAPACITY_MODE_1: ${{ secrets.TEST_CAPACITY_MODE_1 }}
TEST_CAPACITY_MODE_2: ${{ secrets.TEST_CAPACITY_MODE_2 }}
GITHUB_BUILD_NUMBER: "${{ github.run_number }}-p-${{ matrix.python-version}}"

- name: Run integration tests (REST, staging)
Expand All @@ -68,8 +68,6 @@ jobs:
env:
PINECONE_CONTROLLER_HOST: 'https://api-staging.pinecone.io'
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY_STAGING }}
TEST_CAPACITY_MODE_1: ${{ secrets.TEST_CAPACITY_MODE_1 }}
TEST_CAPACITY_MODE_2: ${{ secrets.TEST_CAPACITY_MODE_2 }}
GITHUB_BUILD_NUMBER: "${{ github.run_number }}-s-${{ matrix.python-version}}"

units-grpc:
Expand Down
4 changes: 3 additions & 1 deletion pinecone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
from .control.pinecone import Pinecone
from .data.index import *
from .models import *
# from .core.client.models import *
from .core.client.models import (
IndexModel,
)
2 changes: 2 additions & 0 deletions pinecone/control/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def create_index(
api_instance.create_index(create_index_request=CreateIndexRequest(name=name, dimension=dimension, metric=metric, spec=spec.asdict()))
elif isinstance(spec, PodSpec):
api_instance.create_index(create_index_request=CreateIndexRequest(name=name, dimension=dimension, metric=metric, spec=spec.asdict()))
else:
raise TypeError("spec must be of type dict, ServerlessSpec, or PodSpec")

def is_ready():
status = self._get_status(name)
Expand Down
14 changes: 0 additions & 14 deletions pinecone/core/client/model/configure_index_request_spec_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,6 @@ class ConfigureIndexRequestSpecPod(ModelNormal):
"""

allowed_values = {
('pod_type',): {
'S1.X1': "s1.x1",
'S1.X2': "s1.x2",
'S1.X4': "s1.x4",
'S1.X8': "s1.x8",
'P1.X1': "p1.x1",
'P1.X2': "p1.x2",
'P1.X4': "p1.x4",
'P1.X8': "p1.x8",
'P2.X1': "p2.x1",
'P2.X2': "p2.x2",
'P2.X4': "p2.x4",
'P2.X8': "p2.x8",
},
}

validations = {
Expand Down
18 changes: 2 additions & 16 deletions pinecone/core/client/model/pod_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,6 @@ class PodSpec(ModelNormal):
"""

allowed_values = {
('pod_type',): {
'S1.X1': "s1.x1",
'S1.X2': "s1.x2",
'S1.X4': "s1.x4",
'S1.X8': "s1.x8",
'P1.X1': "p1.x1",
'P1.X2': "p1.x2",
'P1.X4': "p1.x4",
'P1.X8': "p1.x8",
'P2.X1': "p2.x1",
'P2.X2': "p2.x2",
'P2.X4': "p2.x4",
'P2.X8': "p2.x8",
},
}

validations = {
Expand Down Expand Up @@ -150,7 +136,7 @@ def _from_openapi_data(cls, environment, *args, **kwargs): # noqa: E501
Keyword Args:
replicas (int): The number of replicas. Replicas duplicate your index. They provide higher availability and throughput. Replicas can be scaled up or down as your needs change.. defaults to 1 # noqa: E501
shards (int): The number of shards. Shards split your data across multiple pods so you can fit more data into an index.. defaults to 1 # noqa: E501
pod_type (str): The type of pod to use. One of `s1`, `p1`, or `p2` appended with `.` and one of `x1`, `x2`, `x4`, or `x8`.. defaults to "p1.x1", must be one of ["s1.x1", "s1.x2", "s1.x4", "s1.x8", "p1.x1", "p1.x2", "p1.x4", "p1.x8", "p2.x1", "p2.x2", "p2.x4", "p2.x8", ] # noqa: E501
pod_type (str): The type of pod to use. One of `s1`, `p1`, or `p2` appended with `.` and one of `x1`, `x2`, `x4`, or `x8`.. defaults to "p1.x1" # noqa: E501
pods (int): The number of pods to be used in the index. This should be equal to `shards` x `replicas`.. defaults to 1 # noqa: E501
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
Expand Down Expand Up @@ -249,7 +235,7 @@ def __init__(self, environment, *args, **kwargs): # noqa: E501
Keyword Args:
replicas (int): The number of replicas. Replicas duplicate your index. They provide higher availability and throughput. Replicas can be scaled up or down as your needs change.. defaults to 1 # noqa: E501
shards (int): The number of shards. Shards split your data across multiple pods so you can fit more data into an index.. defaults to 1 # noqa: E501
pod_type (str): The type of pod to use. One of `s1`, `p1`, or `p2` appended with `.` and one of `x1`, `x2`, `x4`, or `x8`.. defaults to "p1.x1", must be one of ["s1.x1", "s1.x2", "s1.x4", "s1.x8", "p1.x1", "p1.x2", "p1.x4", "p1.x8", "p2.x1", "p2.x2", "p2.x4", "p2.x8", ] # noqa: E501
pod_type (str): The type of pod to use. One of `s1`, `p1`, or `p2` appended with `.` and one of `x1`, `x2`, `x4`, or `x8`.. defaults to "p1.x1" # noqa: E501
pods (int): The number of pods to be used in the index. This should be equal to `shards` x `replicas`.. defaults to 1 # noqa: E501
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
Expand Down
2 changes: 1 addition & 1 deletion pinecone/core/client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, resp):

def getheaders(self):
"""Returns a dictionary of the response headers."""
return self.urllib3_response.getheaders()
return self.urllib3_response.headers

def getheader(self, name, default=None):
"""Returns a given response header."""
Expand Down
50 changes: 36 additions & 14 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
from pinecone import Pinecone
import random
import time
from pinecone import Pinecone, NotFoundException, ApiException
from .helpers.helpers import generate_index_name, get_environment_var

@pytest.fixture()
Expand All @@ -13,11 +15,11 @@ def environment():

@pytest.fixture()
def create_sl_index_params(index_name):
spec = {
spec = {"serverless": {
'cloud': 'aws',
'region': 'us-east1'
}
return dict(name=index_name, dimension=10, metric='cosine', spec=spec, timeout=-1)
'region': 'us-west-2'
}}
return dict(name=index_name, dimension=10, metric='cosine', spec=spec)

@pytest.fixture()
def create_pod_index_params(index_name, environment):
Expand All @@ -26,43 +28,63 @@ def create_pod_index_params(index_name, environment):
}
return dict(name=index_name, dimension=10, metric='cosine', spec=spec, timeout=-1)

@pytest.fixture()
def random_vector():
return [random.uniform(0, 1) for _ in range(10)]

@pytest.fixture()
def index_name(request):
test_name = request.node.name
return generate_index_name(test_name)

@pytest.fixture()
def ready_sl_index(client, index_name, create_sl_index_params):
del create_sl_index_params['timeout']
create_sl_index_params['timeout'] = None
client.create_index(**create_sl_index_params)
yield index_name
client.delete_index(index_name, -1)

@pytest.fixture()
def notready_sl_index(client, index_name, create_sl_index_params):
client.create_index(**create_sl_index_params)
client.create_index(**create_sl_index_params, timeout=-1)
yield index_name
client.delete_index(index_name, -1)

@pytest.fixture()
def ready_pod_index(client, index_name, create_pod_index_params):
del create_pod_index_params['timeout']
client.create_index(**create_pod_index_params)
yield index_name
client.delete_index(index_name, -1)

@pytest.fixture()
def notready_pod_index(client, index_name, create_pod_index_params):
client.create_index(**create_pod_index_params)
yield index_name
client.delete_index(index_name, -1)

def delete_with_retry(client, index_name, retries=0, sleep_interval=5):
print('Deleting index ' + index_name + ', retry ' + str(retries) + ', next sleep interval ' + str(sleep_interval))
try:
client.delete_index(index_name, -1)
except NotFoundException:
pass
except ApiException as e:
if e.error.code == 'PRECONDITON_FAILED':
if retries > 5:
raise 'Unable to delete index ' + index_name
time.sleep(sleep_interval)
delete_with_retry(client, index_name, retries + 1, sleep_interval * 2)
else:
print(e.__class__)
print(e)
raise 'Unable to delete index ' + index_name
except Exception as e:
print(e.__class__)
print(e)
raise 'Unable to delete index ' + index_name

@pytest.fixture(autouse=True)
def cleanup(client, index_name):
yield

client.delete_index(index_name, -1)

try:
client.delete_index(index_name, -1)
except:
Expand All @@ -73,8 +95,8 @@ def cleanup_all():
yield

client = Pinecone()
for index in client.list_indexes().databases:
for index in client.list_indexes():
try:
client.delete_index(index.name, -1)
delete_with_retry(client, index.name)
except:
pass
40 changes: 20 additions & 20 deletions tests/integration/test_create_index_api_errors.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import pytest
from pinecone import ApiException
from pinecone import ApiException, ApiValueError

class TestCreateIndexApiErrorCases:
def test_create_index_with_invalid_name(self, client, create_index_params):
create_index_params['name'] = '-invalid-name'
def test_create_index_with_invalid_name(self, client, create_sl_index_params):
create_sl_index_params['name'] = '-invalid-name'
with pytest.raises(ApiException):
client.create_index(**create_index_params)
client.create_index(**create_sl_index_params)

def test_create_index_invalid_metric(self, client, create_index_params):
create_index_params['metric'] = 'invalid'
with pytest.raises(ApiException):
client.create_index(**create_index_params)
def test_create_index_invalid_metric(self, client, create_sl_index_params):
create_sl_index_params['metric'] = 'invalid'
with pytest.raises(ApiValueError):
client.create_index(**create_sl_index_params)

def test_create_index_with_invalid_neg_dimension(self, client, create_index_params):
create_index_params['dimension'] = -1
with pytest.raises(ApiException):
client.create_index(**create_index_params)
def test_create_index_with_invalid_neg_dimension(self, client, create_sl_index_params):
create_sl_index_params['dimension'] = -1
with pytest.raises(ApiValueError):
client.create_index(**create_sl_index_params)

def test_create_index_that_already_exists(self, client, create_index_params):
client.create_index(**create_index_params)
def test_create_index_that_already_exists(self, client, create_sl_index_params):
client.create_index(**create_sl_index_params)
with pytest.raises(ApiException):
client.create_index(**create_index_params)
client.create_index(**create_sl_index_params)

@pytest.mark.skip(reason='Bug filed https://app.asana.com/0/1205078872348810/1205917627868143')
def test_create_index_w_incompatible_options(self, client, create_index_params):
create_index_params['pod_type'] = 'p1.x2'
create_index_params['environment'] = 'us-east1-gcp'
create_index_params['replicas'] = 2
def test_create_index_w_incompatible_options(self, client, create_sl_index_params):
create_sl_index_params['pod_type'] = 'p1.x2'
create_sl_index_params['environment'] = 'us-east1-gcp'
create_sl_index_params['replicas'] = 2
with pytest.raises(ApiException):
client.create_index(**create_index_params)
client.create_index(**create_sl_index_params)
2 changes: 1 addition & 1 deletion tests/integration/test_create_index_timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class TestCreateIndexWithTimeout:
def test_create_index_default_timeout(self, client, create_sl_index_params):
del create_sl_index_params['timeout']
create_sl_index_params['timeout'] = None
client.create_index(**create_sl_index_params)
# Waits infinitely for index to be ready
desc = client.describe_index(create_sl_index_params['name'])
Expand Down
29 changes: 18 additions & 11 deletions tests/integration/test_describe_index.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import pytest
from pinecone import IndexDescription
from pinecone import IndexModel

class TestDescribeIndex:
def test_describe_index_when_ready(self, client, ready_sl_index, create_sl_index_params):
description = client.describe_index(ready_sl_index)
assert type(description) == IndexDescription

assert type(description) == IndexModel
assert description.name == ready_sl_index
assert description.dimension == create_sl_index_params['dimension']
assert description.metric == create_sl_index_params['metric']
assert description.capacity_mode == create_sl_index_params['capacity_mode']
assert description.spec.serverless['cloud'] == create_sl_index_params['spec']['serverless']['cloud']
assert description.spec.serverless['region'] == create_sl_index_params['spec']['serverless']['region']

assert type(description.host) == str
assert description.host != ""
assert ready_sl_index in description.host

assert type(description.status.host) == str
assert description.status.host != ""
assert description.status.state == 'Ready'
assert ready_sl_index in description.status.host
assert description.status.ready == True

def test_describe_index_when_not_ready(self, client, notready_sl_index, create_sl_index_params):
description = client.describe_index(notready_sl_index)

assert type(description) == IndexDescription
assert type(description) == IndexModel
assert description.name == notready_sl_index
assert description.dimension == create_sl_index_params['dimension']
assert description.metric == create_sl_index_params['metric']
assert description.spec.serverless['cloud'] == create_sl_index_params['spec']['serverless']['cloud']
assert description.spec.serverless['region'] == create_sl_index_params['spec']['serverless']['region']

assert type(description.host) == str
assert description.host != ""
assert notready_sl_index in description.host

assert type(description.status.host) == str
assert description.status.host != ""
assert notready_sl_index in description.status.host
assert description.status.ready == False
assert description.status.ready == False
assert description.status.state in ['Ready', 'Initializing']
21 changes: 10 additions & 11 deletions tests/integration/test_list_indexes.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
from pinecone import IndexModel

class TestListIndexes():
def test_list_indexes_includes_ready_indexes(self, client, ready_index, create_index_params):
def test_list_indexes_includes_ready_indexes(self, client, ready_sl_index, create_sl_index_params):
list_response = client.list_indexes()
assert len(list_response.indexes) != 0
assert type(list_response.indexes[0]) == IndexModel

created_index = [index for index in list_response.indexes if index.name == ready_index][0]
assert created_index.name == ready_index
assert created_index.dimension == create_index_params['dimension']
assert created_index.metric == create_index_params['metric']
assert ready_index in created_index.host
assert created_index.capacity_mode == create_index_params['capacity_mode']
created_index = [index for index in list_response.indexes if index.name == ready_sl_index][0]
assert created_index.name == ready_sl_index
assert created_index.dimension == create_sl_index_params['dimension']
assert created_index.metric == create_sl_index_params['metric']
assert ready_sl_index in created_index.host

def test_list_indexes_includes_not_ready_indexes(self, client, notready_index):
def test_list_indexes_includes_not_ready_indexes(self, client, notready_sl_index):
list_response = client.list_indexes()
assert len(list_response.indexes) != 0
assert type(list_response.indexes[0]) == IndexModel

created_index = [index for index in list_response.indexes if index.name == notready_index][0]
assert created_index.name == notready_index
assert notready_index in created_index.name
created_index = [index for index in list_response.indexes if index.name == notready_sl_index][0]
assert created_index.name == notready_sl_index
assert notready_sl_index in created_index.name
Loading