Class: Langfuse::Evaluation

Inherits:
Object
  • Object
show all
Defined in:
lib/langfuse/evaluation.rb

Overview

Value object representing a single evaluation score

Returned by evaluator callables during experiment runs. Wraps a score name, value, and optional comment for persistence to the Langfuse API.

Examples:

Numeric evaluation

Evaluation.new(name: "relevance", value: 0.85)

Boolean evaluation with comment

Evaluation.new(name: "is_valid", value: true, comment: "All fields present", data_type: :boolean)

Categorical evaluation

Evaluation.new(name: "sentiment", value: "positive", data_type: :categorical)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, value:, comment: nil, data_type: :numeric, config_id: nil, metadata: nil) ⇒ Evaluation

Returns a new instance of Evaluation.

Parameters:

  • name (String)

    Score name (required, must be non-empty)

  • value (Numeric, Boolean, String)

    Score value (type depends on data_type)

  • comment (String, nil) (defaults to: nil)

    Optional comment describing the evaluation

  • data_type (Symbol) (defaults to: :numeric)

    One of :numeric, :boolean, or :categorical

  • config_id (String, nil) (defaults to: nil)

    Optional score config ID

  • metadata (Hash, nil) (defaults to: nil)

    Optional metadata hash

Raises:

  • (ArgumentError)

    if name is nil or empty

  • (ArgumentError)

    if data_type is not a valid score data type



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/langfuse/evaluation.rb', line 34

def initialize(name:, value:, comment: nil, data_type: :numeric, config_id: nil, metadata: nil)
  raise ArgumentError, "name is required" if name.to_s.empty?

  unless Types::SCORE_DATA_TYPES.key?(data_type)
    raise ArgumentError,
          "Invalid data_type: #{data_type}. Valid types: #{Types::VALID_SCORE_DATA_TYPES.join(', ')}"
  end

  validate_value!(value, data_type)

  @name = name
  @value = value
  @comment = comment
  @data_type = data_type
  @config_id = config_id
  @metadata = 
end

Instance Attribute Details

#commentString, ... (readonly)

Returns:

  • (String)

    the evaluation name

  • (Numeric, Boolean, String)

    the evaluation value

  • (String, nil)

    optional comment

  • (Symbol)

    data type (:numeric, :boolean, or :categorical)

  • (String, nil)

    optional score config ID

  • (Hash, nil)

    optional metadata



24
25
26
# File 'lib/langfuse/evaluation.rb', line 24

def comment
  @comment
end

#config_idString, ... (readonly)

Returns:

  • (String)

    the evaluation name

  • (Numeric, Boolean, String)

    the evaluation value

  • (String, nil)

    optional comment

  • (Symbol)

    data type (:numeric, :boolean, or :categorical)

  • (String, nil)

    optional score config ID

  • (Hash, nil)

    optional metadata



24
25
26
# File 'lib/langfuse/evaluation.rb', line 24

def config_id
  @config_id
end

#data_typeString, ... (readonly)

Returns:

  • (String)

    the evaluation name

  • (Numeric, Boolean, String)

    the evaluation value

  • (String, nil)

    optional comment

  • (Symbol)

    data type (:numeric, :boolean, or :categorical)

  • (String, nil)

    optional score config ID

  • (Hash, nil)

    optional metadata



24
25
26
# File 'lib/langfuse/evaluation.rb', line 24

def data_type
  @data_type
end

#metadataString, ... (readonly)

Returns:

  • (String)

    the evaluation name

  • (Numeric, Boolean, String)

    the evaluation value

  • (String, nil)

    optional comment

  • (Symbol)

    data type (:numeric, :boolean, or :categorical)

  • (String, nil)

    optional score config ID

  • (Hash, nil)

    optional metadata



24
25
26
# File 'lib/langfuse/evaluation.rb', line 24

def 
  @metadata
end

#nameString, ... (readonly)

Returns:

  • (String)

    the evaluation name

  • (Numeric, Boolean, String)

    the evaluation value

  • (String, nil)

    optional comment

  • (Symbol)

    data type (:numeric, :boolean, or :categorical)

  • (String, nil)

    optional score config ID

  • (Hash, nil)

    optional metadata



24
25
26
# File 'lib/langfuse/evaluation.rb', line 24

def name
  @name
end

#valueString, ... (readonly)

Returns:

  • (String)

    the evaluation name

  • (Numeric, Boolean, String)

    the evaluation value

  • (String, nil)

    optional comment

  • (Symbol)

    data type (:numeric, :boolean, or :categorical)

  • (String, nil)

    optional score config ID

  • (Hash, nil)

    optional metadata



24
25
26
# File 'lib/langfuse/evaluation.rb', line 24

def value
  @value
end

Instance Method Details

#to_hHash{Symbol => Object}

Returns:

  • (Hash{Symbol => Object})


53
54
55
56
# File 'lib/langfuse/evaluation.rb', line 53

def to_h
  { name: @name, value: @value, comment: @comment, data_type: @data_type,
    config_id: @config_id, metadata: @metadata }.compact
end