Class: Boxcars::VectorStore::EmbedViaOpenAI

Inherits:
Object
  • Object
show all
Includes:
Boxcars::VectorStore
Defined in:
lib/boxcars/vector_store/embed_via_open_ai.rb

Instance Method Summary collapse

Methods included from Boxcars::VectorStore

included

Constructor Details

#initialize(texts:, client:, model: 'text-embedding-ada-002') ⇒ EmbedViaOpenAI

Returns a new instance of EmbedViaOpenAI.



10
11
12
13
14
15
# File 'lib/boxcars/vector_store/embed_via_open_ai.rb', line 10

def initialize(texts:, client:, model: 'text-embedding-ada-002')
  validate_params(texts, client)
  @texts = texts
  @client = client
  @model = model
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
# File 'lib/boxcars/vector_store/embed_via_open_ai.rb', line 17

def call
  texts.map do |text|
    embedding = embedding_with_retry(model: model, input: strip_new_lines(text))
    {
      embedding: embedding,
      dim: embedding.size
    }
  end
end