diff --git a/pinecone/db_control/resources/asyncio/collection.py b/pinecone/db_control/resources/asyncio/collection.py index 33c1f3d0..e7d98a66 100644 --- a/pinecone/db_control/resources/asyncio/collection.py +++ b/pinecone/db_control/resources/asyncio/collection.py @@ -1,32 +1,32 @@ import logging -from typing import TYPE_CHECKING - from pinecone.db_control.models import CollectionList from pinecone.db_control.request_factory import PineconeDBControlRequestFactory +from pinecone.utils import require_kwargs logger = logging.getLogger(__name__) """ @private """ -if TYPE_CHECKING: - pass - class CollectionResourceAsyncio: def __init__(self, index_api): self.index_api = index_api - async def create(self, name: str, source: str): + @require_kwargs + async def create(self, *, name: str, source: str): req = PineconeDBControlRequestFactory.create_collection_request(name=name, source=source) await self.index_api.create_collection(create_collection_request=req) + @require_kwargs async def list(self) -> CollectionList: response = await self.index_api.list_collections() return CollectionList(response) - async def delete(self, name: str): + @require_kwargs + async def delete(self, *, name: str): await self.index_api.delete_collection(name) - async def describe(self, name: str): + @require_kwargs + async def describe(self, *, name: str): return await self.index_api.describe_collection(name).to_dict() diff --git a/pinecone/db_control/resources/asyncio/index.py b/pinecone/db_control/resources/asyncio/index.py index 7bb10404..9816f365 100644 --- a/pinecone/db_control/resources/asyncio/index.py +++ b/pinecone/db_control/resources/asyncio/index.py @@ -26,7 +26,7 @@ from pinecone.db_control.types import CreateIndexForModelEmbedTypedDict from pinecone.db_control.request_factory import PineconeDBControlRequestFactory from pinecone.core.openapi.db_control import API_VERSION - +from pinecone.utils import require_kwargs logger = logging.getLogger(__name__) """ @private """ @@ -37,8 +37,10 @@ def __init__(self, index_api, config): self._index_api = index_api self._config = config + @require_kwargs async def create( self, + *, name: str, spec: Union[Dict, ServerlessSpec, PodSpec, ByocSpec], dimension: Optional[int] = None, @@ -63,8 +65,10 @@ async def create( return IndexModel(resp) return await self.__poll_describe_index_until_ready(name, timeout) + @require_kwargs async def create_for_model( self, + *, name: str, cloud: Union[CloudProvider, str], region: Union[AwsRegion, GcpRegion, AzureRegion, str], @@ -87,8 +91,10 @@ async def create_for_model( return IndexModel(resp) return await self.__poll_describe_index_until_ready(name, timeout) + @require_kwargs async def create_from_backup( self, + *, name: str, backup_id: str, deletion_protection: Optional[Union[DeletionProtection, str]] = DeletionProtection.DISABLED, @@ -141,17 +147,18 @@ async def is_ready() -> bool: return description - async def delete(self, name: str, timeout: Optional[int] = None): + @require_kwargs + async def delete(self, *, name: str, timeout: Optional[int] = None): await self._index_api.delete_index(name) if timeout == -1: return if timeout is None: - while await self.has(name): + while await self.has(name=name): await asyncio.sleep(5) else: - while await self.has(name) and timeout >= 0: + while await self.has(name=name) and timeout >= 0: await asyncio.sleep(5) timeout -= 5 if timeout and timeout < 0: @@ -163,23 +170,28 @@ async def delete(self, name: str, timeout: Optional[int] = None): ) ) + @require_kwargs async def list(self) -> IndexList: response = await self._index_api.list_indexes() return IndexList(response) - async def describe(self, name: str) -> IndexModel: + @require_kwargs + async def describe(self, *, name: str) -> IndexModel: description = await self._index_api.describe_index(name) return IndexModel(description) - async def has(self, name: str) -> bool: + @require_kwargs + async def has(self, *, name: str) -> bool: available_indexes = await self.list() if name in available_indexes.names(): return True else: return False + @require_kwargs async def configure( self, + *, name: str, replicas: Optional[int] = None, pod_type: Optional[Union[PodType, str]] = None, diff --git a/pinecone/db_control/resources/sync/collection.py b/pinecone/db_control/resources/sync/collection.py index 1d8d11d8..8ed703c2 100644 --- a/pinecone/db_control/resources/sync/collection.py +++ b/pinecone/db_control/resources/sync/collection.py @@ -2,6 +2,7 @@ from pinecone.db_control.models import CollectionList from pinecone.db_control.request_factory import PineconeDBControlRequestFactory +from pinecone.utils import require_kwargs logger = logging.getLogger(__name__) """ @private """ @@ -12,16 +13,20 @@ def __init__(self, index_api): self.index_api = index_api """ @private """ - def create(self, name: str, source: str) -> None: + @require_kwargs + def create(self, *, name: str, source: str) -> None: req = PineconeDBControlRequestFactory.create_collection_request(name=name, source=source) self.index_api.create_collection(create_collection_request=req) + @require_kwargs def list(self) -> CollectionList: response = self.index_api.list_collections() return CollectionList(response) - def delete(self, name: str) -> None: + @require_kwargs + def delete(self, *, name: str) -> None: self.index_api.delete_collection(name) - def describe(self, name: str): + @require_kwargs + def describe(self, *, name: str): return self.index_api.describe_collection(name).to_dict() diff --git a/pinecone/db_control/resources/sync/index.py b/pinecone/db_control/resources/sync/index.py index 05068383..11fbeeac 100644 --- a/pinecone/db_control/resources/sync/index.py +++ b/pinecone/db_control/resources/sync/index.py @@ -43,8 +43,10 @@ def __init__(self, index_api, config): self._index_host_store = IndexHostStore() """ @private """ + @require_kwargs def create( self, + *, name: str, spec: Union[Dict, ServerlessSpec, PodSpec, ByocSpec], dimension: Optional[int] = None, @@ -69,8 +71,10 @@ def create( return IndexModel(resp) return self.__poll_describe_index_until_ready(name, timeout) + @require_kwargs def create_for_model( self, + *, name: str, cloud: Union[CloudProvider, str], region: Union[AwsRegion, GcpRegion, AzureRegion, str], @@ -166,7 +170,8 @@ def is_ready() -> bool: return description - def delete(self, name: str, timeout: Optional[int] = None): + @require_kwargs + def delete(self, *, name: str, timeout: Optional[int] = None): self._index_api.delete_index(name) self._index_host_store.delete_host(self._config, name) @@ -174,10 +179,10 @@ def delete(self, name: str, timeout: Optional[int] = None): return if timeout is None: - while self.has(name): + while self.has(name=name): time.sleep(5) else: - while self.has(name) and timeout >= 0: + while self.has(name=name) and timeout >= 0: time.sleep(5) timeout -= 5 if timeout and timeout < 0: @@ -189,11 +194,13 @@ def delete(self, name: str, timeout: Optional[int] = None): ) ) + @require_kwargs def list(self) -> IndexList: response = self._index_api.list_indexes() return IndexList(response) - def describe(self, name: str) -> IndexModel: + @require_kwargs + def describe(self, *, name: str) -> IndexModel: api_instance = self._index_api description = api_instance.describe_index(name) host = description.host @@ -201,14 +208,17 @@ def describe(self, name: str) -> IndexModel: return IndexModel(description) - def has(self, name: str) -> bool: + @require_kwargs + def has(self, *, name: str) -> bool: if name in self.list().names(): return True else: return False + @require_kwargs def configure( self, + *, name: str, replicas: Optional[int] = None, pod_type: Optional[Union[PodType, str]] = None, diff --git a/pinecone/legacy_pinecone_interface.py b/pinecone/legacy_pinecone_interface.py index ad315d70..27e893d7 100644 --- a/pinecone/legacy_pinecone_interface.py +++ b/pinecone/legacy_pinecone_interface.py @@ -335,6 +335,7 @@ def create_index_from_backup( @abstractmethod def create_index_for_model( self, + *, name: str, cloud: Union["CloudProvider", str], region: Union["AwsRegion", "GcpRegion", "AzureRegion", str], diff --git a/pinecone/pinecone_asyncio.py b/pinecone/pinecone_asyncio.py index 5133f7bd..606210a4 100644 --- a/pinecone/pinecone_asyncio.py +++ b/pinecone/pinecone_asyncio.py @@ -4,8 +4,7 @@ from pinecone.config import PineconeConfig, ConfigBuilder -from pinecone.utils import normalize_host, require_kwargs -from pinecone.utils import docslinks +from pinecone.utils import normalize_host, require_kwargs, docslinks from .pinecone_interface_asyncio import PineconeAsyncioDBControlInterface from .pinecone import check_realistic_host diff --git a/tests/integration/control/resources/index/test_create.py b/tests/integration/control/resources/index/test_create.py index 4e2578fb..55bf66c2 100644 --- a/tests/integration/control/resources/index/test_create.py +++ b/tests/integration/control/resources/index/test_create.py @@ -65,7 +65,7 @@ def test_create_infinite_wait(self, pc, index_name, index_tags): def test_create_default_index_with_metric(self, pc, create_index_params, metric): create_index_params["metric"] = metric pc.db.index.create(**create_index_params) - desc = pc.db.index.describe(create_index_params["name"]) + desc = pc.db.index.describe(name=create_index_params["name"]) if isinstance(metric, str): assert desc.metric == metric else: @@ -96,7 +96,7 @@ def test_create_with_enum_values( pc.db.index.create(**args) - desc = pc.db.index.describe(index_name) + desc = pc.db.index.describe(name=index_name) assert desc.metric == metric_enum.value assert desc.vector_type == vector_type_enum.value assert desc.dimension == dim @@ -111,7 +111,7 @@ def test_create_dense_index_with_metric(self, pc, create_index_params, metric): create_index_params["metric"] = metric create_index_params["vector_type"] = VectorType.DENSE pc.db.index.create(**create_index_params) - desc = pc.db.index.describe(create_index_params["name"]) + desc = pc.db.index.describe(name=create_index_params["name"]) assert desc.metric == metric assert desc.vector_type == "dense" @@ -233,7 +233,7 @@ def test_create_index_default_timeout(self, pc, create_index_params): create_index_params["timeout"] = None pc.db.index.create(**create_index_params) # Waits infinitely for index to be ready - desc = pc.db.index.describe(create_index_params["name"]) + desc = pc.db.index.describe(name=create_index_params["name"]) assert desc.status.ready == True def test_create_index_when_timeout_set(self, pc, create_index_params): @@ -247,7 +247,7 @@ def test_create_index_when_timeout_set(self, pc, create_index_params): def test_create_index_with_negative_timeout(self, pc, create_index_params): create_index_params["timeout"] = -1 pc.db.index.create(**create_index_params) - desc = pc.db.index.describe(create_index_params["name"]) + desc = pc.db.index.describe(name=create_index_params["name"]) # Returns immediately without waiting for index to be ready assert desc.status.ready in [False, True] diff --git a/tests/integration/control/resources/index/test_describe.py b/tests/integration/control/resources/index/test_describe.py index 276176bf..eacb412e 100644 --- a/tests/integration/control/resources/index/test_describe.py +++ b/tests/integration/control/resources/index/test_describe.py @@ -3,7 +3,7 @@ class TestDescribeIndex: def test_describe_index_when_ready(self, pc, ready_sl_index, create_index_params): - description = pc.db.index.describe(ready_sl_index) + description = pc.db.index.describe(name=ready_sl_index) assert isinstance(description, IndexModel) assert description.name == ready_sl_index @@ -26,7 +26,7 @@ def test_describe_index_when_ready(self, pc, ready_sl_index, create_index_params assert description.status.ready == True def test_describe_index_when_not_ready(self, pc, notready_sl_index, create_index_params): - description = pc.db.index.describe(notready_sl_index) + description = pc.db.index.describe(name=notready_sl_index) assert isinstance(description, IndexModel) assert description.name == notready_sl_index diff --git a/tests/integration/control/resources/index/test_has.py b/tests/integration/control/resources/index/test_has.py index 8f55766f..62aba165 100644 --- a/tests/integration/control/resources/index/test_has.py +++ b/tests/integration/control/resources/index/test_has.py @@ -5,14 +5,14 @@ class TestHasIndex: def test_index_exists_success(self, pc, create_index_params): name = create_index_params["name"] pc.db.index.create(**create_index_params) - has_index = pc.db.index.has(name) + has_index = pc.db.index.has(name=name) assert has_index == True def test_index_does_not_exist(self, pc): name = random_string(8) - has_index = pc.db.index.has(name) + has_index = pc.db.index.has(name=name) assert has_index == False def test_has_index_with_null_index_name(self, pc): - has_index = pc.db.index.has("") + has_index = pc.db.index.has(name="") assert has_index == False diff --git a/tests/integration/control/serverless/test_describe_index.py b/tests/integration/control/serverless/test_describe_index.py index 18d22372..87f0876c 100644 --- a/tests/integration/control/serverless/test_describe_index.py +++ b/tests/integration/control/serverless/test_describe_index.py @@ -26,7 +26,7 @@ def test_describe_index_when_ready(self, client, ready_sl_index, create_sl_index 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) + description = client.describe_index(name=notready_sl_index) assert isinstance(description, IndexModel) assert description.name == notready_sl_index diff --git a/tests/integration/control_asyncio/test_describe_index.py b/tests/integration/control_asyncio/test_describe_index.py index f9c5614d..e8c4aff3 100644 --- a/tests/integration/control_asyncio/test_describe_index.py +++ b/tests/integration/control_asyncio/test_describe_index.py @@ -31,7 +31,7 @@ async def test_describe_index_when_ready(self, ready_sl_index, create_sl_index_p async def test_describe_index_when_not_ready(self, notready_sl_index, create_sl_index_params): pc = PineconeAsyncio() - description = await pc.describe_index(notready_sl_index) + description = await pc.describe_index(name=notready_sl_index) assert isinstance(description, IndexModel) assert description.name == notready_sl_index