Module: Mongoid::Extensions::Vector

Defined in:
lib/mongoid/extensions/vector.rb

Overview

Adds type-casting behavior to BSON::Vector class so that a field declared with type: BSON::Vector is stored as a BSON binary of the vector subtype and read back as a BSON::Vector.

Querying by an exact vector value (e.g. where(embedding: vector)) is not supported: BSON::Vector subclasses Array, so the criteria selector treats it as a list of elements rather than a scalar. Use Atlas Vector Search ($vectorSearch) for similarity queries on vector fields.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#mongoizeBSON::Binary | nil

Turn the object from the ruby type we deal with to a Mongo friendly type.

Examples:

Mongoize the object.

object.mongoize

Returns:

  • (BSON::Binary | nil)

    The object as a vector binary.



21
22
23
# File 'lib/mongoid/extensions/vector.rb', line 21

def mongoize
  BSON::Vector.mongoize(self)
end