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.



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

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

Instance Method Details

#callObject



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

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