@@ -455,10 +455,6 @@ BSON::Vector
455
455
Starting in ``bson`` v5.1, you can use the
456
456
``BSON::Vector`` type to represent vectors of numeric values.
457
457
458
- Because this type is serialized as a BSON binary vector (subtype 9), you
459
- can use the ``Vector`` type for improved storage efficiency. To learn
460
- more, see the `BSON specification <https://bsonspec.org/spec.html>`__.
461
-
462
458
You can create a ``Vector`` object to store values of the following
463
459
types:
464
460
@@ -468,22 +464,36 @@ types:
468
464
469
465
You can use the optional ``dtype`` and ``padding`` atrributes to specify
470
466
the 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
469
+ serialized as normal arrays in MongoDB.
471
470
472
471
The following example demonstrates how to create a ``Vector`` object:
473
472
474
473
.. code-block:: ruby
475
474
476
475
BSON::Vector.new([ -0.0016261312, -0.028070757, -0.011342932 ], :float32)
477
476
478
- The following list describes some methods that you can use
479
- to handle conversions between ``BSON::Binary`` and ``BSON::Vector``:
477
+ Convert Vectors to Binary
478
+ `````````````````````````
479
+
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:
483
+
484
+ .. code-block:: ruby
485
+
486
+ BSON::Binary.from_vector([ -0.0016261312, -0.028070757, -0.011342932 ], :float32)
487
+
488
+ Using the ``Binary`` type improves storage efficiency. To learn
489
+ more, see the `BSON specification <https://bsonspec.org/spec.html>`__.
480
490
481
- - ``Binary.as_vector``: Decodes binary data as a ``Vector`` object
482
- - ``Binary.from_vector``: Constructs a binary object from a ``Vector`` object
491
+ You can convert a ``Binary`` to a ``Vector`` by using the
492
+ ``Binary.as_vector`` method.
483
493
484
494
.. tip:: {+avs+}
485
495
486
- To view an example that leverages the ``Vector `` type
496
+ To view an example that leverages the ``Binary `` type
487
497
to perform efficient {+avs+} queries, see the :ref:`ruby-avs-examples`.
488
498
489
499
BSON::Code
0 commit comments