lambdadb 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lambdadb might be problematic. Click here for more details.
- lambdadb/__init__.py +17 -0
- lambdadb/_hooks/__init__.py +5 -0
- lambdadb/_hooks/registration.py +13 -0
- lambdadb/_hooks/sdkhooks.py +76 -0
- lambdadb/_hooks/types.py +106 -0
- lambdadb/_version.py +15 -0
- lambdadb/basesdk.py +358 -0
- lambdadb/collections.py +1630 -0
- lambdadb/docs.py +1328 -0
- lambdadb/errors/__init__.py +74 -0
- lambdadb/errors/apierror.py +22 -0
- lambdadb/errors/badrequest_error.py +20 -0
- lambdadb/errors/internalservererror.py +20 -0
- lambdadb/errors/resourcealreadyexists_error.py +20 -0
- lambdadb/errors/resourcenotfound_error.py +20 -0
- lambdadb/errors/toomanyrequests_error.py +20 -0
- lambdadb/errors/unauthenticated_error.py +20 -0
- lambdadb/httpclient.py +126 -0
- lambdadb/models/__init__.py +420 -0
- lambdadb/models/bulkupsertdocsop.py +59 -0
- lambdadb/models/collectionresponse.py +64 -0
- lambdadb/models/createcollectionop.py +64 -0
- lambdadb/models/createprojectop.py +39 -0
- lambdadb/models/deletecollectionop.py +43 -0
- lambdadb/models/deletedocsop.py +88 -0
- lambdadb/models/deleteprojectop.py +52 -0
- lambdadb/models/fetchdocsop.py +102 -0
- lambdadb/models/getbulkupsertdocsop.py +82 -0
- lambdadb/models/getcollectionop.py +30 -0
- lambdadb/models/getprojectop.py +39 -0
- lambdadb/models/indexconfigs_union.py +95 -0
- lambdadb/models/listcollectionsop.py +35 -0
- lambdadb/models/listprojectsop.py +38 -0
- lambdadb/models/projectresponse.py +38 -0
- lambdadb/models/querycollectionop.py +152 -0
- lambdadb/models/security.py +25 -0
- lambdadb/models/status.py +12 -0
- lambdadb/models/updatecollectionop.py +48 -0
- lambdadb/models/updateprojectop.py +58 -0
- lambdadb/models/upsertdocsop.py +67 -0
- lambdadb/projects.py +1228 -0
- lambdadb/py.typed +1 -0
- lambdadb/sdk.py +170 -0
- lambdadb/sdkconfiguration.py +56 -0
- lambdadb/types/__init__.py +21 -0
- lambdadb/types/basemodel.py +39 -0
- lambdadb/utils/__init__.py +187 -0
- lambdadb/utils/annotations.py +55 -0
- lambdadb/utils/datetimes.py +23 -0
- lambdadb/utils/enums.py +74 -0
- lambdadb/utils/eventstreaming.py +238 -0
- lambdadb/utils/forms.py +202 -0
- lambdadb/utils/headers.py +136 -0
- lambdadb/utils/logger.py +27 -0
- lambdadb/utils/metadata.py +118 -0
- lambdadb/utils/queryparams.py +205 -0
- lambdadb/utils/requestbodies.py +66 -0
- lambdadb/utils/retries.py +217 -0
- lambdadb/utils/security.py +192 -0
- lambdadb/utils/serializers.py +248 -0
- lambdadb/utils/url.py +155 -0
- lambdadb/utils/values.py +137 -0
- lambdadb-0.1.2.dist-info/LICENSE +201 -0
- lambdadb-0.1.2.dist-info/METADATA +514 -0
- lambdadb-0.1.2.dist-info/RECORD +66 -0
- lambdadb-0.1.2.dist-info/WHEEL +4 -0
lambdadb/collections.py
ADDED
|
@@ -0,0 +1,1630 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from .basesdk import BaseSDK
|
|
4
|
+
from .sdkconfiguration import SDKConfiguration
|
|
5
|
+
from lambdadb import errors, models, utils
|
|
6
|
+
from lambdadb._hooks import HookContext
|
|
7
|
+
from lambdadb.docs import Docs
|
|
8
|
+
from lambdadb.types import OptionalNullable, UNSET
|
|
9
|
+
from lambdadb.utils import get_security_from_env
|
|
10
|
+
from typing import Any, Dict, List, Mapping, Optional, Union
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Collections(BaseSDK):
|
|
14
|
+
docs: Docs
|
|
15
|
+
|
|
16
|
+
def __init__(self, sdk_config: SDKConfiguration) -> None:
|
|
17
|
+
BaseSDK.__init__(self, sdk_config)
|
|
18
|
+
self.sdk_configuration = sdk_config
|
|
19
|
+
self._init_sdks()
|
|
20
|
+
|
|
21
|
+
def _init_sdks(self):
|
|
22
|
+
self.docs = Docs(self.sdk_configuration)
|
|
23
|
+
|
|
24
|
+
def list(
|
|
25
|
+
self,
|
|
26
|
+
*,
|
|
27
|
+
project_name: str,
|
|
28
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
29
|
+
server_url: Optional[str] = None,
|
|
30
|
+
timeout_ms: Optional[int] = None,
|
|
31
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
32
|
+
) -> models.ListcollectionsResponse:
|
|
33
|
+
r"""List all collections in an existing project.
|
|
34
|
+
|
|
35
|
+
:param project_name: Project name.
|
|
36
|
+
:param retries: Override the default retry configuration for this method
|
|
37
|
+
:param server_url: Override the default server URL for this method
|
|
38
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
39
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
40
|
+
"""
|
|
41
|
+
base_url = None
|
|
42
|
+
url_variables = None
|
|
43
|
+
if timeout_ms is None:
|
|
44
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
45
|
+
|
|
46
|
+
if server_url is not None:
|
|
47
|
+
base_url = server_url
|
|
48
|
+
else:
|
|
49
|
+
base_url = self._get_url(base_url, url_variables)
|
|
50
|
+
|
|
51
|
+
request = models.ListcollectionsRequest(
|
|
52
|
+
project_name=project_name,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
req = self._build_request(
|
|
56
|
+
method="GET",
|
|
57
|
+
path="/projects/{projectName}/collections",
|
|
58
|
+
base_url=base_url,
|
|
59
|
+
url_variables=url_variables,
|
|
60
|
+
request=request,
|
|
61
|
+
request_body_required=False,
|
|
62
|
+
request_has_path_params=True,
|
|
63
|
+
request_has_query_params=True,
|
|
64
|
+
user_agent_header="user-agent",
|
|
65
|
+
accept_header_value="application/json",
|
|
66
|
+
http_headers=http_headers,
|
|
67
|
+
security=self.sdk_configuration.security,
|
|
68
|
+
timeout_ms=timeout_ms,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
if retries == UNSET:
|
|
72
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
73
|
+
retries = self.sdk_configuration.retry_config
|
|
74
|
+
else:
|
|
75
|
+
retries = utils.RetryConfig(
|
|
76
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
retry_config = None
|
|
80
|
+
if isinstance(retries, utils.RetryConfig):
|
|
81
|
+
retry_config = (retries, ["429", "5XX"])
|
|
82
|
+
|
|
83
|
+
http_res = self.do_request(
|
|
84
|
+
hook_ctx=HookContext(
|
|
85
|
+
base_url=base_url or "",
|
|
86
|
+
operation_id="listcollections",
|
|
87
|
+
oauth2_scopes=[],
|
|
88
|
+
security_source=get_security_from_env(
|
|
89
|
+
self.sdk_configuration.security, models.Security
|
|
90
|
+
),
|
|
91
|
+
),
|
|
92
|
+
request=req,
|
|
93
|
+
error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
|
|
94
|
+
retry_config=retry_config,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
response_data: Any = None
|
|
98
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
99
|
+
return utils.unmarshal_json(http_res.text, models.ListcollectionsResponse)
|
|
100
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
101
|
+
response_data = utils.unmarshal_json(
|
|
102
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
103
|
+
)
|
|
104
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
105
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
106
|
+
response_data = utils.unmarshal_json(
|
|
107
|
+
http_res.text, errors.ResourceNotFoundErrorData
|
|
108
|
+
)
|
|
109
|
+
raise errors.ResourceNotFoundError(data=response_data)
|
|
110
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
111
|
+
response_data = utils.unmarshal_json(
|
|
112
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
113
|
+
)
|
|
114
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
115
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
116
|
+
response_data = utils.unmarshal_json(
|
|
117
|
+
http_res.text, errors.InternalServerErrorData
|
|
118
|
+
)
|
|
119
|
+
raise errors.InternalServerError(data=response_data)
|
|
120
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
121
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
122
|
+
raise errors.APIError(
|
|
123
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
124
|
+
)
|
|
125
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
126
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
127
|
+
raise errors.APIError(
|
|
128
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
content_type = http_res.headers.get("Content-Type")
|
|
132
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
133
|
+
raise errors.APIError(
|
|
134
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
135
|
+
http_res.status_code,
|
|
136
|
+
http_res_text,
|
|
137
|
+
http_res,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
async def list_async(
|
|
141
|
+
self,
|
|
142
|
+
*,
|
|
143
|
+
project_name: str,
|
|
144
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
145
|
+
server_url: Optional[str] = None,
|
|
146
|
+
timeout_ms: Optional[int] = None,
|
|
147
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
148
|
+
) -> models.ListcollectionsResponse:
|
|
149
|
+
r"""List all collections in an existing project.
|
|
150
|
+
|
|
151
|
+
:param project_name: Project name.
|
|
152
|
+
:param retries: Override the default retry configuration for this method
|
|
153
|
+
:param server_url: Override the default server URL for this method
|
|
154
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
155
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
156
|
+
"""
|
|
157
|
+
base_url = None
|
|
158
|
+
url_variables = None
|
|
159
|
+
if timeout_ms is None:
|
|
160
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
161
|
+
|
|
162
|
+
if server_url is not None:
|
|
163
|
+
base_url = server_url
|
|
164
|
+
else:
|
|
165
|
+
base_url = self._get_url(base_url, url_variables)
|
|
166
|
+
|
|
167
|
+
request = models.ListcollectionsRequest(
|
|
168
|
+
project_name=project_name,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
req = self._build_request_async(
|
|
172
|
+
method="GET",
|
|
173
|
+
path="/projects/{projectName}/collections",
|
|
174
|
+
base_url=base_url,
|
|
175
|
+
url_variables=url_variables,
|
|
176
|
+
request=request,
|
|
177
|
+
request_body_required=False,
|
|
178
|
+
request_has_path_params=True,
|
|
179
|
+
request_has_query_params=True,
|
|
180
|
+
user_agent_header="user-agent",
|
|
181
|
+
accept_header_value="application/json",
|
|
182
|
+
http_headers=http_headers,
|
|
183
|
+
security=self.sdk_configuration.security,
|
|
184
|
+
timeout_ms=timeout_ms,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
if retries == UNSET:
|
|
188
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
189
|
+
retries = self.sdk_configuration.retry_config
|
|
190
|
+
else:
|
|
191
|
+
retries = utils.RetryConfig(
|
|
192
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
retry_config = None
|
|
196
|
+
if isinstance(retries, utils.RetryConfig):
|
|
197
|
+
retry_config = (retries, ["429", "5XX"])
|
|
198
|
+
|
|
199
|
+
http_res = await self.do_request_async(
|
|
200
|
+
hook_ctx=HookContext(
|
|
201
|
+
base_url=base_url or "",
|
|
202
|
+
operation_id="listcollections",
|
|
203
|
+
oauth2_scopes=[],
|
|
204
|
+
security_source=get_security_from_env(
|
|
205
|
+
self.sdk_configuration.security, models.Security
|
|
206
|
+
),
|
|
207
|
+
),
|
|
208
|
+
request=req,
|
|
209
|
+
error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
|
|
210
|
+
retry_config=retry_config,
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
response_data: Any = None
|
|
214
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
215
|
+
return utils.unmarshal_json(http_res.text, models.ListcollectionsResponse)
|
|
216
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
217
|
+
response_data = utils.unmarshal_json(
|
|
218
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
219
|
+
)
|
|
220
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
221
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
222
|
+
response_data = utils.unmarshal_json(
|
|
223
|
+
http_res.text, errors.ResourceNotFoundErrorData
|
|
224
|
+
)
|
|
225
|
+
raise errors.ResourceNotFoundError(data=response_data)
|
|
226
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
227
|
+
response_data = utils.unmarshal_json(
|
|
228
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
229
|
+
)
|
|
230
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
231
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
232
|
+
response_data = utils.unmarshal_json(
|
|
233
|
+
http_res.text, errors.InternalServerErrorData
|
|
234
|
+
)
|
|
235
|
+
raise errors.InternalServerError(data=response_data)
|
|
236
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
237
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
238
|
+
raise errors.APIError(
|
|
239
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
240
|
+
)
|
|
241
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
242
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
243
|
+
raise errors.APIError(
|
|
244
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
content_type = http_res.headers.get("Content-Type")
|
|
248
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
249
|
+
raise errors.APIError(
|
|
250
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
251
|
+
http_res.status_code,
|
|
252
|
+
http_res_text,
|
|
253
|
+
http_res,
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
def create(
|
|
257
|
+
self,
|
|
258
|
+
*,
|
|
259
|
+
project_name: str,
|
|
260
|
+
collection_name: str,
|
|
261
|
+
index_configs: Optional[
|
|
262
|
+
Union[
|
|
263
|
+
Dict[str, models.IndexConfigsUnion],
|
|
264
|
+
Dict[str, models.IndexConfigsUnionTypedDict],
|
|
265
|
+
]
|
|
266
|
+
] = None,
|
|
267
|
+
source_project_name: Optional[str] = None,
|
|
268
|
+
source_collection_name: Optional[str] = None,
|
|
269
|
+
source_datetime: Optional[str] = None,
|
|
270
|
+
source_project_api_key: Optional[str] = None,
|
|
271
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
272
|
+
server_url: Optional[str] = None,
|
|
273
|
+
timeout_ms: Optional[int] = None,
|
|
274
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
275
|
+
) -> models.CollectionResponse:
|
|
276
|
+
r"""Create an collection.
|
|
277
|
+
|
|
278
|
+
:param project_name: Project name.
|
|
279
|
+
:param collection_name: Collection name must be unique within a project and the supported maximum length is 52.
|
|
280
|
+
:param index_configs:
|
|
281
|
+
:param source_project_name:
|
|
282
|
+
:param source_collection_name:
|
|
283
|
+
:param source_datetime:
|
|
284
|
+
:param source_project_api_key:
|
|
285
|
+
:param retries: Override the default retry configuration for this method
|
|
286
|
+
:param server_url: Override the default server URL for this method
|
|
287
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
288
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
289
|
+
"""
|
|
290
|
+
base_url = None
|
|
291
|
+
url_variables = None
|
|
292
|
+
if timeout_ms is None:
|
|
293
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
294
|
+
|
|
295
|
+
if server_url is not None:
|
|
296
|
+
base_url = server_url
|
|
297
|
+
else:
|
|
298
|
+
base_url = self._get_url(base_url, url_variables)
|
|
299
|
+
|
|
300
|
+
request = models.CreateCollectionRequest(
|
|
301
|
+
project_name=project_name,
|
|
302
|
+
request_body=models.CreateCollectionRequestBody(
|
|
303
|
+
collection_name=collection_name,
|
|
304
|
+
index_configs=utils.get_pydantic_model(
|
|
305
|
+
index_configs, Optional[Dict[str, models.IndexConfigsUnion]]
|
|
306
|
+
),
|
|
307
|
+
source_project_name=source_project_name,
|
|
308
|
+
source_collection_name=source_collection_name,
|
|
309
|
+
source_datetime=source_datetime,
|
|
310
|
+
source_project_api_key=source_project_api_key,
|
|
311
|
+
),
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
req = self._build_request(
|
|
315
|
+
method="POST",
|
|
316
|
+
path="/projects/{projectName}/collections",
|
|
317
|
+
base_url=base_url,
|
|
318
|
+
url_variables=url_variables,
|
|
319
|
+
request=request,
|
|
320
|
+
request_body_required=True,
|
|
321
|
+
request_has_path_params=True,
|
|
322
|
+
request_has_query_params=True,
|
|
323
|
+
user_agent_header="user-agent",
|
|
324
|
+
accept_header_value="application/json",
|
|
325
|
+
http_headers=http_headers,
|
|
326
|
+
security=self.sdk_configuration.security,
|
|
327
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
328
|
+
request.request_body,
|
|
329
|
+
False,
|
|
330
|
+
False,
|
|
331
|
+
"json",
|
|
332
|
+
models.CreateCollectionRequestBody,
|
|
333
|
+
),
|
|
334
|
+
timeout_ms=timeout_ms,
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
if retries == UNSET:
|
|
338
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
339
|
+
retries = self.sdk_configuration.retry_config
|
|
340
|
+
else:
|
|
341
|
+
retries = utils.RetryConfig(
|
|
342
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
retry_config = None
|
|
346
|
+
if isinstance(retries, utils.RetryConfig):
|
|
347
|
+
retry_config = (retries, ["429", "5XX"])
|
|
348
|
+
|
|
349
|
+
http_res = self.do_request(
|
|
350
|
+
hook_ctx=HookContext(
|
|
351
|
+
base_url=base_url or "",
|
|
352
|
+
operation_id="createCollection",
|
|
353
|
+
oauth2_scopes=[],
|
|
354
|
+
security_source=get_security_from_env(
|
|
355
|
+
self.sdk_configuration.security, models.Security
|
|
356
|
+
),
|
|
357
|
+
),
|
|
358
|
+
request=req,
|
|
359
|
+
error_status_codes=["400", "401", "409", "429", "4XX", "500", "5XX"],
|
|
360
|
+
retry_config=retry_config,
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
response_data: Any = None
|
|
364
|
+
if utils.match_response(http_res, "202", "application/json"):
|
|
365
|
+
return utils.unmarshal_json(http_res.text, models.CollectionResponse)
|
|
366
|
+
if utils.match_response(http_res, "400", "application/json"):
|
|
367
|
+
response_data = utils.unmarshal_json(
|
|
368
|
+
http_res.text, errors.BadRequestErrorData
|
|
369
|
+
)
|
|
370
|
+
raise errors.BadRequestError(data=response_data)
|
|
371
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
372
|
+
response_data = utils.unmarshal_json(
|
|
373
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
374
|
+
)
|
|
375
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
376
|
+
if utils.match_response(http_res, "409", "application/json"):
|
|
377
|
+
response_data = utils.unmarshal_json(
|
|
378
|
+
http_res.text, errors.ResourceAlreadyExistsErrorData
|
|
379
|
+
)
|
|
380
|
+
raise errors.ResourceAlreadyExistsError(data=response_data)
|
|
381
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
382
|
+
response_data = utils.unmarshal_json(
|
|
383
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
384
|
+
)
|
|
385
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
386
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
387
|
+
response_data = utils.unmarshal_json(
|
|
388
|
+
http_res.text, errors.InternalServerErrorData
|
|
389
|
+
)
|
|
390
|
+
raise errors.InternalServerError(data=response_data)
|
|
391
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
392
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
393
|
+
raise errors.APIError(
|
|
394
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
395
|
+
)
|
|
396
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
397
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
398
|
+
raise errors.APIError(
|
|
399
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
content_type = http_res.headers.get("Content-Type")
|
|
403
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
404
|
+
raise errors.APIError(
|
|
405
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
406
|
+
http_res.status_code,
|
|
407
|
+
http_res_text,
|
|
408
|
+
http_res,
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
async def create_async(
|
|
412
|
+
self,
|
|
413
|
+
*,
|
|
414
|
+
project_name: str,
|
|
415
|
+
collection_name: str,
|
|
416
|
+
index_configs: Optional[
|
|
417
|
+
Union[
|
|
418
|
+
Dict[str, models.IndexConfigsUnion],
|
|
419
|
+
Dict[str, models.IndexConfigsUnionTypedDict],
|
|
420
|
+
]
|
|
421
|
+
] = None,
|
|
422
|
+
source_project_name: Optional[str] = None,
|
|
423
|
+
source_collection_name: Optional[str] = None,
|
|
424
|
+
source_datetime: Optional[str] = None,
|
|
425
|
+
source_project_api_key: Optional[str] = None,
|
|
426
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
427
|
+
server_url: Optional[str] = None,
|
|
428
|
+
timeout_ms: Optional[int] = None,
|
|
429
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
430
|
+
) -> models.CollectionResponse:
|
|
431
|
+
r"""Create an collection.
|
|
432
|
+
|
|
433
|
+
:param project_name: Project name.
|
|
434
|
+
:param collection_name: Collection name must be unique within a project and the supported maximum length is 52.
|
|
435
|
+
:param index_configs:
|
|
436
|
+
:param source_project_name:
|
|
437
|
+
:param source_collection_name:
|
|
438
|
+
:param source_datetime:
|
|
439
|
+
:param source_project_api_key:
|
|
440
|
+
:param retries: Override the default retry configuration for this method
|
|
441
|
+
:param server_url: Override the default server URL for this method
|
|
442
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
443
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
444
|
+
"""
|
|
445
|
+
base_url = None
|
|
446
|
+
url_variables = None
|
|
447
|
+
if timeout_ms is None:
|
|
448
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
449
|
+
|
|
450
|
+
if server_url is not None:
|
|
451
|
+
base_url = server_url
|
|
452
|
+
else:
|
|
453
|
+
base_url = self._get_url(base_url, url_variables)
|
|
454
|
+
|
|
455
|
+
request = models.CreateCollectionRequest(
|
|
456
|
+
project_name=project_name,
|
|
457
|
+
request_body=models.CreateCollectionRequestBody(
|
|
458
|
+
collection_name=collection_name,
|
|
459
|
+
index_configs=utils.get_pydantic_model(
|
|
460
|
+
index_configs, Optional[Dict[str, models.IndexConfigsUnion]]
|
|
461
|
+
),
|
|
462
|
+
source_project_name=source_project_name,
|
|
463
|
+
source_collection_name=source_collection_name,
|
|
464
|
+
source_datetime=source_datetime,
|
|
465
|
+
source_project_api_key=source_project_api_key,
|
|
466
|
+
),
|
|
467
|
+
)
|
|
468
|
+
|
|
469
|
+
req = self._build_request_async(
|
|
470
|
+
method="POST",
|
|
471
|
+
path="/projects/{projectName}/collections",
|
|
472
|
+
base_url=base_url,
|
|
473
|
+
url_variables=url_variables,
|
|
474
|
+
request=request,
|
|
475
|
+
request_body_required=True,
|
|
476
|
+
request_has_path_params=True,
|
|
477
|
+
request_has_query_params=True,
|
|
478
|
+
user_agent_header="user-agent",
|
|
479
|
+
accept_header_value="application/json",
|
|
480
|
+
http_headers=http_headers,
|
|
481
|
+
security=self.sdk_configuration.security,
|
|
482
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
483
|
+
request.request_body,
|
|
484
|
+
False,
|
|
485
|
+
False,
|
|
486
|
+
"json",
|
|
487
|
+
models.CreateCollectionRequestBody,
|
|
488
|
+
),
|
|
489
|
+
timeout_ms=timeout_ms,
|
|
490
|
+
)
|
|
491
|
+
|
|
492
|
+
if retries == UNSET:
|
|
493
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
494
|
+
retries = self.sdk_configuration.retry_config
|
|
495
|
+
else:
|
|
496
|
+
retries = utils.RetryConfig(
|
|
497
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
498
|
+
)
|
|
499
|
+
|
|
500
|
+
retry_config = None
|
|
501
|
+
if isinstance(retries, utils.RetryConfig):
|
|
502
|
+
retry_config = (retries, ["429", "5XX"])
|
|
503
|
+
|
|
504
|
+
http_res = await self.do_request_async(
|
|
505
|
+
hook_ctx=HookContext(
|
|
506
|
+
base_url=base_url or "",
|
|
507
|
+
operation_id="createCollection",
|
|
508
|
+
oauth2_scopes=[],
|
|
509
|
+
security_source=get_security_from_env(
|
|
510
|
+
self.sdk_configuration.security, models.Security
|
|
511
|
+
),
|
|
512
|
+
),
|
|
513
|
+
request=req,
|
|
514
|
+
error_status_codes=["400", "401", "409", "429", "4XX", "500", "5XX"],
|
|
515
|
+
retry_config=retry_config,
|
|
516
|
+
)
|
|
517
|
+
|
|
518
|
+
response_data: Any = None
|
|
519
|
+
if utils.match_response(http_res, "202", "application/json"):
|
|
520
|
+
return utils.unmarshal_json(http_res.text, models.CollectionResponse)
|
|
521
|
+
if utils.match_response(http_res, "400", "application/json"):
|
|
522
|
+
response_data = utils.unmarshal_json(
|
|
523
|
+
http_res.text, errors.BadRequestErrorData
|
|
524
|
+
)
|
|
525
|
+
raise errors.BadRequestError(data=response_data)
|
|
526
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
527
|
+
response_data = utils.unmarshal_json(
|
|
528
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
529
|
+
)
|
|
530
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
531
|
+
if utils.match_response(http_res, "409", "application/json"):
|
|
532
|
+
response_data = utils.unmarshal_json(
|
|
533
|
+
http_res.text, errors.ResourceAlreadyExistsErrorData
|
|
534
|
+
)
|
|
535
|
+
raise errors.ResourceAlreadyExistsError(data=response_data)
|
|
536
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
537
|
+
response_data = utils.unmarshal_json(
|
|
538
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
539
|
+
)
|
|
540
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
541
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
542
|
+
response_data = utils.unmarshal_json(
|
|
543
|
+
http_res.text, errors.InternalServerErrorData
|
|
544
|
+
)
|
|
545
|
+
raise errors.InternalServerError(data=response_data)
|
|
546
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
547
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
548
|
+
raise errors.APIError(
|
|
549
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
550
|
+
)
|
|
551
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
552
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
553
|
+
raise errors.APIError(
|
|
554
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
555
|
+
)
|
|
556
|
+
|
|
557
|
+
content_type = http_res.headers.get("Content-Type")
|
|
558
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
559
|
+
raise errors.APIError(
|
|
560
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
561
|
+
http_res.status_code,
|
|
562
|
+
http_res_text,
|
|
563
|
+
http_res,
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
def delete(
|
|
567
|
+
self,
|
|
568
|
+
*,
|
|
569
|
+
project_name: str,
|
|
570
|
+
collection_name: str,
|
|
571
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
572
|
+
server_url: Optional[str] = None,
|
|
573
|
+
timeout_ms: Optional[int] = None,
|
|
574
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
575
|
+
) -> models.DeleteCollectionResponse:
|
|
576
|
+
r"""Delete an existing collection.
|
|
577
|
+
|
|
578
|
+
:param project_name: Project name.
|
|
579
|
+
:param collection_name: Collection name.
|
|
580
|
+
:param retries: Override the default retry configuration for this method
|
|
581
|
+
:param server_url: Override the default server URL for this method
|
|
582
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
583
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
584
|
+
"""
|
|
585
|
+
base_url = None
|
|
586
|
+
url_variables = None
|
|
587
|
+
if timeout_ms is None:
|
|
588
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
589
|
+
|
|
590
|
+
if server_url is not None:
|
|
591
|
+
base_url = server_url
|
|
592
|
+
else:
|
|
593
|
+
base_url = self._get_url(base_url, url_variables)
|
|
594
|
+
|
|
595
|
+
request = models.DeleteCollectionRequest(
|
|
596
|
+
project_name=project_name,
|
|
597
|
+
collection_name=collection_name,
|
|
598
|
+
)
|
|
599
|
+
|
|
600
|
+
req = self._build_request(
|
|
601
|
+
method="DELETE",
|
|
602
|
+
path="/projects/{projectName}/collections/{collectionName}",
|
|
603
|
+
base_url=base_url,
|
|
604
|
+
url_variables=url_variables,
|
|
605
|
+
request=request,
|
|
606
|
+
request_body_required=False,
|
|
607
|
+
request_has_path_params=True,
|
|
608
|
+
request_has_query_params=True,
|
|
609
|
+
user_agent_header="user-agent",
|
|
610
|
+
accept_header_value="application/json",
|
|
611
|
+
http_headers=http_headers,
|
|
612
|
+
security=self.sdk_configuration.security,
|
|
613
|
+
timeout_ms=timeout_ms,
|
|
614
|
+
)
|
|
615
|
+
|
|
616
|
+
if retries == UNSET:
|
|
617
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
618
|
+
retries = self.sdk_configuration.retry_config
|
|
619
|
+
else:
|
|
620
|
+
retries = utils.RetryConfig(
|
|
621
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
622
|
+
)
|
|
623
|
+
|
|
624
|
+
retry_config = None
|
|
625
|
+
if isinstance(retries, utils.RetryConfig):
|
|
626
|
+
retry_config = (retries, ["429", "5XX"])
|
|
627
|
+
|
|
628
|
+
http_res = self.do_request(
|
|
629
|
+
hook_ctx=HookContext(
|
|
630
|
+
base_url=base_url or "",
|
|
631
|
+
operation_id="deleteCollection",
|
|
632
|
+
oauth2_scopes=[],
|
|
633
|
+
security_source=get_security_from_env(
|
|
634
|
+
self.sdk_configuration.security, models.Security
|
|
635
|
+
),
|
|
636
|
+
),
|
|
637
|
+
request=req,
|
|
638
|
+
error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
|
|
639
|
+
retry_config=retry_config,
|
|
640
|
+
)
|
|
641
|
+
|
|
642
|
+
response_data: Any = None
|
|
643
|
+
if utils.match_response(http_res, "202", "application/json"):
|
|
644
|
+
return utils.unmarshal_json(http_res.text, models.DeleteCollectionResponse)
|
|
645
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
646
|
+
response_data = utils.unmarshal_json(
|
|
647
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
648
|
+
)
|
|
649
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
650
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
651
|
+
response_data = utils.unmarshal_json(
|
|
652
|
+
http_res.text, errors.ResourceNotFoundErrorData
|
|
653
|
+
)
|
|
654
|
+
raise errors.ResourceNotFoundError(data=response_data)
|
|
655
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
656
|
+
response_data = utils.unmarshal_json(
|
|
657
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
658
|
+
)
|
|
659
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
660
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
661
|
+
response_data = utils.unmarshal_json(
|
|
662
|
+
http_res.text, errors.InternalServerErrorData
|
|
663
|
+
)
|
|
664
|
+
raise errors.InternalServerError(data=response_data)
|
|
665
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
666
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
667
|
+
raise errors.APIError(
|
|
668
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
669
|
+
)
|
|
670
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
671
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
672
|
+
raise errors.APIError(
|
|
673
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
674
|
+
)
|
|
675
|
+
|
|
676
|
+
content_type = http_res.headers.get("Content-Type")
|
|
677
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
678
|
+
raise errors.APIError(
|
|
679
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
680
|
+
http_res.status_code,
|
|
681
|
+
http_res_text,
|
|
682
|
+
http_res,
|
|
683
|
+
)
|
|
684
|
+
|
|
685
|
+
async def delete_async(
|
|
686
|
+
self,
|
|
687
|
+
*,
|
|
688
|
+
project_name: str,
|
|
689
|
+
collection_name: str,
|
|
690
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
691
|
+
server_url: Optional[str] = None,
|
|
692
|
+
timeout_ms: Optional[int] = None,
|
|
693
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
694
|
+
) -> models.DeleteCollectionResponse:
|
|
695
|
+
r"""Delete an existing collection.
|
|
696
|
+
|
|
697
|
+
:param project_name: Project name.
|
|
698
|
+
:param collection_name: Collection name.
|
|
699
|
+
:param retries: Override the default retry configuration for this method
|
|
700
|
+
:param server_url: Override the default server URL for this method
|
|
701
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
702
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
703
|
+
"""
|
|
704
|
+
base_url = None
|
|
705
|
+
url_variables = None
|
|
706
|
+
if timeout_ms is None:
|
|
707
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
708
|
+
|
|
709
|
+
if server_url is not None:
|
|
710
|
+
base_url = server_url
|
|
711
|
+
else:
|
|
712
|
+
base_url = self._get_url(base_url, url_variables)
|
|
713
|
+
|
|
714
|
+
request = models.DeleteCollectionRequest(
|
|
715
|
+
project_name=project_name,
|
|
716
|
+
collection_name=collection_name,
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
req = self._build_request_async(
|
|
720
|
+
method="DELETE",
|
|
721
|
+
path="/projects/{projectName}/collections/{collectionName}",
|
|
722
|
+
base_url=base_url,
|
|
723
|
+
url_variables=url_variables,
|
|
724
|
+
request=request,
|
|
725
|
+
request_body_required=False,
|
|
726
|
+
request_has_path_params=True,
|
|
727
|
+
request_has_query_params=True,
|
|
728
|
+
user_agent_header="user-agent",
|
|
729
|
+
accept_header_value="application/json",
|
|
730
|
+
http_headers=http_headers,
|
|
731
|
+
security=self.sdk_configuration.security,
|
|
732
|
+
timeout_ms=timeout_ms,
|
|
733
|
+
)
|
|
734
|
+
|
|
735
|
+
if retries == UNSET:
|
|
736
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
737
|
+
retries = self.sdk_configuration.retry_config
|
|
738
|
+
else:
|
|
739
|
+
retries = utils.RetryConfig(
|
|
740
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
741
|
+
)
|
|
742
|
+
|
|
743
|
+
retry_config = None
|
|
744
|
+
if isinstance(retries, utils.RetryConfig):
|
|
745
|
+
retry_config = (retries, ["429", "5XX"])
|
|
746
|
+
|
|
747
|
+
http_res = await self.do_request_async(
|
|
748
|
+
hook_ctx=HookContext(
|
|
749
|
+
base_url=base_url or "",
|
|
750
|
+
operation_id="deleteCollection",
|
|
751
|
+
oauth2_scopes=[],
|
|
752
|
+
security_source=get_security_from_env(
|
|
753
|
+
self.sdk_configuration.security, models.Security
|
|
754
|
+
),
|
|
755
|
+
),
|
|
756
|
+
request=req,
|
|
757
|
+
error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
|
|
758
|
+
retry_config=retry_config,
|
|
759
|
+
)
|
|
760
|
+
|
|
761
|
+
response_data: Any = None
|
|
762
|
+
if utils.match_response(http_res, "202", "application/json"):
|
|
763
|
+
return utils.unmarshal_json(http_res.text, models.DeleteCollectionResponse)
|
|
764
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
765
|
+
response_data = utils.unmarshal_json(
|
|
766
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
767
|
+
)
|
|
768
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
769
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
770
|
+
response_data = utils.unmarshal_json(
|
|
771
|
+
http_res.text, errors.ResourceNotFoundErrorData
|
|
772
|
+
)
|
|
773
|
+
raise errors.ResourceNotFoundError(data=response_data)
|
|
774
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
775
|
+
response_data = utils.unmarshal_json(
|
|
776
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
777
|
+
)
|
|
778
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
779
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
780
|
+
response_data = utils.unmarshal_json(
|
|
781
|
+
http_res.text, errors.InternalServerErrorData
|
|
782
|
+
)
|
|
783
|
+
raise errors.InternalServerError(data=response_data)
|
|
784
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
785
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
786
|
+
raise errors.APIError(
|
|
787
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
788
|
+
)
|
|
789
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
790
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
791
|
+
raise errors.APIError(
|
|
792
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
793
|
+
)
|
|
794
|
+
|
|
795
|
+
content_type = http_res.headers.get("Content-Type")
|
|
796
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
797
|
+
raise errors.APIError(
|
|
798
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
799
|
+
http_res.status_code,
|
|
800
|
+
http_res_text,
|
|
801
|
+
http_res,
|
|
802
|
+
)
|
|
803
|
+
|
|
804
|
+
def get(
|
|
805
|
+
self,
|
|
806
|
+
*,
|
|
807
|
+
project_name: str,
|
|
808
|
+
collection_name: str,
|
|
809
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
810
|
+
server_url: Optional[str] = None,
|
|
811
|
+
timeout_ms: Optional[int] = None,
|
|
812
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
813
|
+
) -> models.CollectionResponse:
|
|
814
|
+
r"""Get metadata of an existing collection.
|
|
815
|
+
|
|
816
|
+
:param project_name: Project name.
|
|
817
|
+
:param collection_name: Collection name.
|
|
818
|
+
:param retries: Override the default retry configuration for this method
|
|
819
|
+
:param server_url: Override the default server URL for this method
|
|
820
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
821
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
822
|
+
"""
|
|
823
|
+
base_url = None
|
|
824
|
+
url_variables = None
|
|
825
|
+
if timeout_ms is None:
|
|
826
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
827
|
+
|
|
828
|
+
if server_url is not None:
|
|
829
|
+
base_url = server_url
|
|
830
|
+
else:
|
|
831
|
+
base_url = self._get_url(base_url, url_variables)
|
|
832
|
+
|
|
833
|
+
request = models.GetCollectionRequest(
|
|
834
|
+
project_name=project_name,
|
|
835
|
+
collection_name=collection_name,
|
|
836
|
+
)
|
|
837
|
+
|
|
838
|
+
req = self._build_request(
|
|
839
|
+
method="GET",
|
|
840
|
+
path="/projects/{projectName}/collections/{collectionName}",
|
|
841
|
+
base_url=base_url,
|
|
842
|
+
url_variables=url_variables,
|
|
843
|
+
request=request,
|
|
844
|
+
request_body_required=False,
|
|
845
|
+
request_has_path_params=True,
|
|
846
|
+
request_has_query_params=True,
|
|
847
|
+
user_agent_header="user-agent",
|
|
848
|
+
accept_header_value="application/json",
|
|
849
|
+
http_headers=http_headers,
|
|
850
|
+
security=self.sdk_configuration.security,
|
|
851
|
+
timeout_ms=timeout_ms,
|
|
852
|
+
)
|
|
853
|
+
|
|
854
|
+
if retries == UNSET:
|
|
855
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
856
|
+
retries = self.sdk_configuration.retry_config
|
|
857
|
+
else:
|
|
858
|
+
retries = utils.RetryConfig(
|
|
859
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
860
|
+
)
|
|
861
|
+
|
|
862
|
+
retry_config = None
|
|
863
|
+
if isinstance(retries, utils.RetryConfig):
|
|
864
|
+
retry_config = (retries, ["429", "5XX"])
|
|
865
|
+
|
|
866
|
+
http_res = self.do_request(
|
|
867
|
+
hook_ctx=HookContext(
|
|
868
|
+
base_url=base_url or "",
|
|
869
|
+
operation_id="getCollection",
|
|
870
|
+
oauth2_scopes=[],
|
|
871
|
+
security_source=get_security_from_env(
|
|
872
|
+
self.sdk_configuration.security, models.Security
|
|
873
|
+
),
|
|
874
|
+
),
|
|
875
|
+
request=req,
|
|
876
|
+
error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
|
|
877
|
+
retry_config=retry_config,
|
|
878
|
+
)
|
|
879
|
+
|
|
880
|
+
response_data: Any = None
|
|
881
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
882
|
+
return utils.unmarshal_json(http_res.text, models.CollectionResponse)
|
|
883
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
884
|
+
response_data = utils.unmarshal_json(
|
|
885
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
886
|
+
)
|
|
887
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
888
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
889
|
+
response_data = utils.unmarshal_json(
|
|
890
|
+
http_res.text, errors.ResourceNotFoundErrorData
|
|
891
|
+
)
|
|
892
|
+
raise errors.ResourceNotFoundError(data=response_data)
|
|
893
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
894
|
+
response_data = utils.unmarshal_json(
|
|
895
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
896
|
+
)
|
|
897
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
898
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
899
|
+
response_data = utils.unmarshal_json(
|
|
900
|
+
http_res.text, errors.InternalServerErrorData
|
|
901
|
+
)
|
|
902
|
+
raise errors.InternalServerError(data=response_data)
|
|
903
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
904
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
905
|
+
raise errors.APIError(
|
|
906
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
907
|
+
)
|
|
908
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
909
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
910
|
+
raise errors.APIError(
|
|
911
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
912
|
+
)
|
|
913
|
+
|
|
914
|
+
content_type = http_res.headers.get("Content-Type")
|
|
915
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
916
|
+
raise errors.APIError(
|
|
917
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
918
|
+
http_res.status_code,
|
|
919
|
+
http_res_text,
|
|
920
|
+
http_res,
|
|
921
|
+
)
|
|
922
|
+
|
|
923
|
+
async def get_async(
|
|
924
|
+
self,
|
|
925
|
+
*,
|
|
926
|
+
project_name: str,
|
|
927
|
+
collection_name: str,
|
|
928
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
929
|
+
server_url: Optional[str] = None,
|
|
930
|
+
timeout_ms: Optional[int] = None,
|
|
931
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
932
|
+
) -> models.CollectionResponse:
|
|
933
|
+
r"""Get metadata of an existing collection.
|
|
934
|
+
|
|
935
|
+
:param project_name: Project name.
|
|
936
|
+
:param collection_name: Collection name.
|
|
937
|
+
:param retries: Override the default retry configuration for this method
|
|
938
|
+
:param server_url: Override the default server URL for this method
|
|
939
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
940
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
941
|
+
"""
|
|
942
|
+
base_url = None
|
|
943
|
+
url_variables = None
|
|
944
|
+
if timeout_ms is None:
|
|
945
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
946
|
+
|
|
947
|
+
if server_url is not None:
|
|
948
|
+
base_url = server_url
|
|
949
|
+
else:
|
|
950
|
+
base_url = self._get_url(base_url, url_variables)
|
|
951
|
+
|
|
952
|
+
request = models.GetCollectionRequest(
|
|
953
|
+
project_name=project_name,
|
|
954
|
+
collection_name=collection_name,
|
|
955
|
+
)
|
|
956
|
+
|
|
957
|
+
req = self._build_request_async(
|
|
958
|
+
method="GET",
|
|
959
|
+
path="/projects/{projectName}/collections/{collectionName}",
|
|
960
|
+
base_url=base_url,
|
|
961
|
+
url_variables=url_variables,
|
|
962
|
+
request=request,
|
|
963
|
+
request_body_required=False,
|
|
964
|
+
request_has_path_params=True,
|
|
965
|
+
request_has_query_params=True,
|
|
966
|
+
user_agent_header="user-agent",
|
|
967
|
+
accept_header_value="application/json",
|
|
968
|
+
http_headers=http_headers,
|
|
969
|
+
security=self.sdk_configuration.security,
|
|
970
|
+
timeout_ms=timeout_ms,
|
|
971
|
+
)
|
|
972
|
+
|
|
973
|
+
if retries == UNSET:
|
|
974
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
975
|
+
retries = self.sdk_configuration.retry_config
|
|
976
|
+
else:
|
|
977
|
+
retries = utils.RetryConfig(
|
|
978
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
979
|
+
)
|
|
980
|
+
|
|
981
|
+
retry_config = None
|
|
982
|
+
if isinstance(retries, utils.RetryConfig):
|
|
983
|
+
retry_config = (retries, ["429", "5XX"])
|
|
984
|
+
|
|
985
|
+
http_res = await self.do_request_async(
|
|
986
|
+
hook_ctx=HookContext(
|
|
987
|
+
base_url=base_url or "",
|
|
988
|
+
operation_id="getCollection",
|
|
989
|
+
oauth2_scopes=[],
|
|
990
|
+
security_source=get_security_from_env(
|
|
991
|
+
self.sdk_configuration.security, models.Security
|
|
992
|
+
),
|
|
993
|
+
),
|
|
994
|
+
request=req,
|
|
995
|
+
error_status_codes=["401", "404", "429", "4XX", "500", "5XX"],
|
|
996
|
+
retry_config=retry_config,
|
|
997
|
+
)
|
|
998
|
+
|
|
999
|
+
response_data: Any = None
|
|
1000
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
1001
|
+
return utils.unmarshal_json(http_res.text, models.CollectionResponse)
|
|
1002
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
1003
|
+
response_data = utils.unmarshal_json(
|
|
1004
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
1005
|
+
)
|
|
1006
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
1007
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
1008
|
+
response_data = utils.unmarshal_json(
|
|
1009
|
+
http_res.text, errors.ResourceNotFoundErrorData
|
|
1010
|
+
)
|
|
1011
|
+
raise errors.ResourceNotFoundError(data=response_data)
|
|
1012
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
1013
|
+
response_data = utils.unmarshal_json(
|
|
1014
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
1015
|
+
)
|
|
1016
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
1017
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
1018
|
+
response_data = utils.unmarshal_json(
|
|
1019
|
+
http_res.text, errors.InternalServerErrorData
|
|
1020
|
+
)
|
|
1021
|
+
raise errors.InternalServerError(data=response_data)
|
|
1022
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
1023
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1024
|
+
raise errors.APIError(
|
|
1025
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1026
|
+
)
|
|
1027
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
1028
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1029
|
+
raise errors.APIError(
|
|
1030
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1031
|
+
)
|
|
1032
|
+
|
|
1033
|
+
content_type = http_res.headers.get("Content-Type")
|
|
1034
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1035
|
+
raise errors.APIError(
|
|
1036
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
1037
|
+
http_res.status_code,
|
|
1038
|
+
http_res_text,
|
|
1039
|
+
http_res,
|
|
1040
|
+
)
|
|
1041
|
+
|
|
1042
|
+
def update(
|
|
1043
|
+
self,
|
|
1044
|
+
*,
|
|
1045
|
+
project_name: str,
|
|
1046
|
+
collection_name: str,
|
|
1047
|
+
index_configs: Union[
|
|
1048
|
+
Dict[str, models.IndexConfigsUnion],
|
|
1049
|
+
Dict[str, models.IndexConfigsUnionTypedDict],
|
|
1050
|
+
],
|
|
1051
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
1052
|
+
server_url: Optional[str] = None,
|
|
1053
|
+
timeout_ms: Optional[int] = None,
|
|
1054
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
1055
|
+
) -> models.CollectionResponse:
|
|
1056
|
+
r"""Configure an collection.
|
|
1057
|
+
|
|
1058
|
+
:param project_name: Project name.
|
|
1059
|
+
:param collection_name: Collection name.
|
|
1060
|
+
:param index_configs:
|
|
1061
|
+
:param retries: Override the default retry configuration for this method
|
|
1062
|
+
:param server_url: Override the default server URL for this method
|
|
1063
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
1064
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
1065
|
+
"""
|
|
1066
|
+
base_url = None
|
|
1067
|
+
url_variables = None
|
|
1068
|
+
if timeout_ms is None:
|
|
1069
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
1070
|
+
|
|
1071
|
+
if server_url is not None:
|
|
1072
|
+
base_url = server_url
|
|
1073
|
+
else:
|
|
1074
|
+
base_url = self._get_url(base_url, url_variables)
|
|
1075
|
+
|
|
1076
|
+
request = models.UpdateCollectionRequest(
|
|
1077
|
+
project_name=project_name,
|
|
1078
|
+
collection_name=collection_name,
|
|
1079
|
+
request_body=models.UpdateCollectionRequestBody(
|
|
1080
|
+
index_configs=utils.get_pydantic_model(
|
|
1081
|
+
index_configs, Dict[str, models.IndexConfigsUnion]
|
|
1082
|
+
),
|
|
1083
|
+
),
|
|
1084
|
+
)
|
|
1085
|
+
|
|
1086
|
+
req = self._build_request(
|
|
1087
|
+
method="PATCH",
|
|
1088
|
+
path="/projects/{projectName}/collections/{collectionName}",
|
|
1089
|
+
base_url=base_url,
|
|
1090
|
+
url_variables=url_variables,
|
|
1091
|
+
request=request,
|
|
1092
|
+
request_body_required=True,
|
|
1093
|
+
request_has_path_params=True,
|
|
1094
|
+
request_has_query_params=True,
|
|
1095
|
+
user_agent_header="user-agent",
|
|
1096
|
+
accept_header_value="application/json",
|
|
1097
|
+
http_headers=http_headers,
|
|
1098
|
+
security=self.sdk_configuration.security,
|
|
1099
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
1100
|
+
request.request_body,
|
|
1101
|
+
False,
|
|
1102
|
+
False,
|
|
1103
|
+
"json",
|
|
1104
|
+
models.UpdateCollectionRequestBody,
|
|
1105
|
+
),
|
|
1106
|
+
timeout_ms=timeout_ms,
|
|
1107
|
+
)
|
|
1108
|
+
|
|
1109
|
+
if retries == UNSET:
|
|
1110
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
1111
|
+
retries = self.sdk_configuration.retry_config
|
|
1112
|
+
else:
|
|
1113
|
+
retries = utils.RetryConfig(
|
|
1114
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
1115
|
+
)
|
|
1116
|
+
|
|
1117
|
+
retry_config = None
|
|
1118
|
+
if isinstance(retries, utils.RetryConfig):
|
|
1119
|
+
retry_config = (retries, ["429", "5XX"])
|
|
1120
|
+
|
|
1121
|
+
http_res = self.do_request(
|
|
1122
|
+
hook_ctx=HookContext(
|
|
1123
|
+
base_url=base_url or "",
|
|
1124
|
+
operation_id="updateCollection",
|
|
1125
|
+
oauth2_scopes=[],
|
|
1126
|
+
security_source=get_security_from_env(
|
|
1127
|
+
self.sdk_configuration.security, models.Security
|
|
1128
|
+
),
|
|
1129
|
+
),
|
|
1130
|
+
request=req,
|
|
1131
|
+
error_status_codes=["400", "401", "404", "429", "4XX", "500", "5XX"],
|
|
1132
|
+
retry_config=retry_config,
|
|
1133
|
+
)
|
|
1134
|
+
|
|
1135
|
+
response_data: Any = None
|
|
1136
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
1137
|
+
return utils.unmarshal_json(http_res.text, models.CollectionResponse)
|
|
1138
|
+
if utils.match_response(http_res, "400", "application/json"):
|
|
1139
|
+
response_data = utils.unmarshal_json(
|
|
1140
|
+
http_res.text, errors.BadRequestErrorData
|
|
1141
|
+
)
|
|
1142
|
+
raise errors.BadRequestError(data=response_data)
|
|
1143
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
1144
|
+
response_data = utils.unmarshal_json(
|
|
1145
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
1146
|
+
)
|
|
1147
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
1148
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
1149
|
+
response_data = utils.unmarshal_json(
|
|
1150
|
+
http_res.text, errors.ResourceNotFoundErrorData
|
|
1151
|
+
)
|
|
1152
|
+
raise errors.ResourceNotFoundError(data=response_data)
|
|
1153
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
1154
|
+
response_data = utils.unmarshal_json(
|
|
1155
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
1156
|
+
)
|
|
1157
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
1158
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
1159
|
+
response_data = utils.unmarshal_json(
|
|
1160
|
+
http_res.text, errors.InternalServerErrorData
|
|
1161
|
+
)
|
|
1162
|
+
raise errors.InternalServerError(data=response_data)
|
|
1163
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
1164
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
1165
|
+
raise errors.APIError(
|
|
1166
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1167
|
+
)
|
|
1168
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
1169
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
1170
|
+
raise errors.APIError(
|
|
1171
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1172
|
+
)
|
|
1173
|
+
|
|
1174
|
+
content_type = http_res.headers.get("Content-Type")
|
|
1175
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
1176
|
+
raise errors.APIError(
|
|
1177
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
1178
|
+
http_res.status_code,
|
|
1179
|
+
http_res_text,
|
|
1180
|
+
http_res,
|
|
1181
|
+
)
|
|
1182
|
+
|
|
1183
|
+
async def update_async(
|
|
1184
|
+
self,
|
|
1185
|
+
*,
|
|
1186
|
+
project_name: str,
|
|
1187
|
+
collection_name: str,
|
|
1188
|
+
index_configs: Union[
|
|
1189
|
+
Dict[str, models.IndexConfigsUnion],
|
|
1190
|
+
Dict[str, models.IndexConfigsUnionTypedDict],
|
|
1191
|
+
],
|
|
1192
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
1193
|
+
server_url: Optional[str] = None,
|
|
1194
|
+
timeout_ms: Optional[int] = None,
|
|
1195
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
1196
|
+
) -> models.CollectionResponse:
|
|
1197
|
+
r"""Configure an collection.
|
|
1198
|
+
|
|
1199
|
+
:param project_name: Project name.
|
|
1200
|
+
:param collection_name: Collection name.
|
|
1201
|
+
:param index_configs:
|
|
1202
|
+
:param retries: Override the default retry configuration for this method
|
|
1203
|
+
:param server_url: Override the default server URL for this method
|
|
1204
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
1205
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
1206
|
+
"""
|
|
1207
|
+
base_url = None
|
|
1208
|
+
url_variables = None
|
|
1209
|
+
if timeout_ms is None:
|
|
1210
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
1211
|
+
|
|
1212
|
+
if server_url is not None:
|
|
1213
|
+
base_url = server_url
|
|
1214
|
+
else:
|
|
1215
|
+
base_url = self._get_url(base_url, url_variables)
|
|
1216
|
+
|
|
1217
|
+
request = models.UpdateCollectionRequest(
|
|
1218
|
+
project_name=project_name,
|
|
1219
|
+
collection_name=collection_name,
|
|
1220
|
+
request_body=models.UpdateCollectionRequestBody(
|
|
1221
|
+
index_configs=utils.get_pydantic_model(
|
|
1222
|
+
index_configs, Dict[str, models.IndexConfigsUnion]
|
|
1223
|
+
),
|
|
1224
|
+
),
|
|
1225
|
+
)
|
|
1226
|
+
|
|
1227
|
+
req = self._build_request_async(
|
|
1228
|
+
method="PATCH",
|
|
1229
|
+
path="/projects/{projectName}/collections/{collectionName}",
|
|
1230
|
+
base_url=base_url,
|
|
1231
|
+
url_variables=url_variables,
|
|
1232
|
+
request=request,
|
|
1233
|
+
request_body_required=True,
|
|
1234
|
+
request_has_path_params=True,
|
|
1235
|
+
request_has_query_params=True,
|
|
1236
|
+
user_agent_header="user-agent",
|
|
1237
|
+
accept_header_value="application/json",
|
|
1238
|
+
http_headers=http_headers,
|
|
1239
|
+
security=self.sdk_configuration.security,
|
|
1240
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
1241
|
+
request.request_body,
|
|
1242
|
+
False,
|
|
1243
|
+
False,
|
|
1244
|
+
"json",
|
|
1245
|
+
models.UpdateCollectionRequestBody,
|
|
1246
|
+
),
|
|
1247
|
+
timeout_ms=timeout_ms,
|
|
1248
|
+
)
|
|
1249
|
+
|
|
1250
|
+
if retries == UNSET:
|
|
1251
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
1252
|
+
retries = self.sdk_configuration.retry_config
|
|
1253
|
+
else:
|
|
1254
|
+
retries = utils.RetryConfig(
|
|
1255
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
1256
|
+
)
|
|
1257
|
+
|
|
1258
|
+
retry_config = None
|
|
1259
|
+
if isinstance(retries, utils.RetryConfig):
|
|
1260
|
+
retry_config = (retries, ["429", "5XX"])
|
|
1261
|
+
|
|
1262
|
+
http_res = await self.do_request_async(
|
|
1263
|
+
hook_ctx=HookContext(
|
|
1264
|
+
base_url=base_url or "",
|
|
1265
|
+
operation_id="updateCollection",
|
|
1266
|
+
oauth2_scopes=[],
|
|
1267
|
+
security_source=get_security_from_env(
|
|
1268
|
+
self.sdk_configuration.security, models.Security
|
|
1269
|
+
),
|
|
1270
|
+
),
|
|
1271
|
+
request=req,
|
|
1272
|
+
error_status_codes=["400", "401", "404", "429", "4XX", "500", "5XX"],
|
|
1273
|
+
retry_config=retry_config,
|
|
1274
|
+
)
|
|
1275
|
+
|
|
1276
|
+
response_data: Any = None
|
|
1277
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
1278
|
+
return utils.unmarshal_json(http_res.text, models.CollectionResponse)
|
|
1279
|
+
if utils.match_response(http_res, "400", "application/json"):
|
|
1280
|
+
response_data = utils.unmarshal_json(
|
|
1281
|
+
http_res.text, errors.BadRequestErrorData
|
|
1282
|
+
)
|
|
1283
|
+
raise errors.BadRequestError(data=response_data)
|
|
1284
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
1285
|
+
response_data = utils.unmarshal_json(
|
|
1286
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
1287
|
+
)
|
|
1288
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
1289
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
1290
|
+
response_data = utils.unmarshal_json(
|
|
1291
|
+
http_res.text, errors.ResourceNotFoundErrorData
|
|
1292
|
+
)
|
|
1293
|
+
raise errors.ResourceNotFoundError(data=response_data)
|
|
1294
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
1295
|
+
response_data = utils.unmarshal_json(
|
|
1296
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
1297
|
+
)
|
|
1298
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
1299
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
1300
|
+
response_data = utils.unmarshal_json(
|
|
1301
|
+
http_res.text, errors.InternalServerErrorData
|
|
1302
|
+
)
|
|
1303
|
+
raise errors.InternalServerError(data=response_data)
|
|
1304
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
1305
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1306
|
+
raise errors.APIError(
|
|
1307
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1308
|
+
)
|
|
1309
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
1310
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1311
|
+
raise errors.APIError(
|
|
1312
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1313
|
+
)
|
|
1314
|
+
|
|
1315
|
+
content_type = http_res.headers.get("Content-Type")
|
|
1316
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1317
|
+
raise errors.APIError(
|
|
1318
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
1319
|
+
http_res.status_code,
|
|
1320
|
+
http_res_text,
|
|
1321
|
+
http_res,
|
|
1322
|
+
)
|
|
1323
|
+
|
|
1324
|
+
def query(
|
|
1325
|
+
self,
|
|
1326
|
+
*,
|
|
1327
|
+
project_name: str,
|
|
1328
|
+
collection_name: str,
|
|
1329
|
+
size: int,
|
|
1330
|
+
query: Optional[Union[models.Query, models.QueryTypedDict]] = None,
|
|
1331
|
+
consistent_read: Optional[bool] = False,
|
|
1332
|
+
include_vectors: Optional[bool] = False,
|
|
1333
|
+
sort: Optional[Union[List[models.Sort], List[models.SortTypedDict]]] = None,
|
|
1334
|
+
fields: Optional[List[str]] = None,
|
|
1335
|
+
track_scores: Optional[bool] = False,
|
|
1336
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
1337
|
+
server_url: Optional[str] = None,
|
|
1338
|
+
timeout_ms: Optional[int] = None,
|
|
1339
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
1340
|
+
) -> models.QueryCollectionResponse:
|
|
1341
|
+
r"""Search an collection with a query and return the most similar documents.
|
|
1342
|
+
|
|
1343
|
+
:param project_name: Project name.
|
|
1344
|
+
:param collection_name: Collection name.
|
|
1345
|
+
:param size: Number of documents to return. Note that the maximum number of documents is 1000.
|
|
1346
|
+
:param query: Query object.
|
|
1347
|
+
:param consistent_read: If your application requires a strongly consistent read, set consistentRead to true. Although a strongly consistent read might take more time than an eventually consistent read, it always returns the last updated value.
|
|
1348
|
+
:param include_vectors: If your application need to include vector values in the response, set includeVectors to true.
|
|
1349
|
+
:param sort: List of field name, sort direction pairs.
|
|
1350
|
+
:param fields: List of field name to include in results
|
|
1351
|
+
:param track_scores: If your application needs to track scores with sorting, set trackScores to true.
|
|
1352
|
+
:param retries: Override the default retry configuration for this method
|
|
1353
|
+
:param server_url: Override the default server URL for this method
|
|
1354
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
1355
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
1356
|
+
"""
|
|
1357
|
+
base_url = None
|
|
1358
|
+
url_variables = None
|
|
1359
|
+
if timeout_ms is None:
|
|
1360
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
1361
|
+
|
|
1362
|
+
if server_url is not None:
|
|
1363
|
+
base_url = server_url
|
|
1364
|
+
else:
|
|
1365
|
+
base_url = self._get_url(base_url, url_variables)
|
|
1366
|
+
|
|
1367
|
+
request = models.QueryCollectionRequest(
|
|
1368
|
+
project_name=project_name,
|
|
1369
|
+
collection_name=collection_name,
|
|
1370
|
+
request_body=models.QueryCollectionRequestBody(
|
|
1371
|
+
size=size,
|
|
1372
|
+
query=utils.get_pydantic_model(query, Optional[models.Query]),
|
|
1373
|
+
consistent_read=consistent_read,
|
|
1374
|
+
include_vectors=include_vectors,
|
|
1375
|
+
sort=utils.get_pydantic_model(sort, Optional[List[models.Sort]]),
|
|
1376
|
+
fields=fields,
|
|
1377
|
+
track_scores=track_scores,
|
|
1378
|
+
),
|
|
1379
|
+
)
|
|
1380
|
+
|
|
1381
|
+
req = self._build_request(
|
|
1382
|
+
method="POST",
|
|
1383
|
+
path="/projects/{projectName}/collections/{collectionName}/query",
|
|
1384
|
+
base_url=base_url,
|
|
1385
|
+
url_variables=url_variables,
|
|
1386
|
+
request=request,
|
|
1387
|
+
request_body_required=True,
|
|
1388
|
+
request_has_path_params=True,
|
|
1389
|
+
request_has_query_params=True,
|
|
1390
|
+
user_agent_header="user-agent",
|
|
1391
|
+
accept_header_value="application/json",
|
|
1392
|
+
http_headers=http_headers,
|
|
1393
|
+
security=self.sdk_configuration.security,
|
|
1394
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
1395
|
+
request.request_body,
|
|
1396
|
+
False,
|
|
1397
|
+
False,
|
|
1398
|
+
"json",
|
|
1399
|
+
models.QueryCollectionRequestBody,
|
|
1400
|
+
),
|
|
1401
|
+
timeout_ms=timeout_ms,
|
|
1402
|
+
)
|
|
1403
|
+
|
|
1404
|
+
if retries == UNSET:
|
|
1405
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
1406
|
+
retries = self.sdk_configuration.retry_config
|
|
1407
|
+
else:
|
|
1408
|
+
retries = utils.RetryConfig(
|
|
1409
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
1410
|
+
)
|
|
1411
|
+
|
|
1412
|
+
retry_config = None
|
|
1413
|
+
if isinstance(retries, utils.RetryConfig):
|
|
1414
|
+
retry_config = (retries, ["429", "5XX"])
|
|
1415
|
+
|
|
1416
|
+
http_res = self.do_request(
|
|
1417
|
+
hook_ctx=HookContext(
|
|
1418
|
+
base_url=base_url or "",
|
|
1419
|
+
operation_id="queryCollection",
|
|
1420
|
+
oauth2_scopes=[],
|
|
1421
|
+
security_source=get_security_from_env(
|
|
1422
|
+
self.sdk_configuration.security, models.Security
|
|
1423
|
+
),
|
|
1424
|
+
),
|
|
1425
|
+
request=req,
|
|
1426
|
+
error_status_codes=["400", "401", "404", "429", "4XX", "500", "5XX"],
|
|
1427
|
+
retry_config=retry_config,
|
|
1428
|
+
)
|
|
1429
|
+
|
|
1430
|
+
response_data: Any = None
|
|
1431
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
1432
|
+
return utils.unmarshal_json(http_res.text, models.QueryCollectionResponse)
|
|
1433
|
+
if utils.match_response(http_res, "400", "application/json"):
|
|
1434
|
+
response_data = utils.unmarshal_json(
|
|
1435
|
+
http_res.text, errors.BadRequestErrorData
|
|
1436
|
+
)
|
|
1437
|
+
raise errors.BadRequestError(data=response_data)
|
|
1438
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
1439
|
+
response_data = utils.unmarshal_json(
|
|
1440
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
1441
|
+
)
|
|
1442
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
1443
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
1444
|
+
response_data = utils.unmarshal_json(
|
|
1445
|
+
http_res.text, errors.ResourceNotFoundErrorData
|
|
1446
|
+
)
|
|
1447
|
+
raise errors.ResourceNotFoundError(data=response_data)
|
|
1448
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
1449
|
+
response_data = utils.unmarshal_json(
|
|
1450
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
1451
|
+
)
|
|
1452
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
1453
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
1454
|
+
response_data = utils.unmarshal_json(
|
|
1455
|
+
http_res.text, errors.InternalServerErrorData
|
|
1456
|
+
)
|
|
1457
|
+
raise errors.InternalServerError(data=response_data)
|
|
1458
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
1459
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
1460
|
+
raise errors.APIError(
|
|
1461
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1462
|
+
)
|
|
1463
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
1464
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
1465
|
+
raise errors.APIError(
|
|
1466
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1467
|
+
)
|
|
1468
|
+
|
|
1469
|
+
content_type = http_res.headers.get("Content-Type")
|
|
1470
|
+
http_res_text = utils.stream_to_text(http_res)
|
|
1471
|
+
raise errors.APIError(
|
|
1472
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
1473
|
+
http_res.status_code,
|
|
1474
|
+
http_res_text,
|
|
1475
|
+
http_res,
|
|
1476
|
+
)
|
|
1477
|
+
|
|
1478
|
+
async def query_async(
|
|
1479
|
+
self,
|
|
1480
|
+
*,
|
|
1481
|
+
project_name: str,
|
|
1482
|
+
collection_name: str,
|
|
1483
|
+
size: int,
|
|
1484
|
+
query: Optional[Union[models.Query, models.QueryTypedDict]] = None,
|
|
1485
|
+
consistent_read: Optional[bool] = False,
|
|
1486
|
+
include_vectors: Optional[bool] = False,
|
|
1487
|
+
sort: Optional[Union[List[models.Sort], List[models.SortTypedDict]]] = None,
|
|
1488
|
+
fields: Optional[List[str]] = None,
|
|
1489
|
+
track_scores: Optional[bool] = False,
|
|
1490
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
1491
|
+
server_url: Optional[str] = None,
|
|
1492
|
+
timeout_ms: Optional[int] = None,
|
|
1493
|
+
http_headers: Optional[Mapping[str, str]] = None,
|
|
1494
|
+
) -> models.QueryCollectionResponse:
|
|
1495
|
+
r"""Search an collection with a query and return the most similar documents.
|
|
1496
|
+
|
|
1497
|
+
:param project_name: Project name.
|
|
1498
|
+
:param collection_name: Collection name.
|
|
1499
|
+
:param size: Number of documents to return. Note that the maximum number of documents is 1000.
|
|
1500
|
+
:param query: Query object.
|
|
1501
|
+
:param consistent_read: If your application requires a strongly consistent read, set consistentRead to true. Although a strongly consistent read might take more time than an eventually consistent read, it always returns the last updated value.
|
|
1502
|
+
:param include_vectors: If your application need to include vector values in the response, set includeVectors to true.
|
|
1503
|
+
:param sort: List of field name, sort direction pairs.
|
|
1504
|
+
:param fields: List of field name to include in results
|
|
1505
|
+
:param track_scores: If your application needs to track scores with sorting, set trackScores to true.
|
|
1506
|
+
:param retries: Override the default retry configuration for this method
|
|
1507
|
+
:param server_url: Override the default server URL for this method
|
|
1508
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
1509
|
+
:param http_headers: Additional headers to set or replace on requests.
|
|
1510
|
+
"""
|
|
1511
|
+
base_url = None
|
|
1512
|
+
url_variables = None
|
|
1513
|
+
if timeout_ms is None:
|
|
1514
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
1515
|
+
|
|
1516
|
+
if server_url is not None:
|
|
1517
|
+
base_url = server_url
|
|
1518
|
+
else:
|
|
1519
|
+
base_url = self._get_url(base_url, url_variables)
|
|
1520
|
+
|
|
1521
|
+
request = models.QueryCollectionRequest(
|
|
1522
|
+
project_name=project_name,
|
|
1523
|
+
collection_name=collection_name,
|
|
1524
|
+
request_body=models.QueryCollectionRequestBody(
|
|
1525
|
+
size=size,
|
|
1526
|
+
query=utils.get_pydantic_model(query, Optional[models.Query]),
|
|
1527
|
+
consistent_read=consistent_read,
|
|
1528
|
+
include_vectors=include_vectors,
|
|
1529
|
+
sort=utils.get_pydantic_model(sort, Optional[List[models.Sort]]),
|
|
1530
|
+
fields=fields,
|
|
1531
|
+
track_scores=track_scores,
|
|
1532
|
+
),
|
|
1533
|
+
)
|
|
1534
|
+
|
|
1535
|
+
req = self._build_request_async(
|
|
1536
|
+
method="POST",
|
|
1537
|
+
path="/projects/{projectName}/collections/{collectionName}/query",
|
|
1538
|
+
base_url=base_url,
|
|
1539
|
+
url_variables=url_variables,
|
|
1540
|
+
request=request,
|
|
1541
|
+
request_body_required=True,
|
|
1542
|
+
request_has_path_params=True,
|
|
1543
|
+
request_has_query_params=True,
|
|
1544
|
+
user_agent_header="user-agent",
|
|
1545
|
+
accept_header_value="application/json",
|
|
1546
|
+
http_headers=http_headers,
|
|
1547
|
+
security=self.sdk_configuration.security,
|
|
1548
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
1549
|
+
request.request_body,
|
|
1550
|
+
False,
|
|
1551
|
+
False,
|
|
1552
|
+
"json",
|
|
1553
|
+
models.QueryCollectionRequestBody,
|
|
1554
|
+
),
|
|
1555
|
+
timeout_ms=timeout_ms,
|
|
1556
|
+
)
|
|
1557
|
+
|
|
1558
|
+
if retries == UNSET:
|
|
1559
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
1560
|
+
retries = self.sdk_configuration.retry_config
|
|
1561
|
+
else:
|
|
1562
|
+
retries = utils.RetryConfig(
|
|
1563
|
+
"backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True
|
|
1564
|
+
)
|
|
1565
|
+
|
|
1566
|
+
retry_config = None
|
|
1567
|
+
if isinstance(retries, utils.RetryConfig):
|
|
1568
|
+
retry_config = (retries, ["429", "5XX"])
|
|
1569
|
+
|
|
1570
|
+
http_res = await self.do_request_async(
|
|
1571
|
+
hook_ctx=HookContext(
|
|
1572
|
+
base_url=base_url or "",
|
|
1573
|
+
operation_id="queryCollection",
|
|
1574
|
+
oauth2_scopes=[],
|
|
1575
|
+
security_source=get_security_from_env(
|
|
1576
|
+
self.sdk_configuration.security, models.Security
|
|
1577
|
+
),
|
|
1578
|
+
),
|
|
1579
|
+
request=req,
|
|
1580
|
+
error_status_codes=["400", "401", "404", "429", "4XX", "500", "5XX"],
|
|
1581
|
+
retry_config=retry_config,
|
|
1582
|
+
)
|
|
1583
|
+
|
|
1584
|
+
response_data: Any = None
|
|
1585
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
1586
|
+
return utils.unmarshal_json(http_res.text, models.QueryCollectionResponse)
|
|
1587
|
+
if utils.match_response(http_res, "400", "application/json"):
|
|
1588
|
+
response_data = utils.unmarshal_json(
|
|
1589
|
+
http_res.text, errors.BadRequestErrorData
|
|
1590
|
+
)
|
|
1591
|
+
raise errors.BadRequestError(data=response_data)
|
|
1592
|
+
if utils.match_response(http_res, "401", "application/json"):
|
|
1593
|
+
response_data = utils.unmarshal_json(
|
|
1594
|
+
http_res.text, errors.UnauthenticatedErrorData
|
|
1595
|
+
)
|
|
1596
|
+
raise errors.UnauthenticatedError(data=response_data)
|
|
1597
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
1598
|
+
response_data = utils.unmarshal_json(
|
|
1599
|
+
http_res.text, errors.ResourceNotFoundErrorData
|
|
1600
|
+
)
|
|
1601
|
+
raise errors.ResourceNotFoundError(data=response_data)
|
|
1602
|
+
if utils.match_response(http_res, "429", "application/json"):
|
|
1603
|
+
response_data = utils.unmarshal_json(
|
|
1604
|
+
http_res.text, errors.TooManyRequestsErrorData
|
|
1605
|
+
)
|
|
1606
|
+
raise errors.TooManyRequestsError(data=response_data)
|
|
1607
|
+
if utils.match_response(http_res, "500", "application/json"):
|
|
1608
|
+
response_data = utils.unmarshal_json(
|
|
1609
|
+
http_res.text, errors.InternalServerErrorData
|
|
1610
|
+
)
|
|
1611
|
+
raise errors.InternalServerError(data=response_data)
|
|
1612
|
+
if utils.match_response(http_res, "4XX", "*"):
|
|
1613
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1614
|
+
raise errors.APIError(
|
|
1615
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1616
|
+
)
|
|
1617
|
+
if utils.match_response(http_res, "5XX", "*"):
|
|
1618
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1619
|
+
raise errors.APIError(
|
|
1620
|
+
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
1621
|
+
)
|
|
1622
|
+
|
|
1623
|
+
content_type = http_res.headers.get("Content-Type")
|
|
1624
|
+
http_res_text = await utils.stream_to_text_async(http_res)
|
|
1625
|
+
raise errors.APIError(
|
|
1626
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
1627
|
+
http_res.status_code,
|
|
1628
|
+
http_res_text,
|
|
1629
|
+
http_res,
|
|
1630
|
+
)
|