16
16
import struct
17
17
from dataclasses import dataclass
18
18
from enum import Enum
19
- from typing import TYPE_CHECKING , Any , Optional , Sequence , Tuple , Type , Union
19
+ from typing import TYPE_CHECKING , Any , Optional , Sequence , Tuple , Type , Union , overload
20
20
from uuid import UUID
21
21
22
22
"""Tools for representing BSON binary data.
@@ -195,7 +195,7 @@ class UuidRepresentation:
195
195
196
196
197
197
VECTOR_SUBTYPE = 9
198
- """**(BETA)** BSON binary subtype for densely packed vector data.
198
+ """BSON binary subtype for densely packed vector data.
199
199
200
200
.. versionadded:: 4.10
201
201
"""
@@ -207,7 +207,7 @@ class UuidRepresentation:
207
207
208
208
209
209
class BinaryVectorDtype (Enum ):
210
- """**(BETA)** Datatypes of vector subtype.
210
+ """Datatypes of vector subtype.
211
211
212
212
:param FLOAT32: (0x27) Pack list of :class:`float` as float32
213
213
:param INT8: (0x03) Pack list of :class:`int` in [-128, 127] as signed int8
@@ -229,7 +229,7 @@ class BinaryVectorDtype(Enum):
229
229
230
230
@dataclass
231
231
class BinaryVector :
232
- """**(BETA)** Vector of numbers along with metadata for binary interoperability.
232
+ """Vector of numbers along with metadata for binary interoperability.
233
233
.. versionadded:: 4.10
234
234
"""
235
235
@@ -256,7 +256,7 @@ class Binary(bytes):
256
256
the difference between what should be considered binary data and
257
257
what should be considered a string when we encode to BSON.
258
258
259
- **(BETA)** Subtype 9 provides a space-efficient representation of 1-dimensional vector data.
259
+ Subtype 9 provides a space-efficient representation of 1-dimensional vector data.
260
260
Its data is prepended with two bytes of metadata.
261
261
The first (dtype) describes its data type, such as float32 or int8.
262
262
The second (padding) prescribes the number of bits to ignore in the final byte.
@@ -278,7 +278,7 @@ class Binary(bytes):
278
278
Support any bytes-like type that implements the buffer protocol.
279
279
280
280
.. versionchanged:: 4.10
281
- **(BETA)** Addition of vector subtype.
281
+ Addition of vector subtype.
282
282
"""
283
283
284
284
_type_marker = 5
@@ -397,14 +397,26 @@ def as_uuid(self, uuid_representation: int = UuidRepresentation.STANDARD) -> UUI
397
397
f"cannot decode subtype { self .subtype } to { UUID_REPRESENTATION_NAMES [uuid_representation ]} "
398
398
)
399
399
400
+ @classmethod
401
+ @overload
402
+ def from_vector (cls : Type [Binary ], vector : BinaryVector ) -> Binary :
403
+ ...
404
+
405
+ @classmethod
406
+ @overload
407
+ def from_vector (
408
+ cls : Type [Binary ], vector : list [int , float ], dtype : BinaryVectorDtype , padding : int = 0
409
+ ) -> Binary :
410
+ ...
411
+
400
412
@classmethod
401
413
def from_vector (
402
414
cls : Type [Binary ],
403
415
vector : Union [BinaryVector , list [int , float ]],
404
416
dtype : Optional [BinaryVectorDtype ] = None ,
405
417
padding : Optional [int ] = None ,
406
418
) -> Binary :
407
- """**(BETA)** Create a BSON :class:`~bson.binary.Binary` of Vector subtype.
419
+ """Create a BSON :class:`~bson.binary.Binary` of Vector subtype.
408
420
409
421
To interpret the representation of the numbers, a data type must be included.
410
422
See :class:`~bson.binary.BinaryVectorDtype` for available types and descriptions.
@@ -447,7 +459,7 @@ def from_vector(
447
459
return cls (metadata + data , subtype = VECTOR_SUBTYPE )
448
460
449
461
def as_vector (self ) -> BinaryVector :
450
- """**(BETA)** From the Binary, create a list of numbers, along with dtype and padding.
462
+ """From the Binary, create a list of numbers, along with dtype and padding.
451
463
452
464
:return: BinaryVector
453
465
0 commit comments