FEATURE: add filter support to ai bot semantic search (#222)
Previously we would bypass semantic search if any filters were present Also shows progress now.
This commit is contained in:
parent
d1642533fb
commit
cdd6faa648
|
@ -100,6 +100,9 @@ module DiscourseAi
|
|||
end
|
||||
|
||||
def show_progress(text, progress_caret: false)
|
||||
return if !@post
|
||||
return if !@placeholder
|
||||
|
||||
# during tests we may have none
|
||||
caret = progress_caret ? PROGRESS_CARET : CARET
|
||||
new_placeholder = @placeholder.sub(caret, text + caret)
|
||||
|
|
|
@ -116,6 +116,9 @@ module DiscourseAi::AiBot::Commands
|
|||
.join(" ")
|
||||
|
||||
@last_query = search_string
|
||||
|
||||
show_progress(localized_description)
|
||||
|
||||
results =
|
||||
Search.execute(
|
||||
search_string.to_s + " status:public",
|
||||
|
@ -129,7 +132,6 @@ module DiscourseAi::AiBot::Commands
|
|||
|
||||
should_try_semantic_search = SiteSetting.ai_embeddings_semantic_search_enabled
|
||||
should_try_semantic_search &&= (limit == MAX_RESULTS)
|
||||
should_try_semantic_search &&= (search_args.keys - %i[search_query order]).length == 0
|
||||
should_try_semantic_search &&= (search_args[:search_query].present?)
|
||||
|
||||
limit = limit - MIN_SEMANTIC_RESULTS if should_try_semantic_search
|
||||
|
@ -141,9 +143,12 @@ module DiscourseAi::AiBot::Commands
|
|||
semantic_search = DiscourseAi::Embeddings::SemanticSearch.new(Guardian.new())
|
||||
topic_ids = Set.new(posts.map(&:topic_id))
|
||||
|
||||
semantic_search
|
||||
.search_for_topics(search_args[:search_query])
|
||||
.each do |post|
|
||||
search = Search.new(search_string, guardian: Guardian.new)
|
||||
|
||||
results = semantic_search.search_for_topics(search.term)
|
||||
results = search.apply_filters(results)
|
||||
|
||||
results.each do |post|
|
||||
next if topic_ids.include?(post.topic_id)
|
||||
|
||||
topic_ids << post.topic_id
|
||||
|
|
|
@ -69,9 +69,9 @@ RSpec.describe DiscourseAi::AiBot::Commands::SearchCommand do
|
|||
.expects(:asymmetric_topics_similarity_search)
|
||||
.returns([post1.topic_id])
|
||||
|
||||
results = search.process(search_query: "hello world, sam")
|
||||
results = search.process(search_query: "hello world, sam", status: "public")
|
||||
|
||||
expect(results[:args]).to eq({ search_query: "hello world, sam" })
|
||||
expect(results[:args]).to eq({ search_query: "hello world, sam", status: "public" })
|
||||
expect(results[:rows].length).to eq(1)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue