FEATURE: Setting to control per post embeddings (#439)

* FEATURE: Setting to control per post embeddings
This commit is contained in:
Rafael dos Santos Silva 2024-01-23 22:09:27 -03:00 committed by GitHub
parent 797f5971b6
commit 04bc402aae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 3 deletions

View File

@ -65,6 +65,8 @@ module Jobs
return if rebaked >= limit
return unless SiteSetting.ai_embeddings_per_post_enabled
# Now for posts
table_name = vector_rep.post_table_name

View File

@ -239,6 +239,7 @@ discourse_ai:
- multilingual-e5-large
- bge-large-en
- gemini
ai_embeddings_per_post_enabled: false
ai_embeddings_generate_for_pms: false
ai_embeddings_semantic_related_topics_enabled:
default: false

View File

@ -44,7 +44,8 @@ module DiscourseAi
# embeddings generation.
callback =
Proc.new do |target|
if SiteSetting.ai_embeddings_enabled
if SiteSetting.ai_embeddings_enabled &&
(target.is_a?(Topic) || SiteSetting.ai_embeddings_per_post_enabled)
Jobs.enqueue(
:generate_embeddings,
target_id: target.id,

View File

@ -16,10 +16,16 @@ describe DiscourseAi::Embeddings::EntryPoint do
it "queues a job on create if embeddings is enabled" do
SiteSetting.ai_embeddings_enabled = true
expect { creator.create }.to change(Jobs::GenerateEmbeddings.jobs, :size).by(2) # topic_created and post_created
expect { creator.create }.to change(Jobs::GenerateEmbeddings.jobs, :size).by(1) # topic_created
end
it "does nothing if sentiment analysis is disabled" do
it "queues two jobs on create if embeddings is enabled" do
SiteSetting.ai_embeddings_enabled = true
expect { creator.create }.to change(Jobs::GenerateEmbeddings.jobs, :size).by(1) # topic_created AND post_created
end
it "does nothing if embeddings analysis is disabled" do
SiteSetting.ai_embeddings_enabled = false
expect { creator.create }.not_to change(Jobs::GenerateEmbeddings.jobs, :size)