Class: VoyageAI::Embed

Inherits:
Object
  • Object
show all
Defined in:
lib/voyageai/embed.rb

Overview

The response for an embeddings request that wraps the model / usage / embeddings.

Examples:

VoyageAI::Embed.new(model: "voyage-3", usage: VoyageAI::Usage.new(total_tokens: 0), embeddings: [])

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, usage:, embeddings:) ⇒ Embed

Returns a new instance of Embed.

Parameters:

  • model (String)
  • usage (Usage)
  • embeddings (Array<Embedding>)


34
35
36
37
38
# File 'lib/voyageai/embed.rb', line 34

def initialize(model:, usage:, embeddings:)
  @model = model
  @usage = usage
  @embeddings = embeddings
end

Instance Attribute Details

#embeddingsArray<Array<Float>>

Returns:

  • (Array<Array<Float>>)


19
20
21
# File 'lib/voyageai/embed.rb', line 19

def embeddings
  @embeddings
end

#modelString

Returns:

  • (String)


11
12
13
# File 'lib/voyageai/embed.rb', line 11

def model
  @model
end

#usageUsage

Returns:



15
16
17
# File 'lib/voyageai/embed.rb', line 15

def usage
  @usage
end

Class Method Details

.parse(data:) ⇒ Embed

Parameters:

  • data (Hash)

Returns:



23
24
25
26
27
28
29
# File 'lib/voyageai/embed.rb', line 23

def self.parse(data:)
  model = data["model"]
  usage = Usage.parse(data: data["usage"])
  embeddings = data["data"].map { |embedding_data| embedding_data["embedding"] }

  new(model: model, usage: usage, embeddings: embeddings)
end

Instance Method Details

#embedding(index: 0) ⇒ Array<Float>

Parameters:

  • index (Integer) (defaults to: 0)

    optional

Returns:

  • (Array<Float>)


48
49
50
# File 'lib/voyageai/embed.rb', line 48

def embedding(index: 0)
  @embeddings[index]
end

#inspectString

Returns:

  • (String)


41
42
43
# File 'lib/voyageai/embed.rb', line 41

def inspect
  "#<#{self.class.name} model=#{@model.inspect} embeddings=#{@embeddings.inspect} usage=#{@usage.inspect}>"
end