From 792df58fbc39ab643b49c968d86e13e543ed18ab Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Mon, 23 Dec 2024 15:58:26 -0300 Subject: [PATCH] FIX: AI Helper category / tag suggestion when user does not categories muted (#1042) --- lib/ai_helper/semantic_categorizer.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/ai_helper/semantic_categorizer.rb b/lib/ai_helper/semantic_categorizer.rb index b226b01b..effb4018 100644 --- a/lib/ai_helper/semantic_categorizer.rb +++ b/lib/ai_helper/semantic_categorizer.rb @@ -109,10 +109,12 @@ module DiscourseAi 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