atlas-db-client 0.0.1__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.
- atlas_db_client-0.0.1/.gitignore +219 -0
- atlas_db_client-0.0.1/LICENSE +21 -0
- atlas_db_client-0.0.1/PKG-INFO +83 -0
- atlas_db_client-0.0.1/README.md +58 -0
- atlas_db_client-0.0.1/atlas_db_client/__init__.py +25 -0
- atlas_db_client-0.0.1/atlas_db_client/_async_client.py +92 -0
- atlas_db_client-0.0.1/atlas_db_client/_base.py +109 -0
- atlas_db_client-0.0.1/atlas_db_client/_client.py +92 -0
- atlas_db_client-0.0.1/atlas_db_client/_exceptions.py +24 -0
- atlas_db_client-0.0.1/atlas_db_client/_models.py +42 -0
- atlas_db_client-0.0.1/pyproject.toml +60 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
|
|
204
|
+
# Ruff stuff:
|
|
205
|
+
.ruff_cache/
|
|
206
|
+
|
|
207
|
+
# PyPI configuration file
|
|
208
|
+
.pypirc
|
|
209
|
+
|
|
210
|
+
# Marimo
|
|
211
|
+
marimo/_static/
|
|
212
|
+
marimo/_lsp/
|
|
213
|
+
__marimo__/
|
|
214
|
+
|
|
215
|
+
# Streamlit
|
|
216
|
+
.streamlit/secrets.toml
|
|
217
|
+
|
|
218
|
+
# JetBrains
|
|
219
|
+
.idea/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 devfrank-m
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: atlas-db-client
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: The Python client for the Atlas vector database
|
|
5
|
+
Project-URL: Homepage, https://github.com/devfrank-m/python-atlas-client
|
|
6
|
+
Project-URL: Repository, https://github.com/devfrank-m/python-atlas-client
|
|
7
|
+
Project-URL: Issues, https://github.com/devfrank-m/python-atlas-client/issues
|
|
8
|
+
Author: devfrank-m
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: atlas,client,database,embeddings,vector
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Database
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# Atlas Client
|
|
27
|
+
|
|
28
|
+
The Python client for the [Atlas](https://github.com/devfrank-m/atlas) vector database.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install atlas-db-client
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from atlas_db_client import AtlasClient
|
|
40
|
+
|
|
41
|
+
client = AtlasClient(host="http://localhost:8600")
|
|
42
|
+
|
|
43
|
+
# Create a collection
|
|
44
|
+
collection = client.create_collection(
|
|
45
|
+
name="my-collection",
|
|
46
|
+
dimension=128,
|
|
47
|
+
metric="cosine",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Insert a vector
|
|
51
|
+
result = client.insert_vector(
|
|
52
|
+
collection_id=collection.id,
|
|
53
|
+
vector=[0.1] * 128,
|
|
54
|
+
metadata={"label": "example"},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# Search
|
|
58
|
+
response = client.search(
|
|
59
|
+
collection_id=collection.id,
|
|
60
|
+
vector=[0.1] * 128,
|
|
61
|
+
k=5,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
for r in response.results:
|
|
65
|
+
print(r.id, r.score)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Async Support
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from atlas_db_client import AsyncAtlasClient
|
|
72
|
+
|
|
73
|
+
async with AsyncAtlasClient() as client:
|
|
74
|
+
collection = await client.create_collection(
|
|
75
|
+
name="my-collection",
|
|
76
|
+
dimension=128,
|
|
77
|
+
metric="cosine",
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Atlas Client
|
|
2
|
+
|
|
3
|
+
The Python client for the [Atlas](https://github.com/devfrank-m/atlas) vector database.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install atlas-db-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from atlas_db_client import AtlasClient
|
|
15
|
+
|
|
16
|
+
client = AtlasClient(host="http://localhost:8600")
|
|
17
|
+
|
|
18
|
+
# Create a collection
|
|
19
|
+
collection = client.create_collection(
|
|
20
|
+
name="my-collection",
|
|
21
|
+
dimension=128,
|
|
22
|
+
metric="cosine",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Insert a vector
|
|
26
|
+
result = client.insert_vector(
|
|
27
|
+
collection_id=collection.id,
|
|
28
|
+
vector=[0.1] * 128,
|
|
29
|
+
metadata={"label": "example"},
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# Search
|
|
33
|
+
response = client.search(
|
|
34
|
+
collection_id=collection.id,
|
|
35
|
+
vector=[0.1] * 128,
|
|
36
|
+
k=5,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
for r in response.results:
|
|
40
|
+
print(r.id, r.score)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Async Support
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from atlas_db_client import AsyncAtlasClient
|
|
47
|
+
|
|
48
|
+
async with AsyncAtlasClient() as client:
|
|
49
|
+
collection = await client.create_collection(
|
|
50
|
+
name="my-collection",
|
|
51
|
+
dimension=128,
|
|
52
|
+
metric="cosine",
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
MIT
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
__version__ = "0.0.1"
|
|
2
|
+
|
|
3
|
+
from ._async_client import AsyncAtlasClient
|
|
4
|
+
from ._client import AtlasClient
|
|
5
|
+
from ._exceptions import AtlasError, NotFoundError, ValidationError
|
|
6
|
+
from ._models import (
|
|
7
|
+
Collection,
|
|
8
|
+
Filter,
|
|
9
|
+
SearchResponse,
|
|
10
|
+
SearchResult,
|
|
11
|
+
VectorInsertResult,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"AtlasClient",
|
|
16
|
+
"AsyncAtlasClient",
|
|
17
|
+
"AtlasError",
|
|
18
|
+
"NotFoundError",
|
|
19
|
+
"ValidationError",
|
|
20
|
+
"Collection",
|
|
21
|
+
"Filter",
|
|
22
|
+
"SearchResponse",
|
|
23
|
+
"SearchResult",
|
|
24
|
+
"VectorInsertResult",
|
|
25
|
+
]
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from ._base import (
|
|
8
|
+
DEFAULT_HOST,
|
|
9
|
+
DEFAULT_TIMEOUT,
|
|
10
|
+
_build_client_kwargs,
|
|
11
|
+
_build_create_body,
|
|
12
|
+
_build_insert_body,
|
|
13
|
+
_build_search_body,
|
|
14
|
+
_parse_collection,
|
|
15
|
+
_parse_insert,
|
|
16
|
+
_parse_search,
|
|
17
|
+
_raise_for_status,
|
|
18
|
+
)
|
|
19
|
+
from ._models import Collection, Filter, SearchResponse, VectorInsertResult
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class AsyncAtlasClient:
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
host: str = DEFAULT_HOST,
|
|
26
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
27
|
+
headers: dict[str, str] | None = None,
|
|
28
|
+
**kwargs: Any,
|
|
29
|
+
) -> None:
|
|
30
|
+
self._client = httpx.AsyncClient(
|
|
31
|
+
**_build_client_kwargs(host, timeout, headers, **kwargs)
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
async def _request(self, method: str, path: str, **kwargs: Any) -> dict[str, Any]:
|
|
35
|
+
response = await self._client.request(method, path, **kwargs)
|
|
36
|
+
_raise_for_status(response)
|
|
37
|
+
return response.json()
|
|
38
|
+
|
|
39
|
+
async def create_collection(
|
|
40
|
+
self,
|
|
41
|
+
name: str,
|
|
42
|
+
dimension: int,
|
|
43
|
+
metric: str,
|
|
44
|
+
index: str | None = None,
|
|
45
|
+
) -> Collection:
|
|
46
|
+
data = await self._request(
|
|
47
|
+
"POST",
|
|
48
|
+
"/collections",
|
|
49
|
+
json=_build_create_body(name, dimension, metric, index),
|
|
50
|
+
)
|
|
51
|
+
return _parse_collection(data)
|
|
52
|
+
|
|
53
|
+
async def get_collection(self, collection_id: str) -> Collection:
|
|
54
|
+
data = await self._request("GET", f"/collections/{collection_id}")
|
|
55
|
+
return _parse_collection(data)
|
|
56
|
+
|
|
57
|
+
async def insert_vector(
|
|
58
|
+
self,
|
|
59
|
+
collection_id: str,
|
|
60
|
+
vector: list[float],
|
|
61
|
+
metadata: dict[str, Any],
|
|
62
|
+
external_id: str | None = None,
|
|
63
|
+
) -> VectorInsertResult:
|
|
64
|
+
data = await self._request(
|
|
65
|
+
"POST",
|
|
66
|
+
f"/collections/{collection_id}/vectors",
|
|
67
|
+
json=_build_insert_body(vector, metadata, external_id),
|
|
68
|
+
)
|
|
69
|
+
return _parse_insert(data)
|
|
70
|
+
|
|
71
|
+
async def search(
|
|
72
|
+
self,
|
|
73
|
+
collection_id: str,
|
|
74
|
+
vector: list[float],
|
|
75
|
+
k: int,
|
|
76
|
+
filter: Filter | None = None,
|
|
77
|
+
) -> SearchResponse:
|
|
78
|
+
data = await self._request(
|
|
79
|
+
"POST",
|
|
80
|
+
f"/collections/{collection_id}/search",
|
|
81
|
+
json=_build_search_body(vector, k, filter),
|
|
82
|
+
)
|
|
83
|
+
return _parse_search(data)
|
|
84
|
+
|
|
85
|
+
async def close(self) -> None:
|
|
86
|
+
await self._client.aclose()
|
|
87
|
+
|
|
88
|
+
async def __aenter__(self) -> AsyncAtlasClient:
|
|
89
|
+
return self
|
|
90
|
+
|
|
91
|
+
async def __aexit__(self, *args: Any) -> None:
|
|
92
|
+
await self.close()
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from ._exceptions import AtlasError, NotFoundError, ValidationError
|
|
8
|
+
from ._models import (
|
|
9
|
+
Collection,
|
|
10
|
+
Filter,
|
|
11
|
+
SearchResponse,
|
|
12
|
+
SearchResult,
|
|
13
|
+
VectorInsertResult,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
DEFAULT_HOST = "http://localhost:8600"
|
|
17
|
+
DEFAULT_TIMEOUT = 30.0
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _build_client_kwargs(
|
|
21
|
+
host: str,
|
|
22
|
+
timeout: float,
|
|
23
|
+
headers: dict[str, str] | None,
|
|
24
|
+
**kwargs: Any,
|
|
25
|
+
) -> dict[str, Any]:
|
|
26
|
+
h = {"Content-Type": "application/json"}
|
|
27
|
+
if headers:
|
|
28
|
+
h.update(headers)
|
|
29
|
+
return {"base_url": host, "timeout": timeout, "headers": h, **kwargs}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _raise_for_status(response: httpx.Response) -> None:
|
|
33
|
+
if response.is_success:
|
|
34
|
+
return
|
|
35
|
+
try:
|
|
36
|
+
body = response.json()
|
|
37
|
+
msg = body.get("error", response.text)
|
|
38
|
+
except Exception:
|
|
39
|
+
msg = response.text
|
|
40
|
+
|
|
41
|
+
status = response.status_code
|
|
42
|
+
if status == 404:
|
|
43
|
+
raise NotFoundError(status, msg)
|
|
44
|
+
if status == 400:
|
|
45
|
+
raise ValidationError(status, msg)
|
|
46
|
+
raise AtlasError(status, msg)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _parse_collection(data: dict[str, Any]) -> Collection:
|
|
50
|
+
return Collection(
|
|
51
|
+
id=data["id"],
|
|
52
|
+
name=data["name"],
|
|
53
|
+
dimension=data.get("dimension"),
|
|
54
|
+
metric=data.get("metric"),
|
|
55
|
+
vector_count=data.get("vector_count"),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _parse_insert(data: dict[str, Any]) -> VectorInsertResult:
|
|
60
|
+
return VectorInsertResult(id=data["id"])
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _parse_search(data: dict[str, Any]) -> SearchResponse:
|
|
64
|
+
return SearchResponse(
|
|
65
|
+
results=[
|
|
66
|
+
SearchResult(
|
|
67
|
+
id=r["id"],
|
|
68
|
+
score=r["score"],
|
|
69
|
+
metadata=r["metadata"],
|
|
70
|
+
vector=r.get("vector"),
|
|
71
|
+
external_id=r.get("external_id"),
|
|
72
|
+
)
|
|
73
|
+
for r in data.get("results", [])
|
|
74
|
+
]
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _build_insert_body(
|
|
79
|
+
vector: list[float],
|
|
80
|
+
metadata: dict[str, Any],
|
|
81
|
+
external_id: str | None,
|
|
82
|
+
) -> dict[str, Any]:
|
|
83
|
+
body: dict[str, Any] = {"vector": vector, "metadata": metadata}
|
|
84
|
+
if external_id is not None:
|
|
85
|
+
body["external_id"] = external_id
|
|
86
|
+
return body
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _build_search_body(
|
|
90
|
+
vector: list[float],
|
|
91
|
+
k: int,
|
|
92
|
+
filter: Filter | None,
|
|
93
|
+
) -> dict[str, Any]:
|
|
94
|
+
body: dict[str, Any] = {"vector": vector, "k": k}
|
|
95
|
+
if filter is not None:
|
|
96
|
+
body["filter"] = filter.to_dict()
|
|
97
|
+
return body
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _build_create_body(
|
|
101
|
+
name: str,
|
|
102
|
+
dimension: int,
|
|
103
|
+
metric: str,
|
|
104
|
+
index: str | None,
|
|
105
|
+
) -> dict[str, Any]:
|
|
106
|
+
body: dict[str, Any] = {"name": name, "dimension": dimension, "metric": metric}
|
|
107
|
+
if index is not None:
|
|
108
|
+
body["index"] = index
|
|
109
|
+
return body
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from ._base import (
|
|
8
|
+
DEFAULT_HOST,
|
|
9
|
+
DEFAULT_TIMEOUT,
|
|
10
|
+
_build_client_kwargs,
|
|
11
|
+
_build_create_body,
|
|
12
|
+
_build_insert_body,
|
|
13
|
+
_build_search_body,
|
|
14
|
+
_parse_collection,
|
|
15
|
+
_parse_insert,
|
|
16
|
+
_parse_search,
|
|
17
|
+
_raise_for_status,
|
|
18
|
+
)
|
|
19
|
+
from ._models import Collection, Filter, SearchResponse, VectorInsertResult
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class AtlasClient:
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
host: str = DEFAULT_HOST,
|
|
26
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
27
|
+
headers: dict[str, str] | None = None,
|
|
28
|
+
**kwargs: Any,
|
|
29
|
+
) -> None:
|
|
30
|
+
self._client = httpx.Client(
|
|
31
|
+
**_build_client_kwargs(host, timeout, headers, **kwargs)
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def _request(self, method: str, path: str, **kwargs: Any) -> dict[str, Any]:
|
|
35
|
+
response = self._client.request(method, path, **kwargs)
|
|
36
|
+
_raise_for_status(response)
|
|
37
|
+
return response.json()
|
|
38
|
+
|
|
39
|
+
def create_collection(
|
|
40
|
+
self,
|
|
41
|
+
name: str,
|
|
42
|
+
dimension: int,
|
|
43
|
+
metric: str,
|
|
44
|
+
index: str | None = None,
|
|
45
|
+
) -> Collection:
|
|
46
|
+
data = self._request(
|
|
47
|
+
"POST",
|
|
48
|
+
"/collections",
|
|
49
|
+
json=_build_create_body(name, dimension, metric, index),
|
|
50
|
+
)
|
|
51
|
+
return _parse_collection(data)
|
|
52
|
+
|
|
53
|
+
def get_collection(self, collection_id: str) -> Collection:
|
|
54
|
+
data = self._request("GET", f"/collections/{collection_id}")
|
|
55
|
+
return _parse_collection(data)
|
|
56
|
+
|
|
57
|
+
def insert_vector(
|
|
58
|
+
self,
|
|
59
|
+
collection_id: str,
|
|
60
|
+
vector: list[float],
|
|
61
|
+
metadata: dict[str, Any],
|
|
62
|
+
external_id: str | None = None,
|
|
63
|
+
) -> VectorInsertResult:
|
|
64
|
+
data = self._request(
|
|
65
|
+
"POST",
|
|
66
|
+
f"/collections/{collection_id}/vectors",
|
|
67
|
+
json=_build_insert_body(vector, metadata, external_id),
|
|
68
|
+
)
|
|
69
|
+
return _parse_insert(data)
|
|
70
|
+
|
|
71
|
+
def search(
|
|
72
|
+
self,
|
|
73
|
+
collection_id: str,
|
|
74
|
+
vector: list[float],
|
|
75
|
+
k: int,
|
|
76
|
+
filter: Filter | None = None,
|
|
77
|
+
) -> SearchResponse:
|
|
78
|
+
data = self._request(
|
|
79
|
+
"POST",
|
|
80
|
+
f"/collections/{collection_id}/search",
|
|
81
|
+
json=_build_search_body(vector, k, filter),
|
|
82
|
+
)
|
|
83
|
+
return _parse_search(data)
|
|
84
|
+
|
|
85
|
+
def close(self) -> None:
|
|
86
|
+
self._client.close()
|
|
87
|
+
|
|
88
|
+
def __enter__(self) -> AtlasClient:
|
|
89
|
+
return self
|
|
90
|
+
|
|
91
|
+
def __exit__(self, *args: Any) -> None:
|
|
92
|
+
self.close()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class AtlasError(Exception):
|
|
8
|
+
status_code: int
|
|
9
|
+
message: str
|
|
10
|
+
|
|
11
|
+
def __str__(self) -> str:
|
|
12
|
+
return f"[{self.status_code}] {self.message}"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ConnectionError(AtlasError):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class NotFoundError(AtlasError):
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ValidationError(AtlasError):
|
|
24
|
+
pass
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class Collection:
|
|
9
|
+
id: str
|
|
10
|
+
name: str
|
|
11
|
+
dimension: int | None = None
|
|
12
|
+
metric: str | None = None
|
|
13
|
+
vector_count: int | None = None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class VectorInsertResult:
|
|
18
|
+
id: int
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class SearchResult:
|
|
23
|
+
id: int
|
|
24
|
+
score: float
|
|
25
|
+
metadata: dict[str, Any]
|
|
26
|
+
vector: list[float] | None = None
|
|
27
|
+
external_id: str | None = None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class SearchResponse:
|
|
32
|
+
results: list[SearchResult] = field(default_factory=list)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class Filter:
|
|
37
|
+
key: str
|
|
38
|
+
value: Any
|
|
39
|
+
op: str = "eq"
|
|
40
|
+
|
|
41
|
+
def to_dict(self) -> dict[str, Any]:
|
|
42
|
+
return {"op": self.op, "key": self.key, "value": self.value}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "atlas-db-client"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "The Python client for the Atlas vector database"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
requires-python = ">=3.11"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "devfrank-m" },
|
|
10
|
+
]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"License :: OSI Approved :: MIT License",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
|
+
"Topic :: Database",
|
|
21
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
keywords = ["atlas", "vector", "database", "client", "embeddings"]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/devfrank-m/python-atlas-client"
|
|
28
|
+
Repository = "https://github.com/devfrank-m/python-atlas-client"
|
|
29
|
+
Issues = "https://github.com/devfrank-m/python-atlas-client/issues"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
[dependency-groups]
|
|
33
|
+
dev = [
|
|
34
|
+
"black>=26.3.1",
|
|
35
|
+
"ruff>=0.15.6",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["hatchling"]
|
|
40
|
+
build-backend = "hatchling.build"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["atlas_db_client"]
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.sdist]
|
|
46
|
+
include = ["atlas_db_client", "README.md", "LICENSE"]
|
|
47
|
+
|
|
48
|
+
[tool.semantic_release]
|
|
49
|
+
version_toml = ["pyproject.toml:project.version"]
|
|
50
|
+
version_variables = ["atlas_db_client/__init__.py:__version__"]
|
|
51
|
+
branch = "main"
|
|
52
|
+
build_command = "pip install build && python -m build"
|
|
53
|
+
commit_message = "chore(release): v{version}"
|
|
54
|
+
|
|
55
|
+
[tool.semantic_release.changelog]
|
|
56
|
+
changelog_file = "CHANGELOG.md"
|
|
57
|
+
|
|
58
|
+
[tool.semantic_release.remote]
|
|
59
|
+
type = "github"
|
|
60
|
+
token = { env = "GH_TOKEN" }
|