Class: LlmMemory::Embeddings::Openai

Inherits:
Object
  • Object
show all
Includes:
LlmMemory::Embedding, Llms::Openai
Defined in:
lib/llm_memory/embeddings/openai.rb

Instance Method Summary collapse

Methods included from Llms::Openai

#client

Methods included from LlmMemory::Embedding

included

Instance Method Details

#embed_document(text, model: "text-embedding-ada-002") ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/llm_memory/embeddings/openai.rb', line 26

def embed_document(text, model: "text-embedding-ada-002")
  res = client.embeddings(
    parameters: {
      model: model,
      input: text
    }
  )
  res["data"][0]["embedding"]
end

#embed_documents(texts, model: "text-embedding-ada-002") ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/llm_memory/embeddings/openai.rb', line 12

def embed_documents(texts, model: "text-embedding-ada-002")
  embedding_list = []
  texts.each do |txt|
    res = client.embeddings(
      parameters: {
        model: model,
        input: txt
      }
    )
    embedding_list.push(res["data"][0]["embedding"])
  end
  embedding_list
end