mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-02-20 02:16:12 +00:00
* FEATURE: HyDE-powered semantic search. It relies on the new outlet added on discourse/discourse#23390 to display semantic search results in an unobtrusive way. We'll use a HyDE-backed approach for semantic search, which consists on generating an hypothetical document from a given keywords, which gets transformed into a vector and used in a asymmetric similarity topic search. This PR also reorganizes the internals to have less moving parts, maintaining one hierarchy of DAOish classes for vector-related operations like transformations and querying. Completions and vectors created by HyDE will remain cached on Redis for now, but we could later use Postgres instead. * Missing translation and rate limiting --------- Co-authored-by: Roman Rizzi <rizziromanalejandro@gmail.com>
44 lines
1.4 KiB
Ruby
44 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
describe DiscourseAi::Embeddings::SemanticRelated do
|
|
subject(:semantic_related) { described_class.new }
|
|
|
|
fab!(:target) { Fabricate(:topic) }
|
|
fab!(:normal_topic_1) { Fabricate(:topic) }
|
|
fab!(:normal_topic_2) { Fabricate(:topic) }
|
|
fab!(:normal_topic_3) { Fabricate(:topic) }
|
|
fab!(:unlisted_topic) { Fabricate(:topic, visible: false) }
|
|
fab!(:private_topic) { Fabricate(:private_message_topic) }
|
|
fab!(:secured_category) { Fabricate(:category, read_restricted: true) }
|
|
fab!(:secured_category_topic) { Fabricate(:topic, category: secured_category) }
|
|
fab!(:closed_topic) { Fabricate(:topic, closed: true) }
|
|
|
|
before { SiteSetting.ai_embeddings_semantic_related_topics_enabled = true }
|
|
|
|
describe "#related_topic_ids_for" do
|
|
context "when embeddings do not exist" do
|
|
let (:topic) do
|
|
Fabricate(:topic).tap { described_class.clear_cache_for(target) }
|
|
end
|
|
|
|
it "queues job only once per 15 minutes" do
|
|
results = nil
|
|
|
|
expect_enqueued_with(job: :generate_embeddings, args: { topic_id: topic.id }) do
|
|
results = semantic_related.related_topic_ids_for(topic)
|
|
end
|
|
|
|
expect(results).to eq([])
|
|
|
|
expect_not_enqueued_with(job: :generate_embeddings, args: { topic_id: topic.id }) do
|
|
results = semantic_related.related_topic_ids_for(topic)
|
|
end
|
|
|
|
expect(results).to eq([])
|
|
end
|
|
end
|
|
end
|
|
end
|