@@ -294,6 +294,8 @@ In addition to the core {+language+} objects, BSON also provides some special ty
294294specific to the specification. The following sections describe other
295295types that are supported in the driver.
296296
297+ .. _ruby-bson-binary:
298+
297299BSON::Binary
298300~~~~~~~~~~~~
299301
@@ -314,8 +316,19 @@ the bytes encode a particular type of data:
314316 BSON::Binary.new("binary_string", :user)
315317 # => <BSON::Binary:0x47113101225420 type=user data=0x62696e6172795f73...>
316318
317- The valid subtype specifications are ``:generic``, ``:function``,
318- ``:old``, ``:uuid_old``, ``:uuid``, ``:md5``, and ``:user``.
319+ The following list provides the valid subtype specifications:
320+
321+ - ``:generic``
322+ - ``:function``
323+ - ``:old``
324+ - ``:uuid_old``
325+ - ``:uuid``
326+ - ``:md5``
327+ - ``:ciphertext``
328+ - ``:column``
329+ - ``:sensitive``
330+ - ``:vector``
331+ - ``:user``
319332
320333You can use the ``data`` and ``type`` attributes to retrieve a
321334``Binary`` object's data and the subtype, as shown in the following code:
@@ -455,20 +468,20 @@ BSON::Vector
455468Starting in ``bson`` v5.1, you can use the
456469``BSON::Vector`` type to represent vectors of numeric values.
457470
458- You can create a ``Vector`` object to store values of the following
471+ You can create a ``BSON:: Vector`` object to store values of the following
459472types:
460473
461474- ``int8``
462475- ``float32``
463476- ``packed_bit``
464477
465- You can use the optional ``dtype`` and ``padding`` atrributes to specify
478+ You can use the optional ``dtype`` and ``padding`` attributes to specify
466479the data type of the vector and the bit padding, respectively.
467- ``Vector`` itself is a container to hold your array values, type
468- information, and padding specification. ``Vector`` objects are
480+ ``BSON:: Vector`` itself is a container to hold your array values, type
481+ information, and padding specification. ``BSON:: Vector`` objects are
469482serialized as normal arrays in MongoDB.
470483
471- The following example demonstrates how to create a ``Vector`` object:
484+ The following example demonstrates how to create a ``BSON:: Vector`` object:
472485
473486.. code-block:: ruby
474487
@@ -477,23 +490,25 @@ The following example demonstrates how to create a ``Vector`` object:
477490Convert Vectors to Binary
478491`````````````````````````
479492
480- You can convert ``Vector`` and array objects to ``BSON::Binary`` objects
481- so they are serialized as BSON binary vector (subtype 9) instances. Use
482- the ``Binary.from_vector`` method, as shown in the following code:
493+ You can convert ``BSON::Vector`` and array objects to
494+ :ref:`ruby-bson-binary` objects so they are serialized as BSON binary
495+ vector (subtype 9) instances. Use the ``BSON::Binary.from_vector``
496+ method, as shown in the following code:
483497
484498.. code-block:: ruby
499+
500+ vector = BSON::Vector.new([ -0.0016261312, -0.028070757, -0.011342932 ], :float32)
501+ BSON::Binary.from_vector(vector)
485502
486- BSON::Binary.from_vector([ -0.0016261312, -0.028070757, -0.011342932 ], :float32)
487-
488- Using the ``Binary`` type improves storage efficiency. To learn
503+ Using the ``BSON::Binary`` type improves storage efficiency. To learn
489504more, see the `BSON specification <https://bsonspec.org/spec.html>`__.
490505
491- You can convert a ``Binary`` to a ``Vector`` by using the
492- ``Binary.as_vector`` method.
506+ You can convert a ``BSON:: Binary`` to a ``BSON:: Vector`` by using the
507+ ``BSON:: Binary.as_vector`` method.
493508
494509.. tip:: {+avs+}
495510
496- To view an example that leverages the ``Binary`` type
511+ To view an example that leverages the ``BSON:: Binary`` type
497512 to perform efficient {+avs+} queries, see the :ref:`ruby-avs-examples`.
498513
499514BSON::Code
0 commit comments