Cache, rescue, disable on PMs
This commit is contained in:
parent
7055a290ae
commit
c3b9b46813
|
@ -102,7 +102,7 @@ plugins:
|
|||
- all-mpnet-base-v2
|
||||
- msmarco-distilbert-base-v4
|
||||
- text-embedding-ada-002
|
||||
ai_embeddings_generate_for_pms: false
|
||||
ai_embeddings_semantic_suggested_topics_anons_enabled: false
|
||||
ai_embeddings_pg_connection_string:
|
||||
default: "postgresql://localhost/embeddings"
|
||||
ai_embeddings_pg_connection_string: ""
|
||||
|
|
@ -6,6 +6,8 @@ module Jobs
|
|||
return unless SiteSetting.ai_embeddings_enabled
|
||||
return if (topic_id = args[:topic_id]).blank?
|
||||
|
||||
topic = Topic.find_by_id(topic_id)
|
||||
return if topic.private_message? && !SiteSetting.ai_embeddings_enabled_for_private_messages
|
||||
post = Topic.find_by_id(topic_id).first_post
|
||||
return if post.nil? || post.raw.blank?
|
||||
|
||||
|
|
|
@ -8,27 +8,36 @@ module DiscourseAI
|
|||
return if topic_query.user
|
||||
return if topic.private_message?
|
||||
|
||||
candidate_ids = DiscourseAI::Database::Connection.db.query(<<~SQL, topic_id: topic.id)
|
||||
SELECT
|
||||
topic_id
|
||||
FROM
|
||||
topic_embeddings_symetric_discourse
|
||||
WHERE
|
||||
topic_id != :topic_id
|
||||
ORDER BY
|
||||
embeddings <#> (
|
||||
SELECT
|
||||
embeddings
|
||||
FROM
|
||||
topic_embeddings_symetric_discourse
|
||||
WHERE
|
||||
topic_id = :topic_id
|
||||
LIMIT 1
|
||||
)
|
||||
LIMIT 10
|
||||
SQL
|
||||
begin
|
||||
candidate_ids =
|
||||
Discourse
|
||||
.cache
|
||||
.fetch("semantic-suggested-topic-#{topic.id}", expires_in: 1.hour) do
|
||||
DiscourseAI::Database::Connection.db.query(<<~SQL, topic_id: topic.id).map(&:topic_id)
|
||||
SELECT
|
||||
topic_id
|
||||
FROM
|
||||
topic_embeddings_symetric_discourse
|
||||
WHERE
|
||||
topic_id != :topic_id
|
||||
ORDER BY
|
||||
embeddings <#> (
|
||||
SELECT
|
||||
embeddings
|
||||
FROM
|
||||
topic_embeddings_symetric_discourse
|
||||
WHERE
|
||||
topic_id = :topic_id
|
||||
LIMIT 1
|
||||
)
|
||||
LIMIT 10
|
||||
SQL
|
||||
end
|
||||
rescue StandardError => e
|
||||
Rails.logger.error("SemanticSuggested: #{e}")
|
||||
end
|
||||
|
||||
candidates = ::Topic.where(id: candidate_ids.map(&:topic_id))
|
||||
candidates = ::Topic.where(id: candidate_ids)
|
||||
{ result: candidates, params: {} }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue