2023-03-15 17:21:45 -03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
|
|
|
class GenerateEmbeddings < ::Jobs::Base
|
2023-10-26 12:07:37 -03:00
|
|
|
sidekiq_options queue: "low"
|
|
|
|
|
2023-03-15 17:21:45 -03:00
|
|
|
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 16:15:10 -03:00
|
|
|
post = topic.first_post
|
2023-03-15 17:21:45 -03:00
|
|
|
return if post.nil? || post.raw.blank?
|
|
|
|
|
2023-09-05 11:08:23 -03:00
|
|
|
strategy = DiscourseAi::Embeddings::Strategies::Truncation.new
|
|
|
|
vector_rep =
|
2023-09-07 11:54:43 -03:00
|
|
|
DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation(strategy)
|
2023-09-05 11:08:23 -03:00
|
|
|
|
2023-09-07 11:54:43 -03:00
|
|
|
vector_rep.generate_topic_representation_from(topic)
|
2023-03-15 17:21:45 -03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|