Skip to content

Vector

A dense array of numeric values stored in a binary storage efficient for storage and retrieval.

Vectors are effectively used to represent data in artificial intelligence, machine learning, semantic search, computer vision, and natural language processing applications.

All values within the vector must be of the same type.

Comparison with BSON arrays

BSON arrays are serialized as objects, where the keys are integers (but still encoded as UTF8 strings). Arrays have a minimum overhead of 3 bytes per stored element.

Vectors are serialized contiguously, so there is no overhead per element.

However, arrays and vectors are not interchangeable. Most MongoDB operators expect one or the other, but will not work with both.

External resources

Inheritors

Types

Companion

object Companion

Serializer

@LowLevelApi



object Serializer : KSerializer<Vector> 

Default serializer for Vector.

Properties

padding

@LowLevelApi



abstract val padding: Byte

The number of bits in the final byte of raw that are to be ignored.

This is useful for types that don't fit in multiples of 8 bits.

For more information on this field, read the specification.

raw

@LowLevelApi



abstract val raw: ByteArray

The raw data stored in this vector.

When reading this property, remember to take into account any declared <strong>padding</strong>!

For more information on this field, read the specification.

type

@LowLevelApi



abstract val type: Byte

The type of the elements in the vector (called dtype in the specification).

Currently, the following types are implemented:

In most situations, users of this library should use is checks with one of the implementing subclasses rather than attempting to match on this property.

Functions

toBinaryData

@LowLevelApi



open fun toBinaryData(): ByteArray

Converts this Vector into a ByteArray that fits into the content of BsonType.BinaryData.

Vector is the binary subtype 0x09.