massengine 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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.5
1
+ Metadata-Version: 2.4
2
2
  Name: massengine
3
- Version: 1.2.1
3
+ Version: 1.2.3
4
4
  Summary: Official Python SDK for the MassEngine filtered vector and hybrid search database.
5
5
  Project-URL: Homepage, https://massengine.com
6
6
  Project-URL: Documentation, https://massengine.com/docs
@@ -11,12 +11,16 @@ import urllib.error
11
11
  import urllib.parse
12
12
  import urllib.request
13
13
 
14
- SDK_VERSION = "1.2.1"
14
+ SDK_VERSION = "1.2.3"
15
15
  USER_AGENT = f"massengine-python/{SDK_VERSION}"
16
16
  DEFAULT_MAX_RESPONSE_BYTES = 64 * 1024 * 1024 # 64 MiB
17
17
  MAX_ERROR_RESPONSE_BYTES = 65536 # 64 KiB
18
18
  _MAX_LINE_READ_CHUNK = 4 * 1024 * 1024
19
19
  _MAX_SPARSE_TERMS = 65536
20
+ _MAX_DOC_ID = (1 << 43) - 2
21
+ _MAX_COORD_ABS = 1e15
22
+ _MAX_BATCH_SEARCH_SIZE = 4096
23
+ _MAX_BATCH_GET_SIZE = 1000
20
24
 
21
25
 
22
26
  class MassEngineError(Exception):
@@ -75,8 +79,8 @@ def _validate_finite_float_seq(vector: Any, label: str = "vector") -> List[float
75
79
  raise ValueError(f"{label} must be a sequence of finite numbers") from None
76
80
  out: List[float] = []
77
81
  for v in raw:
78
- if isinstance(v, bool) or not isinstance(v, (int, float)) or not math.isfinite(float(v)):
79
- raise ValueError(f"{label} must contain only finite numbers")
82
+ if isinstance(v, bool) or not isinstance(v, (int, float)) or not math.isfinite(float(v)) or abs(float(v)) > _MAX_COORD_ABS:
83
+ raise ValueError(f"{label} must contain only finite numbers within bounds")
80
84
  out.append(float(v))
81
85
  return out
82
86
 
@@ -149,9 +153,32 @@ def _extract_error_message(raw_text: str) -> str:
149
153
  return msg
150
154
 
151
155
 
156
+ def _check_int(val: Any, label: str, lo: int, hi: Optional[int] = None) -> int:
157
+ if isinstance(val, bool) or not isinstance(val, int) or val < lo or (hi is not None and val > hi):
158
+ bound_desc = f"[{lo}, {hi}]" if hi is not None else f">= {lo}"
159
+ raise ValueError(f"{label} must be an integer in {bound_desc}")
160
+ return val
161
+
162
+
163
+ def _check_bool(val: Any, label: str) -> bool:
164
+ if not isinstance(val, bool):
165
+ raise ValueError(f"{label} must be a bool")
166
+ return val
167
+
168
+
169
+ def _validate_uint16_seq(vals: Any, label: str) -> List[int]:
170
+ if isinstance(vals, (str, bytes, bytearray)):
171
+ raise ValueError(f"{label} must be a sequence of uint16 integers")
172
+ try:
173
+ items = list(vals)
174
+ except TypeError:
175
+ raise ValueError(f"{label} must be a sequence of uint16 integers") from None
176
+ return [_check_int(item, label, 0, 65535) for item in items]
177
+
178
+
152
179
  def _validate_doc_id_int(val: Any) -> int:
153
- if isinstance(val, bool) or not isinstance(val, int) or val < 0 or val > 0xFFFFFFFFFFFFFFFF:
154
- raise ValueError("doc_id must be a uint64 integer")
180
+ if isinstance(val, bool) or not isinstance(val, int) or val < 0 or val > _MAX_DOC_ID:
181
+ raise ValueError(f"doc_id must be an integer in [0, {_MAX_DOC_ID}]")
155
182
  return val
156
183
 
157
184
 
@@ -197,10 +224,10 @@ class Doc:
197
224
  _validate_identifier(self.database, "database")
198
225
  out["database"] = self.database
199
226
  if self.date is not None:
200
- out["date"] = int(self.date)
227
+ out["date"] = _check_int(self.date, "date", 0, 65535)
201
228
  if self.category is not None:
202
- out["category"] = int(self.category)
203
- if self.no_ttl:
229
+ out["category"] = _check_int(self.category, "category", 0, 65535)
230
+ if _check_bool(self.no_ttl, "no_ttl"):
204
231
  out["no_ttl"] = True
205
232
  if self.metadata is not None:
206
233
  out["metadata"] = self.metadata
@@ -245,7 +272,7 @@ class SearchRequest:
245
272
  raise ValueError("search requires a non-empty vector, query_text, or sparse_indices")
246
273
 
247
274
  out: Dict[str, Any] = {
248
- "k": int(self.k),
275
+ "k": _check_int(self.k, "k", 1, 1000),
249
276
  }
250
277
  if len(vec) > 0:
251
278
  out["vector"] = vec
@@ -264,30 +291,37 @@ class SearchRequest:
264
291
  out["database"] = self.database
265
292
  if self.metadata_filter is not None:
266
293
  out["metadata_filter"] = self.metadata_filter
267
- if self.offset:
268
- out["offset"] = int(self.offset)
294
+ offset_val = _check_int(self.offset, "offset", 0, 10000)
295
+ if offset_val > 0:
296
+ out["offset"] = offset_val
269
297
  if self.min_score is not None:
270
298
  out["min_score"] = _validate_min_score(self.min_score)
271
299
  if self.effort is not None:
272
300
  out["effort"] = _validate_effort(self.effort)
273
- if self.rerank_pool:
274
- out["rerank_pool"] = int(self.rerank_pool)
275
- if self.nprobe:
276
- out["nprobe"] = int(self.nprobe)
277
- if self.skip_meta:
301
+ if self.rerank_pool is not None:
302
+ rp_val = _check_int(self.rerank_pool, "rerank_pool", 0)
303
+ if rp_val > 0:
304
+ out["rerank_pool"] = rp_val
305
+ if self.nprobe is not None:
306
+ np_val = _check_int(self.nprobe, "nprobe", 0)
307
+ if np_val > 0:
308
+ out["nprobe"] = np_val
309
+ if _check_bool(self.skip_meta, "skip_meta"):
278
310
  out["skip_meta"] = True
279
311
  if self.min_date is not None:
280
- out["min_date"] = int(self.min_date)
312
+ out["min_date"] = _check_int(self.min_date, "min_date", 0, 65535)
281
313
  if self.max_date is not None:
282
- out["max_date"] = int(self.max_date)
314
+ out["max_date"] = _check_int(self.max_date, "max_date", 0, 65535)
283
315
  if self.category is not None:
284
- out["category"] = int(self.category)
285
- if self.categories:
286
- out["categories"] = [int(c) for c in self.categories]
316
+ out["category"] = _check_int(self.category, "category", 0, 65535)
317
+ if self.categories is not None:
318
+ cats = _validate_uint16_seq(self.categories, "categories")
319
+ if cats:
320
+ out["categories"] = cats
287
321
  if self.min_doc_id is not None:
288
- out["min_doc_id"] = int(self.min_doc_id)
322
+ out["min_doc_id"] = _check_int(self.min_doc_id, "min_doc_id", 0, _MAX_DOC_ID)
289
323
  if self.max_doc_id is not None:
290
- out["max_doc_id"] = int(self.max_doc_id)
324
+ out["max_doc_id"] = _check_int(self.max_doc_id, "max_doc_id", 0, _MAX_DOC_ID)
291
325
  return out
292
326
 
293
327
 
@@ -303,13 +337,15 @@ class TenantQuota:
303
337
  suspended: bool = False
304
338
 
305
339
  def to_dict(self) -> Dict[str, Any]:
340
+ if isinstance(self.max_qps, bool) or not isinstance(self.max_qps, (int, float)) or not math.isfinite(float(self.max_qps)) or float(self.max_qps) < 0:
341
+ raise ValueError("max_qps must be a finite non-negative number")
306
342
  return {
307
343
  "plan": self.plan,
308
- "max_docs": int(self.max_docs),
309
- "max_bytes": int(self.max_bytes),
344
+ "max_docs": _check_int(self.max_docs, "max_docs", 0, 0xFFFFFFFFFFFFFFFF),
345
+ "max_bytes": _check_int(self.max_bytes, "max_bytes", 0, 0xFFFFFFFFFFFFFFFF),
310
346
  "max_qps": float(self.max_qps),
311
- "burst": int(self.burst),
312
- "suspended": bool(self.suspended),
347
+ "burst": _check_int(self.burst, "burst", 0, 0xFFFFFFFFFFFFFFFF),
348
+ "suspended": _check_bool(self.suspended, "suspended"),
313
349
  }
314
350
 
315
351
 
@@ -348,18 +384,21 @@ class MassEngineClient:
348
384
  if not isinstance(base_url, str) or not base_url.strip():
349
385
  raise ValueError("base_url must be a valid http or https URL")
350
386
  cleaned = base_url.strip().rstrip("/")
351
- if any(ord(ch) <= 0x20 or ord(ch) == 0x7F for ch in cleaned):
387
+ if any(ord(ch) <= 0x20 or ord(ch) == 0x7F or ch in ("?", "#", "\\") for ch in cleaned):
352
388
  raise ValueError("base_url contains invalid characters")
353
389
  parsed = urllib.parse.urlsplit(cleaned)
354
390
  if (
355
391
  parsed.scheme not in ("http", "https")
356
392
  or not parsed.netloc
393
+ or not parsed.hostname
357
394
  or parsed.username is not None
358
395
  or parsed.password is not None
359
396
  or parsed.query
360
397
  or parsed.fragment
361
398
  ):
362
399
  raise ValueError("base_url must use http or https scheme with a valid host")
400
+ if any(seg in (".", "..") for seg in parsed.path.split("/")):
401
+ raise ValueError("base_url must not contain dot path segments")
363
402
  return cleaned
364
403
 
365
404
  @staticmethod
@@ -486,13 +525,24 @@ class MassEngineClient:
486
525
  cls._esc_doc_id(raw_id) # type: ignore[arg-type]
487
526
  if raw_doc_id is not None:
488
527
  _validate_doc_id_int(raw_doc_id)
489
- if "vector" in d:
490
- _validate_vector(d.get("vector"))
528
+ if "vector" not in d:
529
+ raise ValueError("document requires a non-empty vector")
530
+ out = dict(d)
531
+ out["vector"] = _validate_vector(d.get("vector"))
491
532
  if "sparse_indices" in d or "sparse_values" in d:
492
- _validate_sparse(d.get("sparse_indices"), d.get("sparse_values"))
533
+ sparse = _validate_sparse(d.get("sparse_indices"), d.get("sparse_values"))
534
+ if sparse is not None:
535
+ out["sparse_indices"] = sparse[0]
536
+ out["sparse_values"] = sparse[1]
493
537
  if d.get("database"):
494
538
  cls._esc_database(d["database"])
495
- return d
539
+ if d.get("date") is not None:
540
+ out["date"] = _check_int(d["date"], "date", 0, 65535)
541
+ if d.get("category") is not None:
542
+ out["category"] = _check_int(d["category"], "category", 0, 65535)
543
+ if "no_ttl" in d and d["no_ttl"] is not None:
544
+ out["no_ttl"] = _check_bool(d["no_ttl"], "no_ttl")
545
+ return out
496
546
 
497
547
  def ingest(
498
548
  self,
@@ -504,6 +554,8 @@ class MassEngineClient:
504
554
  """Inserts or upserts a batch of documents into `tenant` (or the bound `mk_...` key's tenant when empty)."""
505
555
  esc_tenant = self._validate_optional_tenant(tenant)
506
556
  db = self._validate_optional_database(database)
557
+ if not docs:
558
+ raise ValueError("docs must be non-empty")
507
559
  serialized = [self._serialize_doc(d) for d in docs]
508
560
  path = "/v1/ingest" if esc_tenant == "" else f"/v1/tenants/{esc_tenant}/ingest"
509
561
  body: Dict[str, Any] = {"docs": serialized}
@@ -570,8 +622,8 @@ class MassEngineClient:
570
622
  database: str = "",
571
623
  ) -> Dict[str, Any]:
572
624
  """Executes multiple dense, lexical, sparse, or hybrid search queries in a single round-trip."""
573
- if not queries:
574
- raise ValueError("queries must be non-empty")
625
+ if not queries or len(queries) > _MAX_BATCH_SEARCH_SIZE:
626
+ raise ValueError(f"queries length must be between 1 and {_MAX_BATCH_SEARCH_SIZE}")
575
627
  esc_tenant = self._validate_optional_tenant(tenant)
576
628
  db = self._validate_optional_database(database)
577
629
  serialized: List[Dict[str, Any]] = []
@@ -597,6 +649,28 @@ class MassEngineClient:
597
649
  if sparse is not None:
598
650
  q_copy["sparse_indices"] = sparse[0]
599
651
  q_copy["sparse_values"] = sparse[1]
652
+ if "k" in q_copy and q_copy["k"] is not None:
653
+ q_copy["k"] = _check_int(q_copy["k"], "k", 1, 1000)
654
+ if q_copy.get("offset") is not None:
655
+ q_copy["offset"] = _check_int(q_copy["offset"], "offset", 0, 10000)
656
+ if q_copy.get("rerank_pool") is not None:
657
+ q_copy["rerank_pool"] = _check_int(q_copy["rerank_pool"], "rerank_pool", 0)
658
+ if q_copy.get("nprobe") is not None:
659
+ q_copy["nprobe"] = _check_int(q_copy["nprobe"], "nprobe", 0)
660
+ if "skip_meta" in q_copy and q_copy["skip_meta"] is not None:
661
+ q_copy["skip_meta"] = _check_bool(q_copy["skip_meta"], "skip_meta")
662
+ if q_copy.get("min_date") is not None:
663
+ q_copy["min_date"] = _check_int(q_copy["min_date"], "min_date", 0, 65535)
664
+ if q_copy.get("max_date") is not None:
665
+ q_copy["max_date"] = _check_int(q_copy["max_date"], "max_date", 0, 65535)
666
+ if q_copy.get("category") is not None:
667
+ q_copy["category"] = _check_int(q_copy["category"], "category", 0, 65535)
668
+ if q_copy.get("categories") is not None:
669
+ q_copy["categories"] = _validate_uint16_seq(q_copy["categories"], "categories")
670
+ if q_copy.get("min_doc_id") is not None:
671
+ q_copy["min_doc_id"] = _check_int(q_copy["min_doc_id"], "min_doc_id", 0, _MAX_DOC_ID)
672
+ if q_copy.get("max_doc_id") is not None:
673
+ q_copy["max_doc_id"] = _check_int(q_copy["max_doc_id"], "max_doc_id", 0, _MAX_DOC_ID)
600
674
  if q_copy.get("hybrid_alpha") is not None:
601
675
  q_copy["hybrid_alpha"] = _validate_hybrid_alpha(q_copy["hybrid_alpha"])
602
676
  if q_copy.get("min_score") is not None:
@@ -646,10 +720,10 @@ class MassEngineClient:
646
720
  if metadata is not None:
647
721
  body["metadata"] = metadata
648
722
  if date is not None:
649
- body["date"] = int(date)
723
+ body["date"] = _check_int(date, "date", 0, 65535)
650
724
  if category is not None:
651
- body["category"] = int(category)
652
- if replace_metadata:
725
+ body["category"] = _check_int(category, "category", 0, 65535)
726
+ if _check_bool(replace_metadata, "replace_metadata"):
653
727
  body["replace_metadata"] = True
654
728
  return self._request_json("PATCH", self._doc_path(tenant, doc_id), body)
655
729
 
@@ -664,6 +738,8 @@ class MassEngineClient:
664
738
  esc_tenant = self._validate_optional_tenant(tenant)
665
739
  db = self._validate_optional_database(database)
666
740
  id_list = list(ids)
741
+ if not id_list or len(id_list) > _MAX_BATCH_GET_SIZE:
742
+ raise ValueError(f"ids length must be between 1 and {_MAX_BATCH_GET_SIZE}")
667
743
  for doc_id in id_list:
668
744
  self._esc_doc_id(doc_id)
669
745
  path = "/v1/docs/batch-get" if esc_tenant == "" else f"/v1/tenants/{esc_tenant}/docs/batch-get"
@@ -784,21 +860,26 @@ class MassEngineClient:
784
860
  """Creates or updates a named database under `tenant` (or the bound `mk_...` key's tenant)."""
785
861
  esc_tenant = self._validate_optional_tenant(tenant)
786
862
  self._esc_database(database)
863
+ ns_val = _check_int(num_shards, "num_shards", 0)
864
+ rf_val = _check_int(rf, "rf", 0)
865
+ ttl_val = _check_int(ttl_days, "ttl_days", 0, 65535)
866
+ tb_val = _check_int(time_bucket_days, "time_bucket_days", 0, 3650)
867
+ ao_val = _check_bool(append_only, "append_only")
787
868
  path = "/v1/databases" if esc_tenant == "" else f"/v1/tenants/{esc_tenant}/databases"
788
869
  body: Dict[str, Any] = {"database": database}
789
- if num_shards > 0:
790
- body["num_shards"] = int(num_shards)
791
- if rf > 0:
792
- body["rf"] = int(rf)
870
+ if ns_val > 0:
871
+ body["num_shards"] = ns_val
872
+ if rf_val > 0:
873
+ body["rf"] = rf_val
793
874
  if data_type:
794
875
  body["data_type"] = data_type
795
876
  if mode:
796
877
  body["mode"] = mode
797
- if ttl_days > 0:
798
- body["ttl_days"] = int(ttl_days)
799
- if time_bucket_days > 0:
800
- body["time_bucket_days"] = int(time_bucket_days)
801
- if append_only:
878
+ if ttl_val > 0:
879
+ body["ttl_days"] = ttl_val
880
+ if tb_val > 0:
881
+ body["time_bucket_days"] = tb_val
882
+ if ao_val:
802
883
  body["append_only"] = True
803
884
  resp = self._request_json("POST", path, body)
804
885
  if isinstance(resp, dict) and isinstance(resp.get("database"), dict):
@@ -843,6 +924,10 @@ class MassEngineClient:
843
924
 
844
925
  def create_tenant_key(self, tenant: str, key: str = "") -> str:
845
926
  """Creates or registers a tenant-scoped RBAC API key (requires admin key)."""
927
+ if key != "":
928
+ validated = self._validate_api_key(key)
929
+ if validated != key:
930
+ raise ValueError("custom API key must not contain leading or trailing whitespace")
846
931
  resp = self._request_json(
847
932
  "POST",
848
933
  f"/v1/tenants/{self._esc_tenant(tenant)}/keys",
@@ -852,6 +937,9 @@ class MassEngineClient:
852
937
 
853
938
  def revoke_tenant_key(self, tenant: str, key: str) -> Dict[str, Any]:
854
939
  """Revokes a tenant-scoped RBAC API key (requires admin key)."""
940
+ validated = self._validate_api_key(key)
941
+ if not validated or validated != key:
942
+ raise ValueError("valid non-empty API key is required for revocation")
855
943
  return self._request_json(
856
944
  "DELETE",
857
945
  f"/v1/tenants/{self._esc_tenant(tenant)}/keys",
@@ -864,7 +952,25 @@ class MassEngineClient:
864
952
  quota: Union[TenantQuota, Dict[str, Any]],
865
953
  ) -> Dict[str, Any]:
866
954
  """Sets a tenant's plan tier, max_docs/max_bytes caps, max_qps limit, and suspension status."""
867
- q_dict = quota.to_dict() if isinstance(quota, TenantQuota) else quota
955
+ if isinstance(quota, TenantQuota):
956
+ q_dict = quota.to_dict()
957
+ elif isinstance(quota, dict):
958
+ q_dict = dict(quota)
959
+ if q_dict.get("max_docs") is not None:
960
+ q_dict["max_docs"] = _check_int(q_dict["max_docs"], "max_docs", 0, 0xFFFFFFFFFFFFFFFF)
961
+ if q_dict.get("max_bytes") is not None:
962
+ q_dict["max_bytes"] = _check_int(q_dict["max_bytes"], "max_bytes", 0, 0xFFFFFFFFFFFFFFFF)
963
+ if q_dict.get("burst") is not None:
964
+ q_dict["burst"] = _check_int(q_dict["burst"], "burst", 0, 0xFFFFFFFFFFFFFFFF)
965
+ if q_dict.get("max_qps") is not None:
966
+ qps = q_dict["max_qps"]
967
+ if isinstance(qps, bool) or not isinstance(qps, (int, float)) or not math.isfinite(float(qps)) or float(qps) < 0:
968
+ raise ValueError("max_qps must be a finite non-negative number")
969
+ q_dict["max_qps"] = float(qps)
970
+ if "suspended" in q_dict and q_dict["suspended"] is not None:
971
+ q_dict["suspended"] = _check_bool(q_dict["suspended"], "suspended")
972
+ else:
973
+ raise ValueError("quota must be a TenantQuota or dict")
868
974
  resp = self._request_json(
869
975
  "PUT",
870
976
  f"/v1/tenants/{self._esc_tenant(tenant)}/quota",
@@ -1,10 +1,10 @@
1
1
  [build-system]
2
- requires = ["hatchling>=1.25"]
2
+ requires = ["hatchling==1.27.0"]
3
3
  build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "massengine"
7
- version = "1.2.1"
7
+ version = "1.2.3"
8
8
  description = "Official Python SDK for the MassEngine filtered vector and hybrid search database."
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -278,10 +278,10 @@ class TestMassEngineClient(unittest.TestCase):
278
278
  _MockGatewayHandler.get_db_405 = False
279
279
 
280
280
  def test_sdk_lifecycle_and_user_agent(self) -> None:
281
- self.assertEqual(massengine.__version__, "1.2.1")
281
+ self.assertEqual(massengine.__version__, "1.2.3")
282
282
  admin = MassEngineClient(base_url=self.base_url, api_key=" admin-key ")
283
283
  self.assertEqual(admin.health()["status"], "ok")
284
- self.assertEqual(_MockGatewayHandler.last_user_agent, "massengine-python/1.2.1")
284
+ self.assertEqual(_MockGatewayHandler.last_user_agent, "massengine-python/1.2.3")
285
285
  r_ok = admin.ready()
286
286
  self.assertTrue(r_ok["ready"])
287
287
  self.assertEqual(r_ok["unavailable_shards"], [])
@@ -699,7 +699,7 @@ class TestMassEngineClient(unittest.TestCase):
699
699
  def test_api_parity_v121(self) -> None:
700
700
  default_client = MassEngineClient()
701
701
  self.assertEqual(default_client.base_url, "http://localhost:8080")
702
- self.assertEqual(massengine.__version__, "1.2.1")
702
+ self.assertEqual(massengine.__version__, "1.2.3")
703
703
 
704
704
  # Database creation with ttl_days, time_bucket_days, append_only
705
705
  client = MassEngineClient(base_url=self.base_url, api_key="meadm_test")
@@ -745,6 +745,58 @@ class TestMassEngineClient(unittest.TestCase):
745
745
  with self.assertRaises(ValueError):
746
746
  client.batch_search([{"tenant": "acme", "vector": [1.0, 0.0], "effort": 0}])
747
747
 
748
+ # Security & parity audit v1.2.2 checks
749
+ for bad_url in [
750
+ "http://localhost:8080?",
751
+ "http://localhost:8080#",
752
+ "http://localhost:8080\\bad",
753
+ "http://:8080",
754
+ "http://localhost:8080/v1/../admin",
755
+ ]:
756
+ with self.assertRaises(ValueError, msg=f"base_url={bad_url}"):
757
+ MassEngineClient(base_url=bad_url)
758
+
759
+ with self.assertRaises(ValueError):
760
+ client.create_database("acme", "d", ttl_days=70000)
761
+ with self.assertRaises(ValueError):
762
+ client.create_database("acme", "d", ttl_days=-5)
763
+ with self.assertRaises(ValueError):
764
+ client.create_database("acme", "d", ttl_days=True) # type: ignore[arg-type]
765
+ with self.assertRaises(ValueError):
766
+ client.create_database("acme", "d", time_bucket_days=3651)
767
+ with self.assertRaises(ValueError):
768
+ client.create_database("acme", "d", append_only="false") # type: ignore[arg-type]
769
+ with self.assertRaises(ValueError):
770
+ client.ingest("acme", [])
771
+ with self.assertRaises(ValueError):
772
+ client.ingest("acme", [{"id": "no-vec"}])
773
+ with self.assertRaises(ValueError):
774
+ Doc(doc_id=1 << 44, vector=[1.0, 0.0]).to_dict()
775
+ with self.assertRaises(ValueError):
776
+ Doc(id="x", vector=[1e20, 0.0]).to_dict()
777
+ with self.assertRaises(ValueError):
778
+ Doc(id="x", vector=[1.0, 0.0], date=True).to_dict() # type: ignore[arg-type]
779
+ with self.assertRaises(ValueError):
780
+ SearchRequest(vector=[1.0, 0.0], k=0).to_dict()
781
+ with self.assertRaises(ValueError):
782
+ SearchRequest(vector=[1.0, 0.0], k=1001).to_dict()
783
+ with self.assertRaises(ValueError):
784
+ SearchRequest(vector=[1.0, 0.0], offset=-1).to_dict()
785
+ with self.assertRaises(ValueError):
786
+ SearchRequest(vector=[1.0, 0.0], categories="12").to_dict() # type: ignore[arg-type]
787
+ with self.assertRaises(ValueError):
788
+ client.batch_search([{"vector": [1.0, 0.0], "k": True}]) # type: ignore[list-item]
789
+ with self.assertRaises(ValueError):
790
+ client.patch_doc("acme", "x", category=True) # type: ignore[arg-type]
791
+ with self.assertRaises(ValueError):
792
+ client.batch_get_docs("acme", [])
793
+ with self.assertRaises(ValueError):
794
+ client.set_tenant_quota("acme", {"max_qps": -1})
795
+ with self.assertRaises(ValueError):
796
+ client.create_tenant_key("acme", " mk_bad")
797
+ with self.assertRaises(ValueError):
798
+ client.revoke_tenant_key("acme", "")
799
+
748
800
 
749
801
  if __name__ == "__main__":
750
802
  unittest.main()
File without changes
File without changes
File without changes