vikingdb-python-sdk 0.1.4__tar.gz

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.
Files changed (33) hide show
  1. vikingdb_python_sdk-0.1.4/LICENSE.txt +202 -0
  2. vikingdb_python_sdk-0.1.4/PKG-INFO +228 -0
  3. vikingdb_python_sdk-0.1.4/README.md +200 -0
  4. vikingdb_python_sdk-0.1.4/pyproject.toml +48 -0
  5. vikingdb_python_sdk-0.1.4/setup.cfg +4 -0
  6. vikingdb_python_sdk-0.1.4/vikingdb/__init__.py +34 -0
  7. vikingdb_python_sdk-0.1.4/vikingdb/_client.py +262 -0
  8. vikingdb_python_sdk-0.1.4/vikingdb/auth.py +68 -0
  9. vikingdb_python_sdk-0.1.4/vikingdb/exceptions.py +160 -0
  10. vikingdb_python_sdk-0.1.4/vikingdb/memory/__init__.py +70 -0
  11. vikingdb_python_sdk-0.1.4/vikingdb/memory/client.py +295 -0
  12. vikingdb_python_sdk-0.1.4/vikingdb/memory/collection.py +965 -0
  13. vikingdb_python_sdk-0.1.4/vikingdb/memory/exceptions.py +297 -0
  14. vikingdb_python_sdk-0.1.4/vikingdb/memory/types.py +18 -0
  15. vikingdb_python_sdk-0.1.4/vikingdb/request_options.py +33 -0
  16. vikingdb_python_sdk-0.1.4/vikingdb/vector/__init__.py +21 -0
  17. vikingdb_python_sdk-0.1.4/vikingdb/vector/base.py +51 -0
  18. vikingdb_python_sdk-0.1.4/vikingdb/vector/client.py +278 -0
  19. vikingdb_python_sdk-0.1.4/vikingdb/vector/collection.py +110 -0
  20. vikingdb_python_sdk-0.1.4/vikingdb/vector/embedding.py +33 -0
  21. vikingdb_python_sdk-0.1.4/vikingdb/vector/exceptions.py +40 -0
  22. vikingdb_python_sdk-0.1.4/vikingdb/vector/index.py +189 -0
  23. vikingdb_python_sdk-0.1.4/vikingdb/vector/models/__init__.py +96 -0
  24. vikingdb_python_sdk-0.1.4/vikingdb/vector/models/base.py +68 -0
  25. vikingdb_python_sdk-0.1.4/vikingdb/vector/models/collection.py +67 -0
  26. vikingdb_python_sdk-0.1.4/vikingdb/vector/models/embedding.py +50 -0
  27. vikingdb_python_sdk-0.1.4/vikingdb/vector/models/index.py +122 -0
  28. vikingdb_python_sdk-0.1.4/vikingdb/version.py +4 -0
  29. vikingdb_python_sdk-0.1.4/vikingdb_python_sdk.egg-info/PKG-INFO +228 -0
  30. vikingdb_python_sdk-0.1.4/vikingdb_python_sdk.egg-info/SOURCES.txt +31 -0
  31. vikingdb_python_sdk-0.1.4/vikingdb_python_sdk.egg-info/dependency_links.txt +1 -0
  32. vikingdb_python_sdk-0.1.4/vikingdb_python_sdk.egg-info/requires.txt +7 -0
  33. vikingdb_python_sdk-0.1.4/vikingdb_python_sdk.egg-info/top_level.txt +1 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: vikingdb-python-sdk
3
+ Version: 0.1.4
4
+ Summary: vikingdb Python SDK
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Documentation, https://github.com/volcengine/volc-vikingdb-python-sdk/README.md
7
+ Project-URL: Source, https://github.com/volcengine/volc-vikingdb-python-sdk
8
+ Keywords: vikingdb,vector,bytedance,volcengine,sdk
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Topic :: Software Development :: Libraries
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE.txt
20
+ Requires-Dist: numpy>=1.21.6
21
+ Requires-Dist: httpx>=0.24.1
22
+ Requires-Dist: requests>=2.28.1
23
+ Requires-Dist: pydantic>=2.5.3
24
+ Requires-Dist: urllib3>=2.0.7
25
+ Requires-Dist: volcengine>=1.0.0
26
+ Requires-Dist: aiohttp>=3.10.0
27
+ Dynamic: license-file
28
+
29
+ ## VikingDB Python SDK (v2)
30
+
31
+ This package provides an idiomatic Python interface to the VikingDB v2 data-plane APIs. The SDK mirrors the behaviour and API surface of the official Java and Go clients while embracing Python conventions (dataclasses/pydantic models, requests-based transport, and pytest-driven examples).
32
+
33
+ ### Key Features
34
+ - Simple client configuration with AK/SK signing (Volcano Engine V4) or API-key authentication.
35
+ - **Vector Database**: Request envelope handling with typed request/response models covering collection, index, and embedding workflows.
36
+ - **Memory Management**: Conversational memory APIs for managing user profiles, events, and session messages with semantic search capabilities.
37
+ - Pluggable retry strategy (exponential backoff with jitter) and per-request overrides (`RequestOptions`).
38
+ - Executable example guides (`pytest` integration tests and standalone scripts) that demonstrate connectivity, CRUD, search, analytics, embedding, and memory management scenarios against a real VikingDB environment.
39
+
40
+ ### Installation
41
+
42
+ Clone the repository and install the SDK in editable mode:
43
+
44
+ ```bash
45
+ uv add vikingdb-python-sdk
46
+ ```
47
+
48
+ > **Dependencies:** The SDK relies on `requests`, `pydantic>=2.5`, and the Volcano Engine base SDK (`volcengine`) for request signing.
49
+
50
+ ### Quickstart
51
+
52
+ #### Vector Database
53
+
54
+ ```python
55
+ import os
56
+ from vikingdb import IAM
57
+ from vikingdb.vector import SearchByRandomRequest, VikingVector
58
+
59
+ auth = IAM(ak=os.environ["VIKINGDB_AK"], sk=os.environ["VIKINGDB_SK"])
60
+ client = VikingVector(
61
+ host=os.environ["VIKINGDB_HOST"],
62
+ region=os.environ["VIKINGDB_REGION"],
63
+ auth=auth,
64
+ scheme="https",
65
+ timeout=30,
66
+ )
67
+ index = client.index(
68
+ collection_name=os.environ["VIKINGDB_COLLECTION"],
69
+ index_name=os.environ["VIKINGDB_INDEX"],
70
+ )
71
+ resp = index.search_by_random(SearchByRandomRequest(limit=1))
72
+ print(f"request_id={resp.request_id} hits={len(resp.result.data or [])}")
73
+ ```
74
+
75
+ #### Memory Management
76
+
77
+ ```python
78
+ from vikingdb import IAM
79
+ from vikingdb.memory import VikingMem
80
+
81
+ auth = IAM(ak="<AK>", sk="<SK>")
82
+ client = VikingMem(
83
+ host="api-knowledgebase.mlp.cn-beijing.volces.com",
84
+ region="cn-beijing",
85
+ auth=auth,
86
+ scheme="http",
87
+ )
88
+
89
+ # Get collection
90
+ collection = client.get_collection(
91
+ collection_name="demo_collection",
92
+ project_name="default"
93
+ )
94
+
95
+ # Add session messages
96
+ collection.add_session(
97
+ session_id="session_001",
98
+ messages=[
99
+ {"role": "user", "content": "Hello, how is the weather today?"},
100
+ {"role": "assistant", "content": "Today is sunny, perfect for going out."}
101
+ ],
102
+ metadata={
103
+ "default_user_id": "user_001",
104
+ "default_assistant_id": "assistant_001",
105
+ }
106
+ )
107
+
108
+ # Search memories
109
+ result = collection.search_memory(
110
+ query="weather today",
111
+ filter={"user_id": "user_001", "memory_type": ["event_v1"]},
112
+ limit=10
113
+ )
114
+ print("search results:", result)
115
+ ```
116
+
117
+ ### Example Guides
118
+
119
+ #### Vector Examples
120
+
121
+ The integration guides under `examples/vector` mirror the Go SDK walkthroughs (`1`–`6`). Each test connects to a live VikingDB environment and exercises a specific workflow.
122
+
123
+ 1. Set the required environment variables (or create a `.env` file in the project root):
124
+
125
+ ```
126
+ VIKINGDB_AK=your-access-key
127
+ VIKINGDB_SK=your-secret-key
128
+ VIKINGDB_COLLECTION=demo_collection
129
+ VIKINGDB_INDEX=demo_index
130
+ # Optional:
131
+ # VIKINGDB_PROJECT=project-name
132
+ # VIKINGDB_RESOURCE_ID=resource-id
133
+ ```
134
+
135
+ The pytest guides themselves lock to the ap-southeast-1 public datasets:
136
+
137
+ - host: `api-vikingdb.vikingdb.ap-southeast-1.volces.com`
138
+ - region: `ap-southeast-1`
139
+ - text walkthroughs use `collection=text`, `index=text_index`
140
+ - vector walkthroughs use `collection=vector`, `index=vector_index`
141
+
142
+ 2. Install pytest (if not already available):
143
+
144
+ ```bash
145
+ uv add --dev pytest
146
+ ```
147
+
148
+ 3. Execute the guides:
149
+
150
+ ```bash
151
+ uv run pytest examples/vector -k scenario
152
+ ```
153
+
154
+ Each scenario writes temporary documents using unique session tags and cleans them up afterwards.
155
+
156
+ #### Memory Examples
157
+
158
+ The memory examples under `examples/memory` demonstrate the core workflows for managing conversational memories:
159
+
160
+ 1. **01_init_client_and_collection.py**: Initialize the VikingMem client and get collection instances using either collection name + project name or resource ID.
161
+
162
+ 2. **02_add_session.py**: Add session messages (user-assistant conversations) to the memory collection with metadata such as user ID, assistant ID, and timestamps.
163
+
164
+ 3. **03_search_memory.py**: Search memories with various filters including:
165
+ - User profile search
166
+ - Event search by semantic query
167
+ - Time range filtering for recent events
168
+
169
+ To run the memory examples:
170
+
171
+ ```bash
172
+ # Set environment variables
173
+ export VIKINGDB_AK=your-access-key
174
+ export VIKINGDB_SK=your-secret-key
175
+
176
+ # Run individual examples
177
+ python examples/memory/01_init_client_and_collection.py
178
+ python examples/memory/02_add_session.py
179
+ python examples/memory/03_search_memory.py
180
+ ```
181
+
182
+ ### Architecture Overview
183
+
184
+ - `vikingdb._client`, `vikingdb.auth`, `vikingdb.request_options`, and `vikingdb.vector.exceptions` form the shared runtime used by all present and future SDK domains (vector, memory, knowledge).
185
+ - Domain-specific features live under dedicated namespaces such as `vikingdb.vector` and `vikingdb.memory`, where the high-level clients (`VikingVector`, `VikingMem`) compose the shared auth stack atop the shared client.
186
+ - Vector request/response models now surface directly from `vikingdb.vector` (backed internally by `vikingdb/vector/models`).
187
+ - Memory APIs return plain dictionaries without object encapsulation, providing a lightweight interface for conversational memory management (session, profile, event operations).
188
+ - Imports from the root package now focus on cross-cutting utilities (auth, config, request options), while application code should pull domain-specific functionality from `vikingdb.vector` or `vikingdb.memory` explicitly.
189
+
190
+ ### Project Structure
191
+
192
+ ```
193
+ vikingdb/
194
+ ├── _client.py # Shared base client built on volcengine Service
195
+ ├── auth.py # Shared auth providers (IAM, API key)
196
+ ├── request_options.py # Per-request overrides shared by all services
197
+ ├── version.py # Package metadata
198
+ ├── vector/ # Vector-specific clients and models
199
+ │ ├── __init__.py # High-level vector client and namespace exports
200
+ │ ├── base.py # Shared helpers for vector clients
201
+ │ ├── collection.py # Collection operations
202
+ │ ├── embedding.py # Embedding operations
203
+ │ ├── index.py # Index/search operations
204
+ │ ├── client.py # Vector service wrapper and high-level client
205
+ │ ├── exceptions.py # Vector-specific exceptions
206
+ │ └── models/ # Vector request/response models (pydantic)
207
+ ├── memory/ # Memory-specific clients and models
208
+ │ ├── __init__.py # High-level memory client and namespace exports
209
+ │ ├── client.py # VikingMem service client
210
+ │ ├── collection.py # Memory collection operations
211
+ │ ├── types.py # Type definitions for memory operations
212
+ │ └── exceptions.py # Memory-specific exceptions
213
+
214
+ examples/
215
+ ├── vector/ # Vector integration guides (pytest)
216
+ │ ├── 1_connectivity_test.py
217
+ │ ├── 2_collection_lifecycle_test.py
218
+ │ ├── 3_*_test.py # Search and indexing examples
219
+ │ └── ...
220
+ └── memory/ # Memory usage examples
221
+ ├── 01_init_client_and_collection.py
222
+ ├── 02_add_session.py
223
+ └── 03_search_memory.py
224
+ ```
225
+
226
+ ### Contributing
227
+
228
+ Contributions and feedback are welcome. Please ensure any new APIs match the OpenAPI specification and include accompanying example coverage.
@@ -0,0 +1,200 @@
1
+ ## VikingDB Python SDK (v2)
2
+
3
+ This package provides an idiomatic Python interface to the VikingDB v2 data-plane APIs. The SDK mirrors the behaviour and API surface of the official Java and Go clients while embracing Python conventions (dataclasses/pydantic models, requests-based transport, and pytest-driven examples).
4
+
5
+ ### Key Features
6
+ - Simple client configuration with AK/SK signing (Volcano Engine V4) or API-key authentication.
7
+ - **Vector Database**: Request envelope handling with typed request/response models covering collection, index, and embedding workflows.
8
+ - **Memory Management**: Conversational memory APIs for managing user profiles, events, and session messages with semantic search capabilities.
9
+ - Pluggable retry strategy (exponential backoff with jitter) and per-request overrides (`RequestOptions`).
10
+ - Executable example guides (`pytest` integration tests and standalone scripts) that demonstrate connectivity, CRUD, search, analytics, embedding, and memory management scenarios against a real VikingDB environment.
11
+
12
+ ### Installation
13
+
14
+ Clone the repository and install the SDK in editable mode:
15
+
16
+ ```bash
17
+ uv add vikingdb-python-sdk
18
+ ```
19
+
20
+ > **Dependencies:** The SDK relies on `requests`, `pydantic>=2.5`, and the Volcano Engine base SDK (`volcengine`) for request signing.
21
+
22
+ ### Quickstart
23
+
24
+ #### Vector Database
25
+
26
+ ```python
27
+ import os
28
+ from vikingdb import IAM
29
+ from vikingdb.vector import SearchByRandomRequest, VikingVector
30
+
31
+ auth = IAM(ak=os.environ["VIKINGDB_AK"], sk=os.environ["VIKINGDB_SK"])
32
+ client = VikingVector(
33
+ host=os.environ["VIKINGDB_HOST"],
34
+ region=os.environ["VIKINGDB_REGION"],
35
+ auth=auth,
36
+ scheme="https",
37
+ timeout=30,
38
+ )
39
+ index = client.index(
40
+ collection_name=os.environ["VIKINGDB_COLLECTION"],
41
+ index_name=os.environ["VIKINGDB_INDEX"],
42
+ )
43
+ resp = index.search_by_random(SearchByRandomRequest(limit=1))
44
+ print(f"request_id={resp.request_id} hits={len(resp.result.data or [])}")
45
+ ```
46
+
47
+ #### Memory Management
48
+
49
+ ```python
50
+ from vikingdb import IAM
51
+ from vikingdb.memory import VikingMem
52
+
53
+ auth = IAM(ak="<AK>", sk="<SK>")
54
+ client = VikingMem(
55
+ host="api-knowledgebase.mlp.cn-beijing.volces.com",
56
+ region="cn-beijing",
57
+ auth=auth,
58
+ scheme="http",
59
+ )
60
+
61
+ # Get collection
62
+ collection = client.get_collection(
63
+ collection_name="demo_collection",
64
+ project_name="default"
65
+ )
66
+
67
+ # Add session messages
68
+ collection.add_session(
69
+ session_id="session_001",
70
+ messages=[
71
+ {"role": "user", "content": "Hello, how is the weather today?"},
72
+ {"role": "assistant", "content": "Today is sunny, perfect for going out."}
73
+ ],
74
+ metadata={
75
+ "default_user_id": "user_001",
76
+ "default_assistant_id": "assistant_001",
77
+ }
78
+ )
79
+
80
+ # Search memories
81
+ result = collection.search_memory(
82
+ query="weather today",
83
+ filter={"user_id": "user_001", "memory_type": ["event_v1"]},
84
+ limit=10
85
+ )
86
+ print("search results:", result)
87
+ ```
88
+
89
+ ### Example Guides
90
+
91
+ #### Vector Examples
92
+
93
+ The integration guides under `examples/vector` mirror the Go SDK walkthroughs (`1`–`6`). Each test connects to a live VikingDB environment and exercises a specific workflow.
94
+
95
+ 1. Set the required environment variables (or create a `.env` file in the project root):
96
+
97
+ ```
98
+ VIKINGDB_AK=your-access-key
99
+ VIKINGDB_SK=your-secret-key
100
+ VIKINGDB_COLLECTION=demo_collection
101
+ VIKINGDB_INDEX=demo_index
102
+ # Optional:
103
+ # VIKINGDB_PROJECT=project-name
104
+ # VIKINGDB_RESOURCE_ID=resource-id
105
+ ```
106
+
107
+ The pytest guides themselves lock to the ap-southeast-1 public datasets:
108
+
109
+ - host: `api-vikingdb.vikingdb.ap-southeast-1.volces.com`
110
+ - region: `ap-southeast-1`
111
+ - text walkthroughs use `collection=text`, `index=text_index`
112
+ - vector walkthroughs use `collection=vector`, `index=vector_index`
113
+
114
+ 2. Install pytest (if not already available):
115
+
116
+ ```bash
117
+ uv add --dev pytest
118
+ ```
119
+
120
+ 3. Execute the guides:
121
+
122
+ ```bash
123
+ uv run pytest examples/vector -k scenario
124
+ ```
125
+
126
+ Each scenario writes temporary documents using unique session tags and cleans them up afterwards.
127
+
128
+ #### Memory Examples
129
+
130
+ The memory examples under `examples/memory` demonstrate the core workflows for managing conversational memories:
131
+
132
+ 1. **01_init_client_and_collection.py**: Initialize the VikingMem client and get collection instances using either collection name + project name or resource ID.
133
+
134
+ 2. **02_add_session.py**: Add session messages (user-assistant conversations) to the memory collection with metadata such as user ID, assistant ID, and timestamps.
135
+
136
+ 3. **03_search_memory.py**: Search memories with various filters including:
137
+ - User profile search
138
+ - Event search by semantic query
139
+ - Time range filtering for recent events
140
+
141
+ To run the memory examples:
142
+
143
+ ```bash
144
+ # Set environment variables
145
+ export VIKINGDB_AK=your-access-key
146
+ export VIKINGDB_SK=your-secret-key
147
+
148
+ # Run individual examples
149
+ python examples/memory/01_init_client_and_collection.py
150
+ python examples/memory/02_add_session.py
151
+ python examples/memory/03_search_memory.py
152
+ ```
153
+
154
+ ### Architecture Overview
155
+
156
+ - `vikingdb._client`, `vikingdb.auth`, `vikingdb.request_options`, and `vikingdb.vector.exceptions` form the shared runtime used by all present and future SDK domains (vector, memory, knowledge).
157
+ - Domain-specific features live under dedicated namespaces such as `vikingdb.vector` and `vikingdb.memory`, where the high-level clients (`VikingVector`, `VikingMem`) compose the shared auth stack atop the shared client.
158
+ - Vector request/response models now surface directly from `vikingdb.vector` (backed internally by `vikingdb/vector/models`).
159
+ - Memory APIs return plain dictionaries without object encapsulation, providing a lightweight interface for conversational memory management (session, profile, event operations).
160
+ - Imports from the root package now focus on cross-cutting utilities (auth, config, request options), while application code should pull domain-specific functionality from `vikingdb.vector` or `vikingdb.memory` explicitly.
161
+
162
+ ### Project Structure
163
+
164
+ ```
165
+ vikingdb/
166
+ ├── _client.py # Shared base client built on volcengine Service
167
+ ├── auth.py # Shared auth providers (IAM, API key)
168
+ ├── request_options.py # Per-request overrides shared by all services
169
+ ├── version.py # Package metadata
170
+ ├── vector/ # Vector-specific clients and models
171
+ │ ├── __init__.py # High-level vector client and namespace exports
172
+ │ ├── base.py # Shared helpers for vector clients
173
+ │ ├── collection.py # Collection operations
174
+ │ ├── embedding.py # Embedding operations
175
+ │ ├── index.py # Index/search operations
176
+ │ ├── client.py # Vector service wrapper and high-level client
177
+ │ ├── exceptions.py # Vector-specific exceptions
178
+ │ └── models/ # Vector request/response models (pydantic)
179
+ ├── memory/ # Memory-specific clients and models
180
+ │ ├── __init__.py # High-level memory client and namespace exports
181
+ │ ├── client.py # VikingMem service client
182
+ │ ├── collection.py # Memory collection operations
183
+ │ ├── types.py # Type definitions for memory operations
184
+ │ └── exceptions.py # Memory-specific exceptions
185
+
186
+ examples/
187
+ ├── vector/ # Vector integration guides (pytest)
188
+ │ ├── 1_connectivity_test.py
189
+ │ ├── 2_collection_lifecycle_test.py
190
+ │ ├── 3_*_test.py # Search and indexing examples
191
+ │ └── ...
192
+ └── memory/ # Memory usage examples
193
+ ├── 01_init_client_and_collection.py
194
+ ├── 02_add_session.py
195
+ └── 03_search_memory.py
196
+ ```
197
+
198
+ ### Contributing
199
+
200
+ Contributions and feedback are welcome. Please ensure any new APIs match the OpenAPI specification and include accompanying example coverage.
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "vikingdb-python-sdk"
7
+ dynamic = ["version"]
8
+ description = "vikingdb Python SDK"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = "Apache-2.0"
12
+ keywords = ["vikingdb", "vector", "bytedance", "volcengine", "sdk"]
13
+ classifiers = [
14
+ "Development Status :: 4 - Beta",
15
+ "Intended Audience :: Developers",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.8",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Topic :: Software Development :: Libraries",
22
+ ]
23
+ dependencies = [
24
+ "numpy>=1.21.6",
25
+ "httpx>=0.24.1",
26
+ "requests>=2.28.1",
27
+ "pydantic>=2.5.3",
28
+ "urllib3>=2.0.7",
29
+ "volcengine>=1.0.0",
30
+ "aiohttp>=3.10.0",
31
+ ]
32
+
33
+ [project.urls]
34
+ Documentation = "https://github.com/volcengine/volc-vikingdb-python-sdk/README.md"
35
+ Source = "https://github.com/volcengine/volc-vikingdb-python-sdk"
36
+
37
+ [tool.setuptools.packages.find]
38
+ where = ["."]
39
+ include = ["vikingdb*"]
40
+
41
+ [tool.setuptools.dynamic]
42
+ version = {attr = "vikingdb.version.__version__"}
43
+
44
+ [dependency-groups]
45
+ dev = [
46
+ "pytest>=7.4.4",
47
+ "ruff>=0.14.3",
48
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+