Class: Phronomy::VectorStore::Embeddings::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/phronomy/vector_store/embeddings/base.rb

Overview

Public extension SPI for embedding adapters.

Concrete implementations override #embed. Phronomy owns the async bridge: #embed_async routes the synchronous implementation through the bounded OffloadPool and returns a Task.

Direct Known Subclasses

RubyLLMEmbeddings

Instance Method Summary collapse

Instance Method Details

#embed(text, cancellation_token = nil) ⇒ Array<Float>

Embed the given text and return a vector representation.

Parameters:

Returns:

  • (Array<Float>)

    the embedding vector

Raises:

  • (NotImplementedError)


20
21
22
23
# File 'lib/phronomy/vector_store/embeddings/base.rb', line 20

def embed(text, cancellation_token = nil)
  cancellation_token&.raise_if_cancelled!
  raise NotImplementedError, "#{self.class}#embed is not implemented"
end

#embed_async(text, cancellation_token = nil, timeout: nil) ⇒ Phronomy::Task

Submits an #embed call to OffloadPool.

Parameters:

Returns:



32
33
34
35
36
37
38
39
40
# File 'lib/phronomy/vector_store/embeddings/base.rb', line 32

def embed_async(text, cancellation_token = nil, timeout: nil)
  Phronomy::Runtime.instance.offload.submit(
    timeout: timeout,
    cancellation_token: cancellation_token,
    on_full: :raise
  ) do
    embed(text, cancellation_token)
  end
end