vecmindb 1.2.1__tar.gz → 1.2.3__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 (30) hide show
  1. {vecmindb-1.2.1 → vecmindb-1.2.3}/PKG-INFO +3 -2
  2. {vecmindb-1.2.1 → vecmindb-1.2.3}/pyproject.toml +3 -2
  3. {vecmindb-1.2.1 → vecmindb-1.2.3}/tests/test_client.py +61 -1
  4. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/__init__.py +1 -1
  5. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/async_client.py +25 -7
  6. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/client.py +26 -7
  7. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/exceptions.py +21 -0
  8. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/models.py +29 -6
  9. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb.egg-info/PKG-INFO +3 -2
  10. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb.egg-info/requires.txt +2 -1
  11. {vecmindb-1.2.1 → vecmindb-1.2.3}/README.md +0 -0
  12. {vecmindb-1.2.1 → vecmindb-1.2.3}/setup.cfg +0 -0
  13. {vecmindb-1.2.1 → vecmindb-1.2.3}/tests/test_agent_memory.py +0 -0
  14. {vecmindb-1.2.1 → vecmindb-1.2.3}/tests/test_agent_turns.py +0 -0
  15. {vecmindb-1.2.1 → vecmindb-1.2.3}/tests/test_integrations.py +0 -0
  16. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/agent_turns.py +0 -0
  17. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/auth.py +0 -0
  18. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/gate_calibrate.py +0 -0
  19. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/integrations/__init__.py +0 -0
  20. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/integrations/langchain.py +0 -0
  21. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/integrations/llamaindex.py +0 -0
  22. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/mcp.py +0 -0
  23. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/mcp_server.py +0 -0
  24. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/memory.py +0 -0
  25. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/memory_plugin.py +0 -0
  26. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/py.typed +0 -0
  27. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb/retry.py +0 -0
  28. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb.egg-info/SOURCES.txt +0 -0
  29. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb.egg-info/dependency_links.txt +0 -0
  30. {vecmindb-1.2.1 → vecmindb-1.2.3}/vecmindb.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vecmindb
3
- Version: 1.2.1
3
+ Version: 1.2.3
4
4
  Summary: Python SDK for VecminDB - High-performance vector database HTTP client
5
5
  Author-email: VecminDB Team <contact@lingxinmind.com>
6
6
  License: MIT OR Apache-2.0
@@ -24,7 +24,8 @@ Classifier: Topic :: Database
24
24
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
25
  Requires-Python: >=3.8
26
26
  Description-Content-Type: text/markdown
27
- Requires-Dist: requests>=2.28.0
27
+ Requires-Dist: httpx>=0.24.0
28
+ Requires-Dist: pydantic<3.0,>=2.0
28
29
  Provides-Extra: dev
29
30
  Requires-Dist: pytest>=7.0; extra == "dev"
30
31
  Requires-Dist: pytest-cov>=4.0; extra == "dev"
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "vecmindb"
7
- version = "1.2.1"
7
+ version = "1.2.3"
8
8
  description = "Python SDK for VecminDB - High-performance vector database HTTP client"
9
9
  authors = [{email = "contact@lingxinmind.com", name = "VecminDB Team"}]
10
10
  license = {text = "MIT OR Apache-2.0"}
@@ -28,7 +28,8 @@ classifiers = [
28
28
  "Topic :: Scientific/Engineering :: Artificial Intelligence",
29
29
  ]
30
30
  dependencies = [
31
- "requests>=2.28.0",
31
+ "httpx>=0.24.0",
32
+ "pydantic>=2.0,<3.0",
32
33
  ]
33
34
 
34
35
  [project.optional-dependencies]
@@ -6,6 +6,7 @@ They can also be run in offline/mock mode to verify the SDK structure.
6
6
 
7
7
  import unittest
8
8
  import os
9
+ from unittest.mock import MagicMock
9
10
  from vecmindb import VecminClient, AsyncVecminClient, VecminError
10
11
  from vecmindb.models import (
11
12
  CreateCollectionRequest,
@@ -42,12 +43,13 @@ class TestModels(unittest.TestCase):
42
43
 
43
44
  def test_search_request(self):
44
45
  req = SearchRequest(query=[0.1, 0.2, 0.3], k=5, ef_search=100)
45
- self.assertEqual(req.k, 5)
46
+ self.assertEqual(req.top_k, 5)
46
47
  self.assertEqual(len(req.query), 3)
47
48
 
48
49
  def test_insert_request(self):
49
50
  req = InsertRequest(values=[0.1, 0.2], id="vec-1", metadata={"key": "val"})
50
51
  self.assertEqual(req.id, "vec-1")
52
+ self.assertEqual(req.data, [0.1, 0.2])
51
53
  self.assertEqual(req.metadata["key"], "val")
52
54
 
53
55
  def test_search_response(self):
@@ -95,6 +97,28 @@ class TestExceptions(unittest.TestCase):
95
97
  self.assertIsInstance(exception_from_status(500), ServerError)
96
98
  self.assertIsInstance(exception_from_status(503), ServerError)
97
99
 
100
+ def test_exception_from_status_empty_message_fallback(self):
101
+ """Empty/None server messages must never surface as '[401] None'."""
102
+ from vecmindb.exceptions import (
103
+ AuthenticationError,
104
+ ServerError,
105
+ exception_from_status,
106
+ )
107
+
108
+ for bad_message in (None, "", " "):
109
+ exc = exception_from_status(401, message=bad_message)
110
+ self.assertIsInstance(exc, AuthenticationError)
111
+ self.assertNotIn("None", str(exc))
112
+ self.assertIn("Unauthorized", str(exc))
113
+
114
+ exc = exception_from_status(500, message=None)
115
+ self.assertIsInstance(exc, ServerError)
116
+ self.assertIn("no message from server", str(exc))
117
+
118
+ # A real server-provided message must be preserved as-is.
119
+ exc = exception_from_status(401, message="tenant key revoked")
120
+ self.assertEqual(str(exc), "[401] tenant key revoked")
121
+
98
122
  def test_exception_str(self):
99
123
  exc = VecminError("test error", code=400)
100
124
  self.assertEqual(str(exc), "[400] test error")
@@ -103,6 +127,42 @@ class TestExceptions(unittest.TestCase):
103
127
  self.assertEqual(str(exc2), "plain error")
104
128
 
105
129
 
130
+ class TestEnsureCollection(unittest.TestCase):
131
+ """Verify the get-or-create contract of ensure_collection (mocked transport)."""
132
+
133
+ def _make_client(self) -> VecminClient:
134
+ return VecminClient(base_url="http://localhost:5520", api_key="test-key")
135
+
136
+ def test_missing_collection_is_created(self):
137
+ """404 on get_collection must fall through to create_collection."""
138
+ from vecmindb.exceptions import NotFoundError
139
+
140
+ client = self._make_client()
141
+ client._api_get = MagicMock(side_effect=NotFoundError("not found", code=404))
142
+ client._api_post = MagicMock(return_value={"code": 201})
143
+ self.assertTrue(client.ensure_collection("new_col", dimension=1024))
144
+ client._api_post.assert_called_once()
145
+
146
+ def test_creation_race_returns_true(self):
147
+ """409 Conflict on create means another caller won the race - it exists."""
148
+ from vecmindb.exceptions import ConflictError, NotFoundError
149
+
150
+ client = self._make_client()
151
+ client._api_get = MagicMock(side_effect=NotFoundError("not found", code=404))
152
+ client._api_post = MagicMock(side_effect=ConflictError("already exists", code=409))
153
+ self.assertTrue(client.ensure_collection("raced", dimension=1024))
154
+
155
+ def test_other_create_errors_return_false(self):
156
+ """Non-conflict creation failures must degrade to False, not raise."""
157
+ from vecmindb.exceptions import ConnectionError as SdkConnectionError
158
+ from vecmindb.exceptions import NotFoundError
159
+
160
+ client = self._make_client()
161
+ client._api_get = MagicMock(side_effect=NotFoundError("not found", code=404))
162
+ client._api_post = MagicMock(side_effect=SdkConnectionError("down", code=0))
163
+ self.assertFalse(client.ensure_collection("broken", dimension=1024))
164
+
165
+
106
166
  class TestRetryConfig(unittest.TestCase):
107
167
  """Verify retry configuration and back-off computation."""
108
168
 
@@ -82,7 +82,7 @@ from .agent_turns import (
82
82
  )
83
83
  from typing import Optional
84
84
 
85
- __version__ = "1.2.1"
85
+ __version__ = "1.2.3"
86
86
 
87
87
 
88
88
  def connect(
@@ -23,7 +23,9 @@ import httpx
23
23
  from .auth import AuthManager
24
24
  from .exceptions import (
25
25
  AuthenticationError,
26
+ ConflictError,
26
27
  ConnectionError,
28
+ NotFoundError,
27
29
  TimeoutError,
28
30
  VecminError,
29
31
  exception_from_status,
@@ -504,7 +506,7 @@ class AsyncVecminClient:
504
506
  Returns:
505
507
  The vector identifier.
506
508
  """
507
- payload = InsertRequest(id=id, values=vector, metadata=metadata)
509
+ payload = InsertRequest(id=id or str(uuid.uuid4()), data=vector, metadata=metadata)
508
510
  data = await self._api_post(
509
511
  f"/collections/{collection}/vectors",
510
512
  payload.model_dump(exclude_none=True),
@@ -526,19 +528,33 @@ class AsyncVecminClient:
526
528
 
527
529
  Args:
528
530
  collection: Target collection name.
529
- vectors: List of dicts with keys ``values``, ``id``, ``metadata``.
531
+ vectors: List of dicts with keys ``data`` (or legacy ``values``),
532
+ ``id``, ``metadata``.
530
533
 
531
534
  Returns:
532
535
  List of inserted vector identifiers.
536
+
537
+ Note:
538
+ The batch endpoint requires consensus (distributed) mode; on a
539
+ standalone node the server responds with an internal error.
533
540
  """
534
- items = [InsertRequest(**v) for v in vectors]
535
- payload = BatchInsertRequest(vectors=items)
541
+ operations = [
542
+ {
543
+ "type": "add",
544
+ "id": v.get("id") or str(uuid.uuid4()),
545
+ "data": v.get("data", v.get("values", v.get("vector"))),
546
+ "metadata": v.get("metadata"),
547
+ }
548
+ for v in vectors
549
+ ]
536
550
  data = await self._api_post(
537
551
  f"/collections/{collection}/batch",
538
- payload.model_dump(exclude_none=True),
552
+ {"operations": operations},
539
553
  **kw,
540
554
  )
541
555
  result = data.get("data", data)
556
+ if isinstance(result, dict):
557
+ result = result.get("ids", result.get("vectors", []))
542
558
  if isinstance(result, list):
543
559
  return [r.get("id", str(r)) if isinstance(r, dict) else str(r) for r in result]
544
560
  return [str(result)]
@@ -567,7 +583,7 @@ class AsyncVecminClient:
567
583
  Returns:
568
584
  Search results.
569
585
  """
570
- payload = SearchRequest(query=query, k=top_k, ef_search=ef_search, metric=metric, filter=filter)
586
+ payload = SearchRequest(query=query, top_k=top_k, ef_search=ef_search, metric=metric, filter=filter)
571
587
  data = await self._api_post(
572
588
  f"/collections/{collection}/search",
573
589
  payload.model_dump(exclude_none=True),
@@ -773,7 +789,7 @@ class AsyncVecminClient:
773
789
  Returns:
774
790
  Search results.
775
791
  """
776
- payload = SearchRequest(query=query, k=top_k, ef_search=ef_search, metric=metric, filter=filter)
792
+ payload = SearchRequest(query=query, top_k=top_k, ef_search=ef_search, metric=metric, filter=filter)
777
793
  data = await self._api_post("/vectors/search", payload.model_dump(exclude_none=True), **kw)
778
794
  raw = data.get("data", data)
779
795
  if isinstance(raw, list):
@@ -1259,6 +1275,8 @@ class AsyncVecminClient:
1259
1275
  f"requested {dimension}, but existing collection has {info.dimension}."
1260
1276
  )
1261
1277
  return True
1278
+ except NotFoundError:
1279
+ pass # collection missing -> create it below (get-or-create contract)
1262
1280
  except VecminError:
1263
1281
  raise
1264
1282
  except Exception:
@@ -23,7 +23,9 @@ import httpx
23
23
  from .auth import AuthManager
24
24
  from .exceptions import (
25
25
  AuthenticationError,
26
+ ConflictError,
26
27
  ConnectionError,
28
+ NotFoundError,
27
29
  TimeoutError,
28
30
  VecminError,
29
31
  exception_from_status,
@@ -385,7 +387,7 @@ class VecminClient:
385
387
  Returns:
386
388
  The vector identifier.
387
389
  """
388
- payload = InsertRequest(id=id, values=vector, metadata=metadata)
390
+ payload = InsertRequest(id=id or str(uuid.uuid4()), data=vector, metadata=metadata)
389
391
  data = self._api_post(
390
392
  f"/collections/{collection}/vectors",
391
393
  payload.model_dump(exclude_none=True),
@@ -403,15 +405,28 @@ class VecminClient:
403
405
  vectors: List[Dict[str, Any]],
404
406
  **kw,
405
407
  ) -> List[str]:
406
- """Batch insert vectors into a collection (``POST /api/v1/collections/{name}/batch``)."""
407
- items = [InsertRequest(**v) for v in vectors]
408
- payload = BatchInsertRequest(vectors=items)
408
+ """Batch insert vectors into a collection (``POST /api/v1/collections/{name}/batch``).
409
+
410
+ Note: the batch endpoint requires consensus (distributed) mode; on a
411
+ standalone node the server responds with an internal error.
412
+ """
413
+ operations = [
414
+ {
415
+ "type": "add",
416
+ "id": v.get("id") or str(uuid.uuid4()),
417
+ "data": v.get("data", v.get("values", v.get("vector"))),
418
+ "metadata": v.get("metadata"),
419
+ }
420
+ for v in vectors
421
+ ]
409
422
  data = self._api_post(
410
423
  f"/collections/{collection}/batch",
411
- payload.model_dump(exclude_none=True),
424
+ {"operations": operations},
412
425
  **kw,
413
426
  )
414
427
  result = data.get("data", data)
428
+ if isinstance(result, dict):
429
+ result = result.get("ids", result.get("vectors", []))
415
430
  if isinstance(result, list):
416
431
  return [r.get("id", str(r)) if isinstance(r, dict) else str(r) for r in result]
417
432
  return [str(result)]
@@ -428,7 +443,7 @@ class VecminClient:
428
443
  **kw,
429
444
  ) -> SearchResponse:
430
445
  """Search a collection for nearest neighbours (``POST /api/v1/collections/{name}/search``)."""
431
- payload = SearchRequest(query=query, k=top_k, ef_search=ef_search, metric=metric, filter=filter)
446
+ payload = SearchRequest(query=query, top_k=top_k, ef_search=ef_search, metric=metric, filter=filter)
432
447
  data = self._api_post(
433
448
  f"/collections/{collection}/search",
434
449
  payload.model_dump(exclude_none=True),
@@ -566,7 +581,7 @@ class VecminClient:
566
581
  **kw,
567
582
  ) -> SearchResponse:
568
583
  """Global vector search (``POST /api/v1/vectors/search``)."""
569
- payload = SearchRequest(query=query, k=top_k, ef_search=ef_search, metric=metric, filter=filter)
584
+ payload = SearchRequest(query=query, top_k=top_k, ef_search=ef_search, metric=metric, filter=filter)
570
585
  data = self._api_post("/vectors/search", payload.model_dump(exclude_none=True), **kw)
571
586
  raw = data.get("data", data)
572
587
  if isinstance(raw, list):
@@ -935,6 +950,8 @@ class VecminClient:
935
950
  f"requested {dimension}, but existing collection has {info.dimension}."
936
951
  )
937
952
  return True
953
+ except NotFoundError:
954
+ pass # collection missing -> create it below (get-or-create contract)
938
955
  except VecminError:
939
956
  raise
940
957
  except Exception:
@@ -946,5 +963,7 @@ class VecminClient:
946
963
  domain=domain, sovereignty_token=sovereignty_token,
947
964
  )
948
965
  return True
966
+ except ConflictError:
967
+ return True # lost a concurrent creation race - it exists now
949
968
  except Exception:
950
969
  return False
@@ -117,10 +117,26 @@ _STATUS_CODE_TO_EXCEPTION = {
117
117
  429: RateLimitError,
118
118
  }
119
119
 
120
+ # Shown when the server response body carries no usable ``message`` field
121
+ # (e.g. a bare 401 with ``{"code": 401, "message": null}``).
122
+ _DEFAULT_STATUS_MESSAGES = {
123
+ 400: "Bad request (invalid payload)",
124
+ 401: "Unauthorized (missing or invalid API key)",
125
+ 402: "Payment required (license expired or quota exceeded)",
126
+ 403: "Forbidden (insufficient permissions)",
127
+ 404: "Not found (check collection/tenant/ID)",
128
+ 409: "Conflict (resource already exists or state mismatch)",
129
+ 422: "Validation failed",
130
+ 429: "Rate limited (too many requests)",
131
+ }
132
+
120
133
 
121
134
  def exception_from_status(status_code: int, message: str = "", code: Optional[int] = None) -> VecminError:
122
135
  """Create the appropriate exception from an HTTP status code.
123
136
 
137
+ Empty/None ``message`` values (server bodies without a ``message`` field)
138
+ are replaced with a per-status default so callers never see ``[401] None``.
139
+
124
140
  Args:
125
141
  status_code: HTTP status code returned by the server.
126
142
  message: Human-readable error description.
@@ -129,6 +145,11 @@ def exception_from_status(status_code: int, message: str = "", code: Optional[in
129
145
  Returns:
130
146
  A subclass of :class:`VecminError` matching the status code.
131
147
  """
148
+ message = (message or "").strip()
149
+ if not message:
150
+ message = _DEFAULT_STATUS_MESSAGES.get(
151
+ status_code, f"HTTP {status_code} (no message from server)"
152
+ )
132
153
  if 500 <= status_code < 600:
133
154
  return ServerError(message=message, code=code or status_code)
134
155
  exc_cls = _STATUS_CODE_TO_EXCEPTION.get(status_code, VecminError)
@@ -9,7 +9,7 @@ from __future__ import annotations
9
9
 
10
10
  from typing import Any, Dict, List, Optional, Union
11
11
 
12
- from pydantic import BaseModel, Field
12
+ from pydantic import BaseModel, Field, model_validator
13
13
 
14
14
 
15
15
  # ===========================================================================
@@ -106,16 +106,28 @@ class CollectionStats(BaseModel):
106
106
  class InsertRequest(BaseModel):
107
107
  """Payload for inserting a single vector into a collection.
108
108
 
109
+ Server wire format reads ``id`` (required), ``data`` (pre-computed vector)
110
+ or ``text`` (auto-embedding). The legacy ``values`` key is still accepted
111
+ and mapped to ``data`` for backwards compatibility.
112
+
109
113
  Attributes:
110
- id: Optional client-assigned vector identifier.
111
- values: The embedding vector.
114
+ id: Client-assigned vector identifier (UUID-generated when omitted).
115
+ data: The embedding vector.
112
116
  metadata: Arbitrary key-value metadata.
113
117
  """
114
118
 
115
119
  id: Optional[str] = None
116
- values: List[float]
120
+ data: List[float]
117
121
  metadata: Optional[Dict[str, Any]] = None
118
122
 
123
+ @model_validator(mode="before")
124
+ @classmethod
125
+ def _accept_legacy_values(cls, values_obj: Any) -> Any:
126
+ """Back-compat: accept the retired ``values`` key as ``data``."""
127
+ if isinstance(values_obj, dict) and "values" in values_obj and "data" not in values_obj:
128
+ values_obj = {**values_obj, "data": values_obj.pop("values")}
129
+ return values_obj
130
+
119
131
 
120
132
  class BatchInsertRequest(BaseModel):
121
133
  """Payload for ``POST /api/v1/collections/{name}/batch``.
@@ -130,20 +142,31 @@ class BatchInsertRequest(BaseModel):
130
142
  class SearchRequest(BaseModel):
131
143
  """Payload for vector similarity search.
132
144
 
145
+ The server reads ``top_k`` for the result count; the legacy ``k`` key is
146
+ still accepted and mapped to ``top_k`` for backwards compatibility.
147
+
133
148
  Attributes:
134
149
  query: The query embedding vector.
135
- k: Number of nearest neighbours to return.
150
+ top_k: Number of nearest neighbours to return.
136
151
  ef_search: HNSW search-width parameter.
137
152
  metric: Override the default distance metric.
138
153
  filter: Optional metadata filter expression.
139
154
  """
140
155
 
141
156
  query: List[float]
142
- k: int = 10
157
+ top_k: int = 10
143
158
  ef_search: int = 50
144
159
  metric: Optional[str] = None
145
160
  filter: Optional[Dict[str, Any]] = None
146
161
 
162
+ @model_validator(mode="before")
163
+ @classmethod
164
+ def _accept_legacy_k(cls, values_obj: Any) -> Any:
165
+ """Back-compat: accept the retired ``k`` key as ``top_k``."""
166
+ if isinstance(values_obj, dict) and "k" in values_obj and "top_k" not in values_obj:
167
+ values_obj = {**values_obj, "top_k": values_obj.pop("k")}
168
+ return values_obj
169
+
147
170
 
148
171
  class SearchHit(BaseModel):
149
172
  """A single result from a vector similarity search.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vecmindb
3
- Version: 1.2.1
3
+ Version: 1.2.3
4
4
  Summary: Python SDK for VecminDB - High-performance vector database HTTP client
5
5
  Author-email: VecminDB Team <contact@lingxinmind.com>
6
6
  License: MIT OR Apache-2.0
@@ -24,7 +24,8 @@ Classifier: Topic :: Database
24
24
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
25
  Requires-Python: >=3.8
26
26
  Description-Content-Type: text/markdown
27
- Requires-Dist: requests>=2.28.0
27
+ Requires-Dist: httpx>=0.24.0
28
+ Requires-Dist: pydantic<3.0,>=2.0
28
29
  Provides-Extra: dev
29
30
  Requires-Dist: pytest>=7.0; extra == "dev"
30
31
  Requires-Dist: pytest-cov>=4.0; extra == "dev"
@@ -1,4 +1,5 @@
1
- requests>=2.28.0
1
+ httpx>=0.24.0
2
+ pydantic<3.0,>=2.0
2
3
 
3
4
  [dev]
4
5
  pytest>=7.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes