Module: Spectre::Embeddable::ClassMethods
- Includes:
- Logging
- Defined in:
- lib/spectre/embeddable.rb
Instance Method Summary collapse
-
#embed_all!(scope: nil, validation: nil, embedding_field: :embedding, timestamp_field: :embedded_at) ⇒ Object
Embeds the vectorized content for all records that match the optional scope and pass the validation check.
- #embeddable_field(*fields) ⇒ Object
- #embeddable_fields ⇒ Object
Methods included from Logging
#log_debug, #log_error, #log_info, #logger
Instance Method Details
#embed_all!(scope: nil, validation: nil, embedding_field: :embedding, timestamp_field: :embedded_at) ⇒ Object
Embeds the vectorized content for all records that match the optional scope and pass the validation check. Saves the embedding and timestamp to the specified fields. Also counts the number of successful and failed embeddings.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/spectre/embeddable.rb', line 80 def (scope: nil, validation: nil, embedding_field: :embedding, timestamp_field: :embedded_at) records = scope ? instance_exec(&scope) : all success_count = 0 failure_count = 0 records.each do |record| begin record.( validation: validation, embedding_field: , timestamp_field: ) success_count += 1 rescue EmbeddingValidationError => e log_error("Failed to embed record #{record.id}: #{e.}") failure_count += 1 rescue => e log_error("Unexpected error embedding record #{record.id}: #{e.}") failure_count += 1 end end puts "Successfully embedded #{success_count} records." puts "Failed to embed #{failure_count} records." end |
#embeddable_field(*fields) ⇒ Object
55 56 57 |
# File 'lib/spectre/embeddable.rb', line 55 def (*fields) @embeddable_fields = fields end |
#embeddable_fields ⇒ Object
59 60 61 |
# File 'lib/spectre/embeddable.rb', line 59 def @embeddable_fields ||= [] end |