Class: Hyrum::Validators::SemanticSimilarity
- Inherits:
-
Object
- Object
- Hyrum::Validators::SemanticSimilarity
- Defined in:
- lib/hyrum/validators/semantic_similarity.rb
Instance Attribute Summary collapse
-
#ai_model ⇒ Object
readonly
Returns the value of attribute ai_model.
-
#ai_service ⇒ Object
readonly
Returns the value of attribute ai_service.
-
#original_message ⇒ Object
readonly
Returns the value of attribute original_message.
-
#variations ⇒ Object
readonly
Returns the value of attribute variations.
Instance Method Summary collapse
- #calculate ⇒ Object
-
#initialize(original_message, variations, ai_service, ai_model) ⇒ SemanticSimilarity
constructor
A new instance of SemanticSimilarity.
- #supports_embeddings? ⇒ Boolean
Constructor Details
#initialize(original_message, variations, ai_service, ai_model) ⇒ SemanticSimilarity
Returns a new instance of SemanticSimilarity.
11 12 13 14 15 16 |
# File 'lib/hyrum/validators/semantic_similarity.rb', line 11 def initialize(, variations, ai_service, ai_model) @original_message = @variations = variations @ai_service = ai_service @ai_model = ai_model end |
Instance Attribute Details
#ai_model ⇒ Object (readonly)
Returns the value of attribute ai_model.
9 10 11 |
# File 'lib/hyrum/validators/semantic_similarity.rb', line 9 def ai_model @ai_model end |
#ai_service ⇒ Object (readonly)
Returns the value of attribute ai_service.
9 10 11 |
# File 'lib/hyrum/validators/semantic_similarity.rb', line 9 def ai_service @ai_service end |
#original_message ⇒ Object (readonly)
Returns the value of attribute original_message.
9 10 11 |
# File 'lib/hyrum/validators/semantic_similarity.rb', line 9 def @original_message end |
#variations ⇒ Object (readonly)
Returns the value of attribute variations.
9 10 11 |
# File 'lib/hyrum/validators/semantic_similarity.rb', line 9 def variations @variations end |
Instance Method Details
#calculate ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/hyrum/validators/semantic_similarity.rb', line 18 def calculate return 100.0 if variations.empty? if else calculate_with_fallback end end |
#supports_embeddings? ⇒ Boolean
28 29 30 31 32 33 34 35 |
# File 'lib/hyrum/validators/semantic_similarity.rb', line 28 def # Check if RubyLLM has any embedding models available in the current registry # User is responsible for calling RubyLLM.models.refresh! if needed RubyLLM.models..any? rescue StandardError # If we can't check the registry, assume embeddings aren't available false end |