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

Commit 37d4c36

Browse files
committed
DEV: Follow-up from review
1 parent bfea49f commit 37d4c36

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lib/ai_helper/semantic_categorizer.rb

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def initialize(user, opts)
1111
end
1212

1313
def categories
14-
return [] if @text.blank? && !@topic_id
14+
return [] if @text.blank? && @topic_id.nil?
1515
return [] if !DiscourseAi::Embeddings.enabled?
1616

1717
candidates = nearest_neighbors
@@ -56,7 +56,7 @@ def categories
5656
end
5757

5858
def tags
59-
return [] if @text.blank? && !@topic_id
59+
return [] if @text.blank? && @topic_id.nil?
6060
return [] if !DiscourseAi::Embeddings.enabled?
6161

6262
candidates = nearest_neighbors(limit: 100)
@@ -102,13 +102,19 @@ def tags
102102

103103
def nearest_neighbors(limit: 50)
104104
if @topic_id
105-
table_name = DiscourseAi::Embeddings::Schema::TOPICS_TABLE
106-
embeddings =
107-
DB
108-
.query("SELECT embeddings::text FROM #{table_name} WHERE topic_id=#{@topic_id}")
109-
.first
110-
.embeddings
111-
raw_vector = JSON.parse(embeddings)
105+
target = Topic.find_by(id: @topic_id)
106+
embeddings = @schema.find_by_target(target)&.embeddings
107+
108+
if embeddings.blank?
109+
@text =
110+
DiscourseAi::Summarization::Strategies::TopicSummary
111+
.new(target)
112+
.targets_data
113+
.pluck(:text)
114+
raw_vector = @vector.vector_from(@text)
115+
else
116+
raw_vector = JSON.parse(embeddings)
117+
end
112118
else
113119
raw_vector = @vector.vector_from(@text)
114120
end

0 commit comments

Comments
 (0)