2023-03-15 16:21:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
|
|
|
class GenerateEmbeddings < ::Jobs::Base
|
|
|
|
def execute(args)
|
|
|
|
return unless SiteSetting.ai_embeddings_enabled
|
|
|
|
return if (topic_id = args[:topic_id]).blank?
|
|
|
|
|
|
|
|
topic = Topic.find_by_id(topic_id)
|
|
|
|
return if topic.nil? || topic.private_message? && !SiteSetting.ai_embeddings_generate_for_pms
|
2023-03-31 15:15:10 -04:00
|
|
|
post = topic.first_post
|
2023-03-15 16:21:45 -04:00
|
|
|
return if post.nil? || post.raw.blank?
|
|
|
|
|
2023-09-05 10:08:23 -04:00
|
|
|
strategy = DiscourseAi::Embeddings::Strategies::Truncation.new
|
|
|
|
vector_rep =
|
|
|
|
DiscourseAi::Embeddings::VectorRepresentations::Base.find_vector_representation.new
|
|
|
|
|
|
|
|
vector_rep.generate_topic_representation_from(topic, strategy)
|
2023-03-15 16:21:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|