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

Commit faa8e6e

Browse files
authored
FIX: Embeddings backfill rake task was using old code (#1084)
1 parent e2e753d commit faa8e6e

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

lib/tasks/modules/embeddings/database.rake

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
# frozen_string_literal: true
22

33
desc "Backfill embeddings for all topics and posts"
4-
task "ai:embeddings:backfill", %i[model concurrency] => [:environment] do |_, args|
4+
task "ai:embeddings:backfill", %i[embedding_def_id concurrency] => [:environment] do |_, args|
55
public_categories = Category.where(read_restricted: false).pluck(:id)
66

7-
if args[:model].present?
8-
strategy = DiscourseAi::Embeddings::Strategies::Truncation.new
9-
vector_rep =
10-
DiscourseAi::Embeddings::VectorRepresentations::Base.find_representation(args[:model]).new(
11-
strategy,
12-
)
7+
if args[:embedding_def_id].present?
8+
vdef = EmbeddingDefinition.find(args[:embedding_def_id])
9+
vector_rep = DiscourseAi::Embeddings::Vector.new(vdef)
1310
else
14-
vector_rep = DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation
11+
vector_rep = DiscourseAi::Embeddings::Vector.instance
1512
end
16-
table_name = DiscourseAi::Embeddings::Schema::TOPICS_TABLE
13+
topics_table_name = DiscourseAi::Embeddings::Schema::TOPICS_TABLE
1714

1815
topics =
1916
Topic
20-
.joins("LEFT JOIN #{table_name} ON #{table_name}.topic_id = topics.id")
21-
.where("#{table_name}.topic_id IS NULL")
17+
.joins("LEFT JOIN #{topics_table_name} ON #{topics_table_name}.topic_id = topics.id")
18+
.where("#{topics_table_name}.topic_id IS NULL")
2219
.where("category_id IN (?)", public_categories)
2320
.where(deleted_at: nil)
2421
.order("topics.id DESC")
@@ -29,11 +26,11 @@ task "ai:embeddings:backfill", %i[model concurrency] => [:environment] do |_, ar
2926
end
3027
end
3128

32-
table_name = vector_rep.post_table_name
29+
posts_table_name = DiscourseAi::Embeddings::Schema::POSTS_TABLE
3330
posts =
3431
Post
35-
.joins("LEFT JOIN #{table_name} ON #{table_name}.post_id = posts.id")
36-
.where("#{table_name}.post_id IS NULL")
32+
.joins("LEFT JOIN #{posts_table_name} ON #{posts_table_name}.post_id = posts.id")
33+
.where("#{posts_table_name}.post_id IS NULL")
3734
.where(deleted_at: nil)
3835
.order("posts.id DESC")
3936

0 commit comments

Comments
 (0)