Skip to content

Commit d8c5113

Browse files
committed
update to accurate info about vector/binary
1 parent c9526e8 commit d8c5113

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

source/data-formats/bson.txt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,6 @@ BSON::Vector
455455
Starting in ``bson`` v5.1, you can use the
456456
``BSON::Vector`` type to represent vectors of numeric values.
457457

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-
462458
You can create a ``Vector`` object to store values of the following
463459
types:
464460

@@ -468,22 +464,36 @@ types:
468464

469465
You can use the optional ``dtype`` and ``padding`` atrributes to specify
470466
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.
471470

472471
The following example demonstrates how to create a ``Vector`` object:
473472

474473
.. code-block:: ruby
475474

476475
BSON::Vector.new([ -0.0016261312, -0.028070757, -0.011342932 ], :float32)
477476

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>`__.
480490

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.
483493

484494
.. tip:: {+avs+}
485495

486-
To view an example that leverages the ``Vector`` type
496+
To view an example that leverages the ``Binary`` type
487497
to perform efficient {+avs+} queries, see the :ref:`ruby-avs-examples`.
488498

489499
BSON::Code

0 commit comments

Comments
 (0)