mirror of
				https://github.com/discourse/discourse-ai.git
				synced 2025-10-31 14:38:37 +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>
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # frozen_string_literal: true
 | |
| 
 | |
| require "rails_helper"
 | |
| 
 | |
| describe ::TopicsController do
 | |
|   fab!(:topic) { Fabricate(:topic) }
 | |
|   fab!(:topic1) { Fabricate(:topic) }
 | |
|   fab!(:topic2) { Fabricate(:topic) }
 | |
|   fab!(:topic3) { Fabricate(:topic) }
 | |
|   fab!(:user) { Fabricate(:admin) }
 | |
| 
 | |
|   before do
 | |
|     SiteSetting.ai_embeddings_semantic_related_topics_enabled = true
 | |
|     SiteSetting.ai_embeddings_semantic_related_topics = 2
 | |
|   end
 | |
| 
 | |
|   context "when a user is logged on" do
 | |
|     it "includes related topics in payload when configured" do
 | |
|       DiscourseAi::Embeddings::SemanticRelated
 | |
|         .any_instance
 | |
|         .stubs(:related_topic_ids_for)
 | |
|         .returns([topic1.id, topic2.id, topic3.id])
 | |
| 
 | |
|       get("#{topic.relative_url}.json")
 | |
|       expect(response.status).to eq(200)
 | |
|       json = response.parsed_body
 | |
| 
 | |
|       expect(json["suggested_topics"].length).to eq(0)
 | |
|       expect(json["related_topics"].length).to eq(2)
 | |
| 
 | |
|       sign_in(user)
 | |
| 
 | |
|       get("#{topic.relative_url}.json")
 | |
|       json = response.parsed_body
 | |
| 
 | |
|       expect(json["suggested_topics"].length).to eq(0)
 | |
|       expect(json["related_topics"].length).to eq(2)
 | |
|     end
 | |
|   end
 | |
| end
 |