Class: Turbopuffer::Models::Row

Inherits:
Internal::Type::BaseModel show all
Defined in:
lib/turbopuffer/models/row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Internal::Type::BaseModel

==, #==, #[], coerce, #deconstruct_keys, #deep_to_h, dump, fields, hash, #hash, inherited, inspect, #inspect, known_fields, optional, recursively_to_h, required, #to_h, #to_json, #to_s, to_sorbet_type, #to_yaml

Methods included from Internal::Type::Converter

#coerce, coerce, #dump, dump, inspect, #inspect, meta_info, new_coerce_state, type_info

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(id: , vector: nil) ⇒ Object

A single document, in a row-based format.

Parameters:

  • id (String, Integer) (defaults to: )

    An identifier for a document.

  • vector (Array<Float>, String) (defaults to: nil)

    A vector embedding associated with a document.



25
26
27
28
29
30
31
# File 'lib/turbopuffer/models/row.rb', line 25

def method_missing(name, *args, &block)
  if @data.key?(name)
    @data[name]
  else
    super
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/turbopuffer/models/row.rb', line 25

def method_missing(name, *args, &block)
  if @data.key?(name)
    @data[name]
  else
    super
  end
end

Instance Attribute Details

#idString, Integer

An identifier for a document.

Returns:

  • (String, Integer)


10
# File 'lib/turbopuffer/models/row.rb', line 10

required :id, union: -> { Turbopuffer::ID }

#vectorArray<Float>, ...

A vector embedding associated with a document.

Returns:

  • (Array<Float>, String, nil)


16
# File 'lib/turbopuffer/models/row.rb', line 16

optional :vector, union: -> { Turbopuffer::Vector }

Instance Method Details

#[]=(key, value) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/turbopuffer/models/row.rb', line 37

def []=(key, value)
  unless key.instance_of?(Symbol)
    raise ArgumentError.new("Expected symbol key for set, got #{key.inspect}")
  end

  @data[key] = value
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/turbopuffer/models/row.rb', line 33

def respond_to_missing?(name, include_private = false)
  @data.key?(name) || super
end