Module: RailsAi::Embeddable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/ai/embeddable.rb
Instance Method Summary collapse
- #generate_embedding!(field: :content, model: nil) ⇒ Object
- #similar_records(limit: 5, threshold: 0.8) ⇒ Object
Instance Method Details
#generate_embedding!(field: :content, model: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/concerns/ai/embeddable.rb', line 11 def (field: :content, model: nil) text = send(field) return if text.blank? model ||= RailsAi.config.default_model = RailsAi.provider.( texts: [text], model: model ).first .create!( content: text, embedding: , model: model, field: field.to_s ) end |
#similar_records(limit: 5, threshold: 0.8) ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/models/concerns/ai/embeddable.rb', line 30 def similar_records(limit: 5, threshold: 0.8) return [] unless .any? # This would need to be implemented based on your vector database # For now, return empty array [] end |