From 1cbd19bafc561eab91410b2ecdeef08e42fc9fa5 Mon Sep 17 00:00:00 2001 From: rajat08 Date: Mon, 15 Aug 2022 10:35:19 -0400 Subject: [PATCH 1/8] Change how IndexDescription works --- pinecone/manage.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index b71b7ef96..ca77d7536 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -21,17 +21,13 @@ ] -class IndexDescription(NamedTuple): - name: str - metric: str - replicas: int - dimension: int - shards: int - pods: int - pod_type: str - status: None - metadata_config: None - source_collection: None +class IndexDescription(object): + def __init__(self, keys, values): + for k, v in zip(keys, values): + self.__dict__[k] = v + + def __str__(self): + return str(self.__dict__) class CollectionDescription(object): @@ -193,15 +189,10 @@ def describe_index(name: str): :return: Description of an index """ api_instance = _get_api_instance() - response = api_instance.describe_index(name) - db = response['database'] - ready = response['status']['ready'] - state = response['status']['state'] - return IndexDescription(name=db['name'], metric=db['metric'], - replicas=db['replicas'], dimension=db['dimension'], shards=db['shards'], - pods=db.get('pods', db['shards'] * db['replicas']), pod_type=db.get('pod_type', 'p1'), - status={'ready': ready, 'state': state}, metadata_config=db.get('metadata_config'), - source_collection=db.get('source_collection', '')) + response = api_instance.describe_index(name).to_dict() + response_object = IndexDescription(response.keys(), response.values()) + return response_object + # return IndexDescription(**returned_values) def scale_index(name: str, replicas: int): From ff67d707aa0e711dadae9c52a77ae7e29451f7b4 Mon Sep 17 00:00:00 2001 From: rajat08 Date: Mon, 15 Aug 2022 10:36:37 -0400 Subject: [PATCH 2/8] remove comment --- pinecone/manage.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index ca77d7536..e88c190e8 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -192,7 +192,6 @@ def describe_index(name: str): response = api_instance.describe_index(name).to_dict() response_object = IndexDescription(response.keys(), response.values()) return response_object - # return IndexDescription(**returned_values) def scale_index(name: str, replicas: int): From 3e6c3c9dd1c833041d10026aa512cf7501e2b4b2 Mon Sep 17 00:00:00 2001 From: rajat08 Date: Mon, 15 Aug 2022 10:58:29 -0400 Subject: [PATCH 3/8] Fixes --- pinecone/manage.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index e88c190e8..5322a80b1 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -189,7 +189,13 @@ def describe_index(name: str): :return: Description of an index """ api_instance = _get_api_instance() - response = api_instance.describe_index(name).to_dict() + response = api_instance.describe_index(name) + db_status = response.get('status', {}) + response = response['database'].to_dict() + state = db_status.get('state', '') + ready = db_status.get('ready', '') + status = {'state': state, 'ready': ready} + response['status'] = status response_object = IndexDescription(response.keys(), response.values()) return response_object @@ -258,3 +264,4 @@ def configure_index(name: str, replicas: Optional[int] = None, pod_type: Optiona config_args.update(replicas=replicas) patch_request = PatchRequest(**config_args) api_instance.configure_index(name, patch_request=patch_request) + From 7769b1d9f8d25e3f7345221fb2f50db082c32097 Mon Sep 17 00:00:00 2001 From: rajat08 Date: Mon, 15 Aug 2022 12:24:06 -0400 Subject: [PATCH 4/8] PR comments fixes --- pinecone/manage.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index 5322a80b1..27248c977 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -196,6 +196,10 @@ def describe_index(name: str): ready = db_status.get('ready', '') status = {'state': state, 'ready': ready} response['status'] = status + shards = response.get('shards', 1) + replicas = response.get('replicas', 1) + pods = shards * replicas + response['pods'] = pods response_object = IndexDescription(response.keys(), response.values()) return response_object @@ -264,4 +268,3 @@ def configure_index(name: str, replicas: Optional[int] = None, pod_type: Optiona config_args.update(replicas=replicas) patch_request = PatchRequest(**config_args) api_instance.configure_index(name, patch_request=patch_request) - From 2059332709b3ae54658ead9973a1dc47dd691cba Mon Sep 17 00:00:00 2001 From: rajat08 Date: Mon, 15 Aug 2022 13:07:30 -0400 Subject: [PATCH 5/8] Changes --- pinecone/manage.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index 27248c977..f5bf5f8c5 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -22,8 +22,8 @@ class IndexDescription(object): - def __init__(self, keys, values): - for k, v in zip(keys, values): + def __init__(self, response: dict): + for k, v in response.items(): self.__dict__[k] = v def __str__(self): @@ -192,15 +192,15 @@ def describe_index(name: str): response = api_instance.describe_index(name) db_status = response.get('status', {}) response = response['database'].to_dict() - state = db_status.get('state', '') - ready = db_status.get('ready', '') + state = db_status.get('state', None) + ready = db_status.get('ready', None) status = {'state': state, 'ready': ready} response['status'] = status shards = response.get('shards', 1) replicas = response.get('replicas', 1) pods = shards * replicas response['pods'] = pods - response_object = IndexDescription(response.keys(), response.values()) + response_object = IndexDescription(response) return response_object From 757a080ddaf040f3f7c5686abf408a22a38db8cc Mon Sep 17 00:00:00 2001 From: pineconemachine Date: Tue, 16 Aug 2022 13:16:12 +0000 Subject: [PATCH 6/8] Code update --- pinecone/core/client/api/index_operations_api.py | 4 ++-- pinecone/core/client/model/create_request.py | 14 ++++++-------- pinecone/core/client/model/index_meta_database.py | 8 ++++---- pinecone/core/client/model/patch_request.py | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/pinecone/core/client/api/index_operations_api.py b/pinecone/core/client/api/index_operations_api.py index 2ee2c2546..0b2f9a9fe 100644 --- a/pinecone/core/client/api/index_operations_api.py +++ b/pinecone/core/client/api/index_operations_api.py @@ -52,7 +52,7 @@ def __configure_index( ): """configure_index # noqa: E501 - Configure index to change pod type and number of replicas. # noqa: E501 + This operation specifies the pod type and number of replicas for an index. # noqa: E501 This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req=True @@ -63,7 +63,7 @@ def __configure_index( index_name (str): The name of the index Keyword Args: - patch_request (PatchRequest): The desired configuration changes for the index.. [optional] + patch_request (PatchRequest): The desired pod type and replica configuration for the index.. [optional] _return_http_data_only (bool): response data without head status code and headers. Default is True. _preload_content (bool): if False, the urllib3.HTTPResponse object diff --git a/pinecone/core/client/model/create_request.py b/pinecone/core/client/model/create_request.py index 58b388d38..d3790ea63 100644 --- a/pinecone/core/client/model/create_request.py +++ b/pinecone/core/client/model/create_request.py @@ -125,12 +125,11 @@ def discriminator(): @classmethod @convert_js_args_to_python_args - def _from_openapi_data(cls, name, dimension, *args, **kwargs): # noqa: E501 + def _from_openapi_data(cls, name, *args, **kwargs): # noqa: E501 """CreateRequest - a model defined in OpenAPI Args: name (str): The name of the index to be created. The maximum length is 45 characters. - dimension (int): The dimensions of the vectors to be inserted in the index Keyword Args: _check_type (bool): if True, values for parameters in openapi_types @@ -163,12 +162,13 @@ def _from_openapi_data(cls, name, dimension, *args, **kwargs): # noqa: E501 Animal class but this time we won't travel through its discriminator because we passed in _visited_composed_classes = (Animal,) + dimension (int): The dimensions of the vectors to be inserted in the index. [optional] # noqa: E501 index_type (str): The type of vector index. Pinecone supports 'approximated'.. [optional] if omitted the server will use the default value of "approximated" # noqa: E501 metric (str): The distance metric to be used for similarity search. You can use 'euclidean', 'cosine', or 'dotproduct'.. [optional] if omitted the server will use the default value of "cosine" # noqa: E501 pods (int): The number of pods for the index to use,including replicas.. [optional] if omitted the server will use the default value of 1 # noqa: E501 replicas (int): The number of replicas. Replicas duplicate your index. They provide higher availability and throughput.. [optional] if omitted the server will use the default value of 1 # noqa: E501 shards (int): The number of shards to be used in the index.. [optional] if omitted the server will use the default value of 1 # noqa: E501 - pod_type (str): The type of pod to use. One of 's1' or 'p1'.. [optional] if omitted the server will use the default value of "p1" # 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`.. [optional] if omitted the server will use the default value of "p1.x1" # noqa: E501 index_config (dict): [optional] # noqa: E501 metadata_config ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}, none_type): Configuration for the behavior of Pinecone's internal metadata index. By default, all metadata is indexed; when `metadata_config` is present, only specified metadata fields are indexed. To specify metadata fields to index, provide a JSON object of the following form: ``` {\"indexed\": [\"example_metadata_field\"]} ``` . [optional] # noqa: E501 source_collection (str): The name of the collection to create an index from. [optional] # noqa: E501 @@ -200,7 +200,6 @@ def _from_openapi_data(cls, name, dimension, *args, **kwargs): # noqa: E501 self._visited_composed_classes = _visited_composed_classes + (self.__class__,) self.name = name - self.dimension = dimension for var_name, var_value in kwargs.items(): if var_name not in self.attribute_map and \ self._configuration is not None and \ @@ -221,12 +220,11 @@ def _from_openapi_data(cls, name, dimension, *args, **kwargs): # noqa: E501 ]) @convert_js_args_to_python_args - def __init__(self, name, dimension, *args, **kwargs): # noqa: E501 + def __init__(self, name, *args, **kwargs): # noqa: E501 """CreateRequest - a model defined in OpenAPI Args: name (str): The name of the index to be created. The maximum length is 45 characters. - dimension (int): The dimensions of the vectors to be inserted in the index Keyword Args: _check_type (bool): if True, values for parameters in openapi_types @@ -259,12 +257,13 @@ def __init__(self, name, dimension, *args, **kwargs): # noqa: E501 Animal class but this time we won't travel through its discriminator because we passed in _visited_composed_classes = (Animal,) + dimension (int): The dimensions of the vectors to be inserted in the index. [optional] # noqa: E501 index_type (str): The type of vector index. Pinecone supports 'approximated'.. [optional] if omitted the server will use the default value of "approximated" # noqa: E501 metric (str): The distance metric to be used for similarity search. You can use 'euclidean', 'cosine', or 'dotproduct'.. [optional] if omitted the server will use the default value of "cosine" # noqa: E501 pods (int): The number of pods for the index to use,including replicas.. [optional] if omitted the server will use the default value of 1 # noqa: E501 replicas (int): The number of replicas. Replicas duplicate your index. They provide higher availability and throughput.. [optional] if omitted the server will use the default value of 1 # noqa: E501 shards (int): The number of shards to be used in the index.. [optional] if omitted the server will use the default value of 1 # noqa: E501 - pod_type (str): The type of pod to use. One of 's1' or 'p1'.. [optional] if omitted the server will use the default value of "p1" # 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`.. [optional] if omitted the server will use the default value of "p1.x1" # noqa: E501 index_config (dict): [optional] # noqa: E501 metadata_config ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}, none_type): Configuration for the behavior of Pinecone's internal metadata index. By default, all metadata is indexed; when `metadata_config` is present, only specified metadata fields are indexed. To specify metadata fields to index, provide a JSON object of the following form: ``` {\"indexed\": [\"example_metadata_field\"]} ``` . [optional] # noqa: E501 source_collection (str): The name of the collection to create an index from. [optional] # noqa: E501 @@ -294,7 +293,6 @@ def __init__(self, name, dimension, *args, **kwargs): # noqa: E501 self._visited_composed_classes = _visited_composed_classes + (self.__class__,) self.name = name - self.dimension = dimension for var_name, var_value in kwargs.items(): if var_name not in self.attribute_map and \ self._configuration is not None and \ diff --git a/pinecone/core/client/model/index_meta_database.py b/pinecone/core/client/model/index_meta_database.py index 4baf55557..728e2ba63 100644 --- a/pinecone/core/client/model/index_meta_database.py +++ b/pinecone/core/client/model/index_meta_database.py @@ -93,7 +93,7 @@ def openapi_types(): lazy_import() return { 'name': (str,), # noqa: E501 - 'dimensions': (str,), # noqa: E501 + 'dimension': (str,), # noqa: E501 'index_type': (str,), # noqa: E501 'metric': (str,), # noqa: E501 'pods': (int,), # noqa: E501 @@ -111,7 +111,7 @@ def discriminator(): attribute_map = { 'name': 'name', # noqa: E501 - 'dimensions': 'dimensions', # noqa: E501 + 'dimension': 'dimension', # noqa: E501 'index_type': 'index_type', # noqa: E501 'metric': 'metric', # noqa: E501 'pods': 'pods', # noqa: E501 @@ -164,7 +164,7 @@ def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 through its discriminator because we passed in _visited_composed_classes = (Animal,) name (str): [optional] # noqa: E501 - dimensions (str): [optional] # noqa: E501 + dimension (str): [optional] # noqa: E501 index_type (str): [optional] # noqa: E501 metric (str): [optional] # noqa: E501 pods (int): [optional] # noqa: E501 @@ -255,7 +255,7 @@ def __init__(self, *args, **kwargs): # noqa: E501 through its discriminator because we passed in _visited_composed_classes = (Animal,) name (str): [optional] # noqa: E501 - dimensions (str): [optional] # noqa: E501 + dimension (str): [optional] # noqa: E501 index_type (str): [optional] # noqa: E501 metric (str): [optional] # noqa: E501 pods (int): [optional] # noqa: E501 diff --git a/pinecone/core/client/model/patch_request.py b/pinecone/core/client/model/patch_request.py index 45a5135b0..85b66d121 100644 --- a/pinecone/core/client/model/patch_request.py +++ b/pinecone/core/client/model/patch_request.py @@ -142,7 +142,7 @@ def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 through its discriminator because we passed in _visited_composed_classes = (Animal,) replicas (int): The desired number of replicas for the index.. [optional] # noqa: E501 - pod_type (str): The new pod type for the index.. [optional] # noqa: E501 + pod_type (str): The new pod type for the index. One of `s1`, `p1`, or `p2` appended with `.` and one of `x1`, `x2`, `x4`, or `x8`.. [optional] # noqa: E501 """ _check_type = kwargs.pop('_check_type', True) @@ -225,7 +225,7 @@ def __init__(self, *args, **kwargs): # noqa: E501 through its discriminator because we passed in _visited_composed_classes = (Animal,) replicas (int): The desired number of replicas for the index.. [optional] # noqa: E501 - pod_type (str): The new pod type for the index.. [optional] # noqa: E501 + pod_type (str): The new pod type for the index. One of `s1`, `p1`, or `p2` appended with `.` and one of `x1`, `x2`, `x4`, or `x8`.. [optional] # noqa: E501 """ _check_type = kwargs.pop('_check_type', True) From 8da103f9efb71b1f435ac7159fe920f5048c9a3e Mon Sep 17 00:00:00 2001 From: Rajat Tripathi Date: Tue, 16 Aug 2022 09:25:45 -0400 Subject: [PATCH 7/8] Update manage.py --- pinecone/manage.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index f5bf5f8c5..6bde20081 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -21,13 +21,17 @@ ] -class IndexDescription(object): - def __init__(self, response: dict): - for k, v in response.items(): - self.__dict__[k] = v - - def __str__(self): - return str(self.__dict__) +class IndexDescription(NamedTuple): + name: str + metric: str + replicas: int + dimension: int + shards: int + pods: int + pod_type: str + status: None + metadata_config: None + source_collection: None class CollectionDescription(object): @@ -63,7 +67,7 @@ def _get_status(name: str): def create_index( name: str, - dimension: int, + dimension: int = None, timeout: int = None, index_type: str = "approximated", metric: str = "cosine", @@ -190,18 +194,14 @@ def describe_index(name: str): """ api_instance = _get_api_instance() response = api_instance.describe_index(name) - db_status = response.get('status', {}) - response = response['database'].to_dict() - state = db_status.get('state', None) - ready = db_status.get('ready', None) - status = {'state': state, 'ready': ready} - response['status'] = status - shards = response.get('shards', 1) - replicas = response.get('replicas', 1) - pods = shards * replicas - response['pods'] = pods - response_object = IndexDescription(response) - return response_object + db = response['database'] + ready = response['status']['ready'] + state = response['status']['state'] + return IndexDescription(name=db['name'], metric=db['metric'], + replicas=db['replicas'], dimension=db['dimension'], shards=db['shards'], + pods=db.get('pods', db['shards'] * db['replicas']), pod_type=db.get('pod_type', 'p1'), + status={'ready': ready, 'state': state}, metadata_config=db.get('metadata_config'), + source_collection=db.get('source_collection', '')) def scale_index(name: str, replicas: int): From 8c4ed411544025bf48a4ff475531e57edf2d8819 Mon Sep 17 00:00:00 2001 From: Rajat Tripathi Date: Tue, 16 Aug 2022 09:44:07 -0400 Subject: [PATCH 8/8] Remove type check on create --- pinecone/manage.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pinecone/manage.py b/pinecone/manage.py index 6bde20081..443f1c051 100644 --- a/pinecone/manage.py +++ b/pinecone/manage.py @@ -126,7 +126,8 @@ def create_index( pod_type=pod_type, index_config=index_config or {}, metadata_config=metadata_config, - source_collection=source_collection + source_collection=source_collection, + _check_type=False )) def is_ready():