Module: Ragdoll::Core

Extended by:
SingleForwardable
Defined in:
lib/ragdoll/core.rb,
lib/ragdoll/core/model.rb,
lib/ragdoll/core/client.rb,
lib/ragdoll/core/errors.rb,
lib/ragdoll/core/version.rb,
lib/ragdoll/core/database.rb,
lib/ragdoll/core/configuration.rb

Defined Under Namespace

Classes: Client, Configuration, ConfigurationError, Database, DocumentError, EmbeddingError, Error, SearchError

Constant Summary collapse

Model =

Model represents a provider and model name. It is initialized with a string in the format “provider/model”. The provider is optional. Can be initialized with nil or empty string.

Data.define(:name) do
  def initialize(name:)
    # Handle case where a Model object is passed instead of a string
    if name.is_a?(Model)
      super(name: name.name)
    else
      super(name: name)
    end
  end
  # @return [Symbol, nil] the provider part of the name, or nil if not present.
  def provider
    return nil if name.nil? || name.empty?

    parts = name.split("/", 2)
    return nil if parts.length < 2 || parts.first.empty?

    parts.first.to_sym
  end

  # @return [String, nil] the model part of the name, or nil if name is nil/empty.
  def model
    return nil if name.nil? || name.empty?

    parts = name.split("/", 2)
    parts.length < 2 ? name : parts.last
  end

  # @return [String] the original name string, or empty string if name is nil.
  def to_s
    name.nil? ? "" : name
  end

  # @return [Boolean] true if the name is nil or empty.
  def empty?
    name.nil? || name.empty?
  end

  # @return [Hash] a hash representation of the model.
  def to_h
    { provider: provider, model: model }
  end

  # YAML serialization - save as string name
  def encode_with(coder)
    coder.scalar = name
  end
end
VERSION =
"0.1.12"

Class Method Summary collapse

Class Method Details

.client(_config = nil) ⇒ Object

Factory method for creating clients



86
87
88
# File 'lib/ragdoll/core.rb', line 86

def self.client(_config = nil)
  Client.new
end

.configObject



67
68
69
# File 'lib/ragdoll/core.rb', line 67

def self.config
  @config ||= Configuration.new
end

.configurationObject



71
72
73
# File 'lib/ragdoll/core.rb', line 71

def self.configuration
  config
end

.configure {|config| ... } ⇒ Object

Yields:



75
76
77
# File 'lib/ragdoll/core.rb', line 75

def self.configure
  yield(config)
end

.default_clientObject



96
97
98
# File 'lib/ragdoll/core.rb', line 96

def self.default_client
  @default_client ||= Client.new
end

.reset_configuration!Object

Reset configuration (useful for testing)



80
81
82
83
# File 'lib/ragdoll/core.rb', line 80

def self.reset_configuration!
  @config = Configuration.new
  @default_client = nil
end