Class: SemanticTextChunker::Embedders::Cohere

Inherits:
Base
  • Object
show all
Defined in:
lib/semantic_text_chunker/embedders/cohere.rb

Constant Summary collapse

BATCH_SIZE =
96
ENDPOINT =
"https://api.cohere.com/v1/embed"

Instance Method Summary collapse

Methods inherited from Base

#cosine_similarity

Constructor Details

#initialize(api_key:, model: "embed-english-v3.0") ⇒ Cohere

Returns a new instance of Cohere.



11
12
13
14
# File 'lib/semantic_text_chunker/embedders/cohere.rb', line 11

def initialize(api_key:, model: "embed-english-v3.0")
  @api_key = api_key
  @model   = model
end

Instance Method Details

#embed(texts) ⇒ Object



16
17
18
19
20
21
# File 'lib/semantic_text_chunker/embedders/cohere.rb', line 16

def embed(texts)
  texts.each_slice(BATCH_SIZE).flat_map do |batch|
    response = post(batch)
    response["embeddings"] || raise(EmbedderError, "No embeddings in response: #{response}")
  end
end