vecmindb 1.2.2__tar.gz → 1.2.5__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.2 → vecmindb-1.2.5}/PKG-INFO +1 -1
  2. {vecmindb-1.2.2 → vecmindb-1.2.5}/pyproject.toml +1 -1
  3. {vecmindb-1.2.2 → vecmindb-1.2.5}/tests/test_client.py +59 -0
  4. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/__init__.py +1 -1
  5. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/async_client.py +4 -0
  6. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/client.py +6 -0
  7. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/exceptions.py +21 -0
  8. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb.egg-info/PKG-INFO +1 -1
  9. {vecmindb-1.2.2 → vecmindb-1.2.5}/README.md +0 -0
  10. {vecmindb-1.2.2 → vecmindb-1.2.5}/setup.cfg +0 -0
  11. {vecmindb-1.2.2 → vecmindb-1.2.5}/tests/test_agent_memory.py +0 -0
  12. {vecmindb-1.2.2 → vecmindb-1.2.5}/tests/test_agent_turns.py +0 -0
  13. {vecmindb-1.2.2 → vecmindb-1.2.5}/tests/test_integrations.py +0 -0
  14. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/agent_turns.py +0 -0
  15. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/auth.py +0 -0
  16. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/gate_calibrate.py +0 -0
  17. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/integrations/__init__.py +0 -0
  18. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/integrations/langchain.py +0 -0
  19. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/integrations/llamaindex.py +0 -0
  20. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/mcp.py +0 -0
  21. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/mcp_server.py +0 -0
  22. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/memory.py +0 -0
  23. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/memory_plugin.py +0 -0
  24. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/models.py +0 -0
  25. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/py.typed +0 -0
  26. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb/retry.py +0 -0
  27. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb.egg-info/SOURCES.txt +0 -0
  28. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb.egg-info/dependency_links.txt +0 -0
  29. {vecmindb-1.2.2 → vecmindb-1.2.5}/vecmindb.egg-info/requires.txt +0 -0
  30. {vecmindb-1.2.2 → vecmindb-1.2.5}/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.2
3
+ Version: 1.2.5
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "vecmindb"
7
- version = "1.2.2"
7
+ version = "1.2.5"
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"}
@@ -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,
@@ -96,6 +97,28 @@ class TestExceptions(unittest.TestCase):
96
97
  self.assertIsInstance(exception_from_status(500), ServerError)
97
98
  self.assertIsInstance(exception_from_status(503), ServerError)
98
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
+
99
122
  def test_exception_str(self):
100
123
  exc = VecminError("test error", code=400)
101
124
  self.assertEqual(str(exc), "[400] test error")
@@ -104,6 +127,42 @@ class TestExceptions(unittest.TestCase):
104
127
  self.assertEqual(str(exc2), "plain error")
105
128
 
106
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
+
107
166
  class TestRetryConfig(unittest.TestCase):
108
167
  """Verify retry configuration and back-off computation."""
109
168
 
@@ -82,7 +82,7 @@ from .agent_turns import (
82
82
  )
83
83
  from typing import Optional
84
84
 
85
- __version__ = "1.2.2"
85
+ __version__ = "1.2.5"
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,
@@ -1273,6 +1275,8 @@ class AsyncVecminClient:
1273
1275
  f"requested {dimension}, but existing collection has {info.dimension}."
1274
1276
  )
1275
1277
  return True
1278
+ except NotFoundError:
1279
+ pass # collection missing -> create it below (get-or-create contract)
1276
1280
  except VecminError:
1277
1281
  raise
1278
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,
@@ -948,6 +950,8 @@ class VecminClient:
948
950
  f"requested {dimension}, but existing collection has {info.dimension}."
949
951
  )
950
952
  return True
953
+ except NotFoundError:
954
+ pass # collection missing -> create it below (get-or-create contract)
951
955
  except VecminError:
952
956
  raise
953
957
  except Exception:
@@ -959,5 +963,7 @@ class VecminClient:
959
963
  domain=domain, sovereignty_token=sovereignty_token,
960
964
  )
961
965
  return True
966
+ except ConflictError:
967
+ return True # lost a concurrent creation race - it exists now
962
968
  except Exception:
963
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vecmindb
3
- Version: 1.2.2
3
+ Version: 1.2.5
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes