From e408cd080c336caae19e6a9045960c6b880b2d94 Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Fri, 30 Aug 2024 12:13:29 -0300 Subject: [PATCH] FIX: coerce value before downcasing the hyde param (#787) --- .../embeddings/embeddings_controller.rb | 2 +- .../embeddings/embeddings_controller_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/controllers/discourse_ai/embeddings/embeddings_controller.rb b/app/controllers/discourse_ai/embeddings/embeddings_controller.rb index 753ec18f..d2aafce8 100644 --- a/app/controllers/discourse_ai/embeddings/embeddings_controller.rb +++ b/app/controllers/discourse_ai/embeddings/embeddings_controller.rb @@ -9,7 +9,7 @@ module DiscourseAi def search query = params[:q].to_s - skip_hyde = params[:hyde].downcase.to_s == "false" || params[:hyde].to_s == "0" + skip_hyde = params[:hyde].to_s.downcase == "false" || params[:hyde].to_s == "0" if query.length < SiteSetting.min_search_term_length raise Discourse::InvalidParameters.new(:q) diff --git a/spec/requests/embeddings/embeddings_controller_spec.rb b/spec/requests/embeddings/embeddings_controller_spec.rb index 01d9d11b..d292996f 100644 --- a/spec/requests/embeddings/embeddings_controller_spec.rb +++ b/spec/requests/embeddings/embeddings_controller_spec.rb @@ -88,5 +88,21 @@ describe DiscourseAi::Embeddings::EmbeddingsController do expect(response.status).to eq(200) expect(response.parsed_body["topics"].map { |t| t["id"] }).to eq([topic_in_subcategory.id]) end + + it "doesn't skip HyDE if the hyde param is missing" do + assign_fake_provider_to(:ai_embeddings_semantic_search_hyde_model) + index(topic) + index(topic_in_subcategory) + + query = "test category:#{category.slug}" + stub_embedding("test") + + DiscourseAi::Completions::Llm.with_prepared_responses(["Hyde #{query}"]) do + get "/discourse-ai/embeddings/semantic-search.json?q=#{query}" + + expect(response.status).to eq(200) + expect(response.parsed_body["topics"].map { |t| t["id"] }).to eq([topic_in_subcategory.id]) + end + end end end