Skip to content

Commit

Permalink
FIX: AI Helper category / tag suggestion when user does not categorie…
Browse files Browse the repository at this point in the history
…s muted (#1042)
  • Loading branch information
xfalcox authored Dec 23, 2024
1 parent ceac6e5 commit 792df58
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/ai_helper/semantic_categorizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ def nearest_neighbors(limit: 100)
schema
.asymmetric_similarity_search(raw_vector, limit: limit, offset: 0) do |builder|
builder.join("topics t on t.id = topic_id")
builder.where(<<~SQL, exclude_category_ids: muted_category_ids.map(&:to_i))
t.category_id NOT IN (:exclude_category_ids) AND
t.category_id NOT IN (SELECT categories.id FROM categories WHERE categories.parent_category_id IN (:exclude_category_ids))
SQL
unless muted_category_ids.empty?
builder.where(<<~SQL, exclude_category_ids: muted_category_ids.map(&:to_i))
t.category_id NOT IN (:exclude_category_ids) AND
t.category_id NOT IN (SELECT categories.id FROM categories WHERE categories.parent_category_id IN (:exclude_category_ids))
SQL
end
end
.map { |r| [r.topic_id, r.distance] }
end
Expand Down

0 comments on commit 792df58

Please sign in to comment.