44
55from pinecone .utils import parse_non_empty_args , convert_enum_to_string
66
7- from pinecone .core .openapi .db_control .model .create_collection_request import (
8- CreateCollectionRequest ,
9- )
7+ from pinecone .core .openapi .db_control .model .create_collection_request import CreateCollectionRequest
108from pinecone .core .openapi .db_control .model .create_index_for_model_request import (
119 CreateIndexForModelRequest ,
1210)
1311from pinecone .core .openapi .db_control .model .create_index_for_model_request_embed import (
1412 CreateIndexForModelRequestEmbed ,
1513)
16- from pinecone .core .openapi .db_control .model .create_index_request import (
17- CreateIndexRequest ,
18- )
19- from pinecone .core .openapi .db_control .model .configure_index_request import (
20- ConfigureIndexRequest ,
21- )
14+ from pinecone .core .openapi .db_control .model .create_index_request import CreateIndexRequest
15+ from pinecone .core .openapi .db_control .model .configure_index_request import ConfigureIndexRequest
2216from pinecone .core .openapi .db_control .model .configure_index_request_spec import (
2317 ConfigureIndexRequestSpec ,
2418)
3832)
3933from pinecone .core .openapi .db_control .model .byoc_spec import ByocSpec as ByocSpecModel
4034from pinecone .core .openapi .db_control .model .pod_spec import PodSpec as PodSpecModel
41- from pinecone .core .openapi .db_control .model .pod_spec_metadata_config import (
42- PodSpecMetadataConfig ,
43- )
35+ from pinecone .core .openapi .db_control .model .pod_spec_metadata_config import PodSpecMetadataConfig
4436from pinecone .core .openapi .db_control .model .create_index_from_backup_request import (
4537 CreateIndexFromBackupRequest ,
4638)
47- from pinecone .db_control .models import (
48- ServerlessSpec ,
49- PodSpec ,
50- ByocSpec ,
51- IndexModel ,
52- IndexEmbed ,
53- )
39+ from pinecone .db_control .models import ServerlessSpec , PodSpec , ByocSpec , IndexModel , IndexEmbed
5440
5541from pinecone .db_control .enums import (
5642 Metric ,
@@ -91,30 +77,18 @@ def __parse_deletion_protection(
9177 if deletion_protection in ["enabled" , "disabled" ]:
9278 return DeletionProtectionModel (deletion_protection )
9379 else :
94- raise ValueError (
95- "deletion_protection must be either 'enabled' or 'disabled'"
96- )
80+ raise ValueError ("deletion_protection must be either 'enabled' or 'disabled'" )
9781
9882 @staticmethod
99- def __parse_index_spec (
100- spec : Union [Dict , ServerlessSpec , PodSpec , ByocSpec ],
101- ) -> IndexSpec :
83+ def __parse_index_spec (spec : Union [Dict , ServerlessSpec , PodSpec , ByocSpec ]) -> IndexSpec :
10284 if isinstance (spec , dict ):
10385 if "serverless" in spec :
104- spec ["serverless" ]["cloud" ] = convert_enum_to_string (
105- spec ["serverless" ]["cloud" ]
106- )
107- spec ["serverless" ]["region" ] = convert_enum_to_string (
108- spec ["serverless" ]["region" ]
109- )
86+ spec ["serverless" ]["cloud" ] = convert_enum_to_string (spec ["serverless" ]["cloud" ])
87+ spec ["serverless" ]["region" ] = convert_enum_to_string (spec ["serverless" ]["region" ])
11088
111- index_spec = IndexSpec (
112- serverless = ServerlessSpecModel (** spec ["serverless" ])
113- )
89+ index_spec = IndexSpec (serverless = ServerlessSpecModel (** spec ["serverless" ]))
11490 elif "pod" in spec :
115- spec ["pod" ]["environment" ] = convert_enum_to_string (
116- spec ["pod" ]["environment" ]
117- )
91+ spec ["pod" ]["environment" ] = convert_enum_to_string (spec ["pod" ]["environment" ])
11892 args_dict = parse_non_empty_args (
11993 [
12094 ("environment" , spec ["pod" ].get ("environment" )),
@@ -133,9 +107,7 @@ def __parse_index_spec(
133107 elif "byoc" in spec :
134108 index_spec = IndexSpec (byoc = ByocSpecModel (** spec ["byoc" ]))
135109 else :
136- raise ValueError (
137- "spec must contain either 'serverless', 'pod', or 'byoc' key"
138- )
110+ raise ValueError ("spec must contain either 'serverless', 'pod', or 'byoc' key" )
139111 elif isinstance (spec , ServerlessSpec ):
140112 index_spec = IndexSpec (
141113 serverless = ServerlessSpecModel (cloud = spec .cloud , region = spec .region )
@@ -155,17 +127,13 @@ def __parse_index_spec(
155127 )
156128
157129 index_spec = IndexSpec (
158- pod = PodSpecModel (
159- environment = spec .environment , pod_type = spec .pod_type , ** args_dict
160- )
130+ pod = PodSpecModel (environment = spec .environment , pod_type = spec .pod_type , ** args_dict )
161131 )
162132 elif isinstance (spec , ByocSpec ):
163133 args_dict = parse_non_empty_args ([("environment" , spec .environment )])
164134 index_spec = IndexSpec (byoc = ByocSpecModel (** args_dict ))
165135 else :
166- raise TypeError (
167- "spec must be of type dict, ServerlessSpec, PodSpec, or ByocSpec"
168- )
136+ raise TypeError ("spec must be of type dict, ServerlessSpec, PodSpec, or ByocSpec" )
169137
170138 return index_spec
171139
@@ -175,9 +143,7 @@ def create_index_request(
175143 spec : Union [Dict , ServerlessSpec , PodSpec , ByocSpec ],
176144 dimension : Optional [int ] = None ,
177145 metric : Optional [Union [Metric , str ]] = Metric .COSINE ,
178- deletion_protection : Optional [
179- Union [DeletionProtection , str ]
180- ] = DeletionProtection .DISABLED ,
146+ deletion_protection : Optional [Union [DeletionProtection , str ]] = DeletionProtection .DISABLED ,
181147 vector_type : Optional [Union [VectorType , str ]] = VectorType .DENSE ,
182148 tags : Optional [Dict [str , str ]] = None ,
183149 ) -> CreateIndexRequest :
@@ -186,9 +152,7 @@ def create_index_request(
186152 if vector_type is not None :
187153 vector_type = convert_enum_to_string (vector_type )
188154 if deletion_protection is not None :
189- dp = PineconeDBControlRequestFactory .__parse_deletion_protection (
190- deletion_protection
191- )
155+ dp = PineconeDBControlRequestFactory .__parse_deletion_protection (deletion_protection )
192156 else :
193157 dp = None
194158
@@ -219,16 +183,12 @@ def create_index_for_model_request(
219183 region : Union [AwsRegion , GcpRegion , AzureRegion , str ],
220184 embed : Union [IndexEmbed , CreateIndexForModelEmbedTypedDict ],
221185 tags : Optional [Dict [str , str ]] = None ,
222- deletion_protection : Optional [
223- Union [DeletionProtection , str ]
224- ] = DeletionProtection .DISABLED ,
186+ deletion_protection : Optional [Union [DeletionProtection , str ]] = DeletionProtection .DISABLED ,
225187 ) -> CreateIndexForModelRequest :
226188 cloud = convert_enum_to_string (cloud )
227189 region = convert_enum_to_string (region )
228190 if deletion_protection is not None :
229- dp = PineconeDBControlRequestFactory .__parse_deletion_protection (
230- deletion_protection
231- )
191+ dp = PineconeDBControlRequestFactory .__parse_deletion_protection (deletion_protection )
232192 else :
233193 dp = None
234194 tags_obj = PineconeDBControlRequestFactory .__parse_tags (tags )
@@ -265,23 +225,17 @@ def create_index_for_model_request(
265225 @staticmethod
266226 def create_index_from_backup_request (
267227 name : str ,
268- deletion_protection : Optional [
269- Union [DeletionProtection , str ]
270- ] = DeletionProtection .DISABLED ,
228+ deletion_protection : Optional [Union [DeletionProtection , str ]] = DeletionProtection .DISABLED ,
271229 tags : Optional [Dict [str , str ]] = None ,
272230 ) -> CreateIndexFromBackupRequest :
273231 if deletion_protection is not None :
274- dp = PineconeDBControlRequestFactory .__parse_deletion_protection (
275- deletion_protection
276- )
232+ dp = PineconeDBControlRequestFactory .__parse_deletion_protection (deletion_protection )
277233 else :
278234 dp = None
279235
280236 tags_obj = PineconeDBControlRequestFactory .__parse_tags (tags )
281237
282- return CreateIndexFromBackupRequest (
283- name = name , deletion_protection = dp , tags = tags_obj
284- )
238+ return CreateIndexFromBackupRequest (name = name , deletion_protection = dp , tags = tags_obj )
285239
286240 @staticmethod
287241 def configure_index_request (
@@ -299,9 +253,7 @@ def configure_index_request(
299253 elif deletion_protection in ["enabled" , "disabled" ]:
300254 dp = DeletionProtectionModel (deletion_protection )
301255 else :
302- raise ValueError (
303- "deletion_protection must be either 'enabled' or 'disabled'"
304- )
256+ raise ValueError ("deletion_protection must be either 'enabled' or 'disabled'" )
305257
306258 fetched_tags = description .tags
307259 if fetched_tags is None :
@@ -329,9 +281,7 @@ def configure_index_request(
329281
330282 spec = None
331283 if pod_config_args :
332- spec = ConfigureIndexRequestSpec (
333- pod = ConfigureIndexRequestSpecPod (** pod_config_args )
334- )
284+ spec = ConfigureIndexRequestSpec (pod = ConfigureIndexRequestSpecPod (** pod_config_args ))
335285
336286 args_dict = parse_non_empty_args (
337287 [
0 commit comments