Class: ActiveRecordVector::Providers::Custom

Inherits:
Base
  • Object
show all
Defined in:
lib/active_record_vector/providers/custom.rb

Overview

Custom provider allowing any Proc, Lambda, or custom object responding to #call or #embed

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#embed_batch, #initialize

Constructor Details

This class inherits a constructor from ActiveRecordVector::Providers::Base

Instance Method Details

#embed(text) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_record_vector/providers/custom.rb', line 7

def embed(text)
  callable = options[:with] || options[:proc]
  raise Error, "Custom provider requires options[:with] to be a Proc or object responding to #call" unless callable

  if callable.respond_to?(:call)
    callable.call(text)
  elsif callable.respond_to?(:embed)
    callable.embed(text)
  else
    raise Error, "Custom provider options[:with] must respond to #call or #embed"
  end
end