FIX: Tag/category suggestion broke in 2c0f535 (#198)

This commit is contained in:
Rafael dos Santos Silva 2023-09-05 14:15:01 -03:00 committed by GitHub
parent ae0238c616
commit ee734a340a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 13 deletions

View File

@ -11,12 +11,7 @@ module DiscourseAi
return [] if @text.blank?
return [] unless SiteSetting.ai_embeddings_enabled
strategy = DiscourseAi::Embeddings::Strategies::Truncation.new
vector_rep =
DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation(strategy)
candidates =
vector_rep.asymmetric_semantic_search(@text, limit: 100, offset: 0, return_distance: true)
candidates = nearest_neighbors(limit: 100)
candidate_ids = candidates.map(&:first)
::Topic
@ -41,13 +36,7 @@ module DiscourseAi
return [] if @text.blank?
return [] unless SiteSetting.ai_embeddings_enabled
candidates =
::DiscourseAi::Embeddings::SemanticSearch.new(nil).asymmetric_semantic_search(
@text,
100,
0,
return_distance: true,
)
candidates = nearest_neighbors(limit: 100)
candidate_ids = candidates.map(&:first)
::Topic
@ -70,6 +59,23 @@ module DiscourseAi
.sort_by { |c| -c[:score] }
.take(5)
end
private
def nearest_neighbors(limit: 100)
strategy = DiscourseAi::Embeddings::Strategies::Truncation.new
vector_rep =
DiscourseAi::Embeddings::VectorRepresentations::Base.current_representation(strategy)
raw_vector = vector_rep.vector_from(@text)
vector_rep.asymmetric_topics_similarity_search(
raw_vector,
limit: limit,
offset: 0,
return_distance: true,
)
end
end
end
end