Class: RubyLLM::SemanticRouter::Strategies::Semantic::CustomSearchMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyllm/semantic_router/strategies/semantic.rb

Overview

Wrapper for custom search results (from find_examples callable) Accepts hashes or objects with agent_name, example_text, distance/score

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ CustomSearchMatch

Returns a new instance of CustomSearchMatch.



202
203
204
# File 'lib/rubyllm/semantic_router/strategies/semantic.rb', line 202

def initialize(result)
  @result = result
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



200
201
202
# File 'lib/rubyllm/semantic_router/strategies/semantic.rb', line 200

def result
  @result
end

Instance Method Details

#agent_nameObject



206
207
208
# File 'lib/rubyllm/semantic_router/strategies/semantic.rb', line 206

def agent_name
  fetch(:agent_name) || fetch(:agent)
end

#distanceObject



214
215
216
217
218
219
220
221
222
223
# File 'lib/rubyllm/semantic_router/strategies/semantic.rb', line 214

def distance
  # Support both distance (lower is better) and score (higher is better)
  if (d = fetch(:distance))
    d
  elsif (s = fetch(:score))
    1.0 - s  # Convert score to distance
  else
    0.0
  end
end

#example_textObject



210
211
212
# File 'lib/rubyllm/semantic_router/strategies/semantic.rb', line 210

def example_text
  fetch(:example_text) || fetch(:text)
end

#neighbor_distanceObject



225
226
227
# File 'lib/rubyllm/semantic_router/strategies/semantic.rb', line 225

def neighbor_distance
  distance
end