Skip to content

Commit

Permalink
FIX: coerce value before downcasing the hyde param (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanrizzi authored Aug 30, 2024
1 parent 4a18742 commit e408cd0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EmbeddingsController < ::ApplicationController

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)
Expand Down
16 changes: 16 additions & 0 deletions spec/requests/embeddings/embeddings_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,21 @@ def create_api_key(user)
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

0 comments on commit e408cd0

Please sign in to comment.