Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 3ab9c6c

Browse files
Merge branch 'main' into ux/use-d-stat-tiles
2 parents ddad365 + 94b85ec commit 3ab9c6c

36 files changed

+533
-618
lines changed

app/jobs/regular/digest_rag_upload.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ def execute(args)
1818
target = target_type.constantize.find_by(id: target_id)
1919
return if !target
2020

21-
truncation = DiscourseAi::Embeddings::Strategies::Truncation.new
22-
vector_rep =
23-
DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation(truncation)
21+
vector_rep = DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation
2422

2523
tokenizer = vector_rep.tokenizer
2624
chunk_tokens = target.rag_chunk_tokens

app/jobs/regular/fast_track_topic_gist.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def execute(args)
1414

1515
summarizer = DiscourseAi::Summarization.topic_gist(topic)
1616
gist = summarizer.existing_summary
17-
return if gist.present? && !gist.outdated
17+
return if gist.present? && (!gist.outdated || gist.created_at >= 5.minutes.ago)
1818

1919
summarizer.force_summarize(Discourse.system_user)
2020
end

app/jobs/regular/generate_embeddings.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ def execute(args)
1616
return if topic.private_message? && !SiteSetting.ai_embeddings_generate_for_pms
1717
return if post.raw.blank?
1818

19-
strategy = DiscourseAi::Embeddings::Strategies::Truncation.new
20-
vector_rep =
21-
DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation(strategy)
19+
vector_rep = DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation
2220

2321
vector_rep.generate_representation_from(target)
2422
end

app/jobs/regular/generate_rag_embeddings.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class GenerateRagEmbeddings < ::Jobs::Base
88
def execute(args)
99
return if (fragments = RagDocumentFragment.where(id: args[:fragment_ids].to_a)).empty?
1010

11-
truncation = DiscourseAi::Embeddings::Strategies::Truncation.new
12-
vector_rep =
13-
DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation(truncation)
11+
vector_rep = DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation
1412

1513
# generate_representation_from checks compares the digest value to make sure
1614
# the embedding is only generated once per fragment unless something changes.

app/jobs/scheduled/embeddings_backfill.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ def execute(args)
2020

2121
rebaked = 0
2222

23-
strategy = DiscourseAi::Embeddings::Strategies::Truncation.new
24-
vector_rep =
25-
DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation(strategy)
26-
table_name = vector_rep.topic_table_name
23+
vector_rep = DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation
24+
table_name = DiscourseAi::Embeddings::Schema::TOPICS_TABLE
2725

2826
topics =
2927
Topic
@@ -41,7 +39,7 @@ def execute(args)
4139
relation = topics.where(<<~SQL).limit(limit - rebaked)
4240
#{table_name}.model_version < #{vector_rep.version}
4341
OR
44-
#{table_name}.strategy_version < #{strategy.version}
42+
#{table_name}.strategy_version < #{vector_rep.strategy_version}
4543
SQL
4644

4745
rebaked += populate_topic_embeddings(vector_rep, relation)
@@ -63,7 +61,7 @@ def execute(args)
6361
return unless SiteSetting.ai_embeddings_per_post_enabled
6462

6563
# Now for posts
66-
table_name = vector_rep.post_table_name
64+
table_name = DiscourseAi::Embeddings::Schema::POSTS_TABLE
6765
posts_batch_size = 1000
6866

6967
posts =
@@ -90,7 +88,7 @@ def execute(args)
9088
.where(<<~SQL)
9189
#{table_name}.model_version < #{vector_rep.version}
9290
OR
93-
#{table_name}.strategy_version < #{strategy.version}
91+
#{table_name}.strategy_version < #{vector_rep.strategy_version}
9492
SQL
9593
.limit(limit - rebaked)
9694
.pluck(:id)
@@ -121,7 +119,8 @@ def execute(args)
121119
def populate_topic_embeddings(vector_rep, topics, force: false)
122120
done = 0
123121

124-
topics = topics.where("#{vector_rep.topic_table_name}.topic_id IS NULL") if !force
122+
topics =
123+
topics.where("#{DiscourseAi::Embeddings::Schema::TOPICS_TABLE}.topic_id IS NULL") if !force
125124

126125
ids = topics.pluck("topics.id")
127126
batch_size = 1000

app/jobs/scheduled/summaries_backfill.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def execute(_args)
1414

1515
if SiteSetting.ai_summary_gists_enabled
1616
gist_t = AiSummary.summary_types[:gist]
17+
1718
backfill_candidates(gist_t)
1819
.limit(current_budget(gist_t))
1920
.each do |topic|
@@ -42,8 +43,13 @@ def backfill_candidates(summary_type)
4243
SQL
4344
.where("topics.created_at > current_timestamp - INTERVAL '#{max_age_days.to_i} DAY'")
4445
.where(
45-
"ais.id IS NULL OR UPPER(ais.content_range) < topics.highest_post_number + 1",
46-
) # (1..1) gets stored ad (1..2).
46+
<<~SQL, # (1..1) gets stored ad (1..2).
47+
ais.id IS NULL OR (
48+
UPPER(ais.content_range) < topics.highest_post_number + 1
49+
AND ais.created_at < (current_timestamp - INTERVAL '5 minutes')
50+
)
51+
SQL
52+
)
4753
.order("ais.created_at DESC NULLS FIRST, topics.last_posted_at DESC")
4854
end
4955

app/models/rag_document_fragment.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ def update_target_uploads(target, upload_ids)
3939
end
4040

4141
def indexing_status(persona, uploads)
42-
truncation = DiscourseAi::Embeddings::Strategies::Truncation.new
43-
vector_rep =
44-
DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation(truncation)
45-
46-
embeddings_table = vector_rep.rag_fragments_table_name
42+
embeddings_table = DiscourseAi::Embeddings::Schema.for(self).table
4743

4844
results =
4945
DB.query(

assets/javascripts/discourse/services/gists.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@ export default class Gists extends Service {
77
@tracked preference = localStorage.getItem("topicListLayout");
88

99
get shouldShow() {
10-
const currentRoute = this.router.currentRoute.name;
11-
const isDiscovery = currentRoute.includes("discovery");
12-
const isNotCategories = !currentRoute.includes("categories");
13-
const gistsAvailable =
14-
this.router.currentRoute.attributes?.list?.topics?.some(
15-
(topic) => topic.ai_topic_gist
16-
);
17-
18-
return isDiscovery && isNotCategories && gistsAvailable;
10+
return this.router.currentRoute.attributes?.list?.topics?.some(
11+
(topic) => topic.ai_topic_gist
12+
);
1913
}
2014

2115
setPreference(value) {

config/locales/server.en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ en:
1212
flagged_post: |
1313
<div>Response from the model:</div>
1414
<p>%%LLM_RESPONSE%%</p>
15-
<b>Triggered by the <a href="/admin/plugins/discourse-automation/%%AUTOMATION_ID%%">%%AUTOMATION_NAME%%</a> rule.</b>
15+
<b>Triggered by the <a href="%{base_path}/admin/plugins/discourse-automation/%%AUTOMATION_ID%%">%%AUTOMATION_NAME%%</a> rule.</b>
1616
llm_report:
1717
title: Periodic report using AI
1818
description: "Periodic report based on a large language model"

db/migrate/20230710171143_migrate_embeddings_from_dedicated_database.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def up
1414
].map { |k| k.new(truncation) }
1515

1616
vector_reps.each do |vector_rep|
17-
new_table_name = vector_rep.topic_table_name
17+
new_table_name = DiscourseAi::Embeddings::Schema::TOPICS_TABLE
1818
old_table_name = "topic_embeddings_#{vector_rep.name.underscore}"
1919

2020
begin

0 commit comments

Comments
 (0)