vikingdb-python-sdk 0.1.9__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.
- vikingdb/__init__.py +36 -0
- vikingdb/_client.py +262 -0
- vikingdb/auth.py +68 -0
- vikingdb/exceptions.py +160 -0
- vikingdb/memory/__init__.py +70 -0
- vikingdb/memory/client.py +302 -0
- vikingdb/memory/collection.py +1038 -0
- vikingdb/memory/exceptions.py +297 -0
- vikingdb/memory/types.py +18 -0
- vikingdb/request_options.py +33 -0
- vikingdb/vector/__init__.py +23 -0
- vikingdb/vector/base.py +51 -0
- vikingdb/vector/client.py +292 -0
- vikingdb/vector/collection.py +110 -0
- vikingdb/vector/embedding.py +33 -0
- vikingdb/vector/exceptions.py +40 -0
- vikingdb/vector/index.py +189 -0
- vikingdb/vector/models/__init__.py +106 -0
- vikingdb/vector/models/base.py +68 -0
- vikingdb/vector/models/collection.py +67 -0
- vikingdb/vector/models/embedding.py +50 -0
- vikingdb/vector/models/index.py +122 -0
- vikingdb/vector/models/rerank.py +35 -0
- vikingdb/vector/rerank.py +33 -0
- vikingdb/version.py +4 -0
- vikingdb_python_sdk-0.1.9.dist-info/METADATA +228 -0
- vikingdb_python_sdk-0.1.9.dist-info/RECORD +30 -0
- vikingdb_python_sdk-0.1.9.dist-info/WHEEL +5 -0
- vikingdb_python_sdk-0.1.9.dist-info/licenses/LICENSE.txt +202 -0
- vikingdb_python_sdk-0.1.9.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# coding:utf-8
|
|
2
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd.
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""Viking Memory SDK Exception Definitions"""
|
|
6
|
+
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
from ..exceptions import VikingException
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class VikingMemException(VikingException):
|
|
13
|
+
"""Viking Memory base exception class"""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
code: int,
|
|
18
|
+
request_id: str,
|
|
19
|
+
message: Optional[str] = None,
|
|
20
|
+
*,
|
|
21
|
+
status_code: Optional[int] = None,
|
|
22
|
+
):
|
|
23
|
+
if message is None:
|
|
24
|
+
message = f"unknown error, request_id: {request_id}"
|
|
25
|
+
super().__init__(
|
|
26
|
+
code,
|
|
27
|
+
request_id,
|
|
28
|
+
message,
|
|
29
|
+
status_code=status_code,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class UnauthorizedException(VikingMemException):
|
|
34
|
+
"""
|
|
35
|
+
User authentication failed exception (Error code: 1000001)
|
|
36
|
+
|
|
37
|
+
Triggered by:
|
|
38
|
+
- Incorrect AK/SK configuration
|
|
39
|
+
- Request body not signed
|
|
40
|
+
- Insufficient sub-account permissions
|
|
41
|
+
|
|
42
|
+
Resolution:
|
|
43
|
+
- Check if AK/SK input is correct
|
|
44
|
+
- Check if request body is signed and signature is added to request headers
|
|
45
|
+
- If sub-account lacks permissions, refer to documentation to request permissions
|
|
46
|
+
"""
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class InvalidRequestException(VikingMemException):
|
|
51
|
+
"""
|
|
52
|
+
Invalid request parameters exception (Error code: 1000003)
|
|
53
|
+
|
|
54
|
+
Triggered by:
|
|
55
|
+
- Incorrect request parameter format or incorrect usage
|
|
56
|
+
|
|
57
|
+
Resolution:
|
|
58
|
+
- Check request parameters based on error message
|
|
59
|
+
"""
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class CollectionExistException(VikingMemException):
|
|
64
|
+
"""
|
|
65
|
+
Collection already exists exception (Error code: 1000004)
|
|
66
|
+
|
|
67
|
+
Triggered by:
|
|
68
|
+
- Creating a collection with duplicate name
|
|
69
|
+
|
|
70
|
+
Resolution:
|
|
71
|
+
- Check if collection exists
|
|
72
|
+
"""
|
|
73
|
+
pass
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class CollectionNotExistException(VikingMemException):
|
|
77
|
+
"""
|
|
78
|
+
Collection does not exist exception (Error code: 1000005)
|
|
79
|
+
|
|
80
|
+
Triggered by:
|
|
81
|
+
- Collection name is incorrect or does not exist
|
|
82
|
+
|
|
83
|
+
Resolution:
|
|
84
|
+
- Check if collection exists
|
|
85
|
+
"""
|
|
86
|
+
pass
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class IndexExistException(VikingMemException):
|
|
90
|
+
"""
|
|
91
|
+
Index already exists exception (Error code: 1000007)
|
|
92
|
+
|
|
93
|
+
Triggered by:
|
|
94
|
+
- Creating an index with duplicate name under the same collection
|
|
95
|
+
|
|
96
|
+
Resolution:
|
|
97
|
+
- Check if index exists
|
|
98
|
+
"""
|
|
99
|
+
pass
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class IndexNotExistException(VikingMemException):
|
|
103
|
+
"""
|
|
104
|
+
Index does not exist exception (Error code: 1000008)
|
|
105
|
+
|
|
106
|
+
Triggered by:
|
|
107
|
+
- Index name is incorrect or does not exist
|
|
108
|
+
|
|
109
|
+
Resolution:
|
|
110
|
+
- Check if index exists
|
|
111
|
+
"""
|
|
112
|
+
pass
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class DataNotFoundException(VikingMemException):
|
|
116
|
+
"""
|
|
117
|
+
Data not found exception (Error code: 1000011)
|
|
118
|
+
|
|
119
|
+
Triggered by:
|
|
120
|
+
- Attempting to update_data on non-existent data
|
|
121
|
+
|
|
122
|
+
Resolution:
|
|
123
|
+
- Check if data exists
|
|
124
|
+
"""
|
|
125
|
+
pass
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class DelOpFailedException(VikingMemException):
|
|
129
|
+
"""
|
|
130
|
+
Delete operation failed exception (Error code: 1000013)
|
|
131
|
+
|
|
132
|
+
Triggered by:
|
|
133
|
+
- Delete operation fails, usually due to server issues
|
|
134
|
+
|
|
135
|
+
Resolution:
|
|
136
|
+
- Contact customer service promptly
|
|
137
|
+
"""
|
|
138
|
+
pass
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class UpsertOpFailedException(VikingMemException):
|
|
142
|
+
"""
|
|
143
|
+
Upsert operation failed exception (Error code: 1000014)
|
|
144
|
+
|
|
145
|
+
Triggered by:
|
|
146
|
+
- Upsert operation fails, usually due to server issues
|
|
147
|
+
|
|
148
|
+
Resolution:
|
|
149
|
+
- Contact customer service promptly
|
|
150
|
+
"""
|
|
151
|
+
pass
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class InvalidVectorException(VikingMemException):
|
|
155
|
+
"""
|
|
156
|
+
Invalid vector exception (Error code: 1000016)
|
|
157
|
+
|
|
158
|
+
Triggered by:
|
|
159
|
+
- Vector input issues, inconsistent dimensions or incorrect format
|
|
160
|
+
|
|
161
|
+
Resolution:
|
|
162
|
+
- Check the vector field in the search request
|
|
163
|
+
"""
|
|
164
|
+
pass
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class InvalidPrimaryKeyException(VikingMemException):
|
|
168
|
+
"""
|
|
169
|
+
Invalid primary key exception (Error code: 1000017)
|
|
170
|
+
|
|
171
|
+
Triggered by:
|
|
172
|
+
- Primary key type mismatch or incorrect format
|
|
173
|
+
|
|
174
|
+
Resolution:
|
|
175
|
+
- Check the primary key field
|
|
176
|
+
"""
|
|
177
|
+
pass
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class InvalidFilterException(VikingMemException):
|
|
181
|
+
"""
|
|
182
|
+
Invalid scalar filter statement exception (Error code: 1000019)
|
|
183
|
+
|
|
184
|
+
Triggered by:
|
|
185
|
+
- Incorrect filter format
|
|
186
|
+
- Field not added to scalar index
|
|
187
|
+
- Improper use of field filter statement
|
|
188
|
+
|
|
189
|
+
Resolution:
|
|
190
|
+
- Check filter statement format and field configuration
|
|
191
|
+
"""
|
|
192
|
+
pass
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class IndexSearchException(VikingMemException):
|
|
196
|
+
"""
|
|
197
|
+
Index search exception (Error code: 1000021)
|
|
198
|
+
|
|
199
|
+
Triggered by:
|
|
200
|
+
- Server encountered unknown error or failure
|
|
201
|
+
|
|
202
|
+
Resolution:
|
|
203
|
+
- Contact customer service promptly
|
|
204
|
+
"""
|
|
205
|
+
pass
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class IndexFetchException(VikingMemException):
|
|
209
|
+
"""
|
|
210
|
+
Index fetch data exception (Error code: 1000022)
|
|
211
|
+
|
|
212
|
+
Triggered by:
|
|
213
|
+
- Server encountered unknown error or failure
|
|
214
|
+
|
|
215
|
+
Resolution:
|
|
216
|
+
- Contact customer service promptly
|
|
217
|
+
"""
|
|
218
|
+
pass
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
class IndexInitializingException(VikingMemException):
|
|
222
|
+
"""
|
|
223
|
+
Index initializing exception (Error code: 1000023)
|
|
224
|
+
|
|
225
|
+
Triggered by:
|
|
226
|
+
- Attempting to search or query data while index is initializing
|
|
227
|
+
|
|
228
|
+
Resolution:
|
|
229
|
+
- Wait for index to be ready
|
|
230
|
+
- If not ready after long time (over 1 hour), contact customer service promptly
|
|
231
|
+
"""
|
|
232
|
+
pass
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class EmbeddingException(VikingMemException):
|
|
236
|
+
"""
|
|
237
|
+
Embedding execution exception (Error code: 1000025)
|
|
238
|
+
|
|
239
|
+
Triggered by:
|
|
240
|
+
- Server error during vectorization of unstructured data
|
|
241
|
+
|
|
242
|
+
Resolution:
|
|
243
|
+
- If error occurs occasionally, check if input data format is valid
|
|
244
|
+
- Otherwise, contact customer service promptly
|
|
245
|
+
"""
|
|
246
|
+
pass
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
class InternalServerException(VikingMemException):
|
|
250
|
+
"""
|
|
251
|
+
Internal server error exception (Error code: 1000028)
|
|
252
|
+
|
|
253
|
+
Triggered by:
|
|
254
|
+
- Server encountered unexpected error
|
|
255
|
+
|
|
256
|
+
Resolution:
|
|
257
|
+
- Contact customer service promptly
|
|
258
|
+
"""
|
|
259
|
+
pass
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
class QuotaLimiterException(VikingMemException):
|
|
263
|
+
"""
|
|
264
|
+
Request rate limit exceeded exception (Error code: 1000029)
|
|
265
|
+
|
|
266
|
+
Triggered by:
|
|
267
|
+
- API request QPS too high
|
|
268
|
+
|
|
269
|
+
Resolution:
|
|
270
|
+
- If search requests are rate limited, increase CPU Quota
|
|
271
|
+
- If other APIs are rate limited, check if calling method has issues
|
|
272
|
+
- Adjust API calling frequency
|
|
273
|
+
"""
|
|
274
|
+
pass
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
# Error code to exception class mapping
|
|
278
|
+
EXCEPTION_MAP = {
|
|
279
|
+
1000001: UnauthorizedException, # User authentication failed
|
|
280
|
+
1000003: InvalidRequestException, # Invalid request parameters
|
|
281
|
+
1000004: CollectionExistException, # Collection already exists
|
|
282
|
+
1000005: CollectionNotExistException, # Collection does not exist
|
|
283
|
+
1000007: IndexExistException, # Index already exists
|
|
284
|
+
1000008: IndexNotExistException, # Index does not exist
|
|
285
|
+
1000011: DataNotFoundException, # Data not found
|
|
286
|
+
1000013: DelOpFailedException, # Delete operation failed
|
|
287
|
+
1000014: UpsertOpFailedException, # Upsert operation failed
|
|
288
|
+
1000016: InvalidVectorException, # Invalid vector
|
|
289
|
+
1000017: InvalidPrimaryKeyException, # Invalid primary key
|
|
290
|
+
1000019: InvalidFilterException, # Invalid scalar filter statement
|
|
291
|
+
1000021: IndexSearchException, # Index search exception
|
|
292
|
+
1000022: IndexFetchException, # Index fetch data exception
|
|
293
|
+
1000023: IndexInitializingException, # Index initializing
|
|
294
|
+
1000025: EmbeddingException, # Embedding execution exception
|
|
295
|
+
1000028: InternalServerException, # Internal server error
|
|
296
|
+
1000029: QuotaLimiterException, # Request rate limit exceeded
|
|
297
|
+
}
|
vikingdb/memory/types.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# coding:utf-8
|
|
2
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd.
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
"""Viking Memory SDK Type Definitions"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
from enum import Enum
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class EnumEncoder(json.JSONEncoder):
|
|
13
|
+
"""Enum type JSON encoder"""
|
|
14
|
+
|
|
15
|
+
def default(self, obj: Any) -> Any:
|
|
16
|
+
if isinstance(obj, Enum):
|
|
17
|
+
return obj.value
|
|
18
|
+
return super().default(obj)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from typing import MutableMapping, Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class RequestOptions:
|
|
12
|
+
"""
|
|
13
|
+
Per-request overrides for headers, query parameters, and retry behaviour.
|
|
14
|
+
|
|
15
|
+
Attributes:
|
|
16
|
+
headers: Additional HTTP headers to apply for a single request.
|
|
17
|
+
query: Additional query parameters appended to the request URL.
|
|
18
|
+
request_id: Optional request identifier propagated via X-Tt-Logid.
|
|
19
|
+
max_attempts: Override for retry attempts (defaults to client configuration).
|
|
20
|
+
timeout: Override for the response read timeout (seconds).
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
headers: MutableMapping[str, str] = field(default_factory=dict)
|
|
24
|
+
query: MutableMapping[str, str] = field(default_factory=dict)
|
|
25
|
+
request_id: Optional[str] = None
|
|
26
|
+
max_attempts: Optional[int] = None
|
|
27
|
+
timeout: Optional[int] = None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def ensure_request_options(
|
|
31
|
+
options: Optional[RequestOptions],
|
|
32
|
+
) -> RequestOptions:
|
|
33
|
+
return options if options is not None else RequestOptions()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from .client import VikingVector
|
|
7
|
+
from .collection import CollectionClient
|
|
8
|
+
from .embedding import EmbeddingClient
|
|
9
|
+
from .rerank import RerankClient
|
|
10
|
+
from .index import IndexClient
|
|
11
|
+
from .models import CollectionMeta, IndexMeta, __all__ as _models_all # noqa: F401
|
|
12
|
+
from .models import * # noqa: F401,F403
|
|
13
|
+
from .exceptions import VikingVectorException
|
|
14
|
+
__all__ = [
|
|
15
|
+
"VikingVector",
|
|
16
|
+
"CollectionClient",
|
|
17
|
+
"IndexClient",
|
|
18
|
+
"EmbeddingClient",
|
|
19
|
+
"RerankClient",
|
|
20
|
+
"VikingVectorException",
|
|
21
|
+
] + list(_models_all)
|
|
22
|
+
|
|
23
|
+
del _models_all
|
vikingdb/vector/base.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Mapping, Optional, Type, Union
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel
|
|
9
|
+
|
|
10
|
+
from ..request_options import RequestOptions
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from .client import VikingVector
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class VectorClientBase:
|
|
17
|
+
"""Shared helper for all Vector clients."""
|
|
18
|
+
|
|
19
|
+
def __init__(self, service: "VikingVector") -> None:
|
|
20
|
+
self._service = service
|
|
21
|
+
|
|
22
|
+
def _post(
|
|
23
|
+
self,
|
|
24
|
+
api: str,
|
|
25
|
+
payload: Mapping[str, Any],
|
|
26
|
+
response_model: Type[BaseModel],
|
|
27
|
+
*,
|
|
28
|
+
request_options: Optional[RequestOptions] = None,
|
|
29
|
+
) -> BaseModel:
|
|
30
|
+
response_payload = self._service.request(api, payload, options=request_options)
|
|
31
|
+
return response_model.model_validate(response_payload)
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def _merge_payload(
|
|
35
|
+
base: Mapping[str, Any],
|
|
36
|
+
request: Union[BaseModel, Mapping[str, Any], None],
|
|
37
|
+
) -> Mapping[str, Any]:
|
|
38
|
+
if isinstance(request, BaseModel):
|
|
39
|
+
body = request.model_dump(by_alias=True, exclude_none=True)
|
|
40
|
+
elif request is None:
|
|
41
|
+
body = {}
|
|
42
|
+
elif isinstance(request, Mapping):
|
|
43
|
+
body = {key: value for key, value in request.items() if value is not None}
|
|
44
|
+
else:
|
|
45
|
+
raise Exception(
|
|
46
|
+
f"unsupported request type: {type(request)!r}"
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
merged = dict(base)
|
|
50
|
+
merged.update(body)
|
|
51
|
+
return merged
|