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

Commit 6ad2f7b

Browse files
committed
Working deduplication
1 parent ad94cb7 commit 6ad2f7b

File tree

6 files changed

+24
-66
lines changed

6 files changed

+24
-66
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
class CreateInferredConceptsTopics < ActiveRecord::Migration[7.0]
4+
def change
5+
create_table :inferred_concepts_topics, id: false do |t|
6+
t.belongs_to :inferred_concept
7+
t.belongs_to :topic
8+
t.timestamps
9+
end
10+
end
11+
end

db/migrate/20250508183456_create_topics_inferred_concepts.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
class CreateInferredConceptsPosts < ActiveRecord::Migration[7.0]
4+
def change
5+
create_table :inferred_concepts_posts, id: false do |t|
6+
t.belongs_to :inferred_concept
7+
t.belongs_to :post
8+
t.timestamps
9+
end
10+
end
11+
end

db/migrate/20250509000001_create_posts_inferred_concepts.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/inferred_concepts/applier.rb

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -65,44 +65,6 @@ def self.post_content_for_analysis(post)
6565
content
6666
end
6767

68-
# Comprehensive method to analyze a topic and apply concepts
69-
def self.analyze_and_apply(topic)
70-
return if topic.blank?
71-
72-
# Get content to analyze
73-
content = topic_content_for_analysis(topic)
74-
75-
# Identify concepts
76-
concept_names = Finder.identify_concepts(content)
77-
78-
# Create or find concepts in the database
79-
concepts = Finder.create_or_find_concepts(concept_names)
80-
81-
# Apply concepts to the topic
82-
apply_to_topic(topic, concepts)
83-
84-
concepts
85-
end
86-
87-
# Comprehensive method to analyze a post and apply concepts
88-
def self.analyze_and_apply_post(post)
89-
return if post.blank?
90-
91-
# Get content to analyze
92-
content = post_content_for_analysis(post)
93-
94-
# Identify concepts
95-
concept_names = Finder.identify_concepts(content)
96-
97-
# Create or find concepts in the database
98-
concepts = Finder.create_or_find_concepts(concept_names)
99-
100-
# Apply concepts to the post
101-
apply_to_post(post, concepts)
102-
103-
concepts
104-
end
105-
10668
# Match a topic with existing concepts
10769
def self.match_existing_concepts(topic)
10870
return [] if topic.blank?
@@ -158,7 +120,7 @@ def self.match_concepts_to_content(content, concept_list)
158120

159121
# Use the ConceptMatcher persona to match concepts
160122
llm = DiscourseAi::Completions::Llm.default_llm
161-
persona = DiscourseAi::Personas::ConceptMatcher.new(concept_list: concept_list)
123+
persona = DiscourseAi::Personas::ConceptMatcher.new
162124
context =
163125
DiscourseAi::Personas::BotContext.new(
164126
messages: [{ type: :user, content: user_message }],

lib/inferred_concepts/manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def self.deduplicate_concepts_by_letter(per_letter_batch: 50, full_pass_batch: 1
6868
final_result.uniq!
6969

7070
# Apply the deduplicated concepts
71-
InferredConcept.destroy_all
71+
InferredConcept.where.not(name: final_result).destroy_all
7272
InferredConcept.insert_all(final_result.map { { name: it } })
7373
end
7474
end

0 commit comments

Comments
 (0)