Skip to content

Add SemanticSearcher for semantic search#195

Open
abetomo wants to merge 3 commits into
clear-code:masterfrom
abetomo:semantic_searcher
Open

Add SemanticSearcher for semantic search#195
abetomo wants to merge 3 commits into
clear-code:masterfrom
abetomo:semantic_searcher

Conversation

@abetomo

@abetomo abetomo commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

It basically just adds language_model_knn() to the Searcher's filter.
Overrode the keyword search only parts (e.g. match_columns) to do nothing.

It basically just adds language_model_knn() to the Searcher's filter.
Overrode the keyword search only parts (e.g. `match_columns`) to do nothing.
Copilot AI review requested due to automatic review settings June 12, 2026 12:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new FullTextSearch::SemanticSearcher intended to run semantic (embedding/KNN-based) search via PGroonga’s language_model_knn(), and updates the existing select plumbing so callers can target a specific PGroonga index.

Changes:

  • Add SemanticSearcher (subclass of Searcher) that builds a semantic KNN filter and targets a dedicated semantic index.
  • Extend the Searcher/backend select APIs to allow passing an explicit index_name.
  • Add a unit test for semantic search (guarded behind SEMANTIC_SEARCH_TEST and PostgreSQL).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/full_text_search/semantic_searcher.rb Adds semantic-search-specific searcher that uses language_model_knn and a semantic index.
test/unit/full_text_search/semantic_searcher_test.rb Adds an opt-in test that provisions the semantic index and asserts semantic ranking.
lib/full_text_search/searcher.rb Allows subclasses to override index_name and slice usage; passes index_name into Target.select.
lib/full_text_search/pgroonga.rb Updates select/build_sql to support choosing a PGroonga index name.
lib/full_text_search/mroonga.rb Updates select signature to accept (and ignore) index_name for API compatibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +22 to +25
def knn_expression
query = Groonga::Client::ScriptSyntax.format_string(@request.query)
%Q[language_model_knn(content, #{query}, {"k": #{K}})]
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the initial implementation, K is fixed at 50.

Comment thread lib/full_text_search/semantic_searcher.rb
Comment thread lib/full_text_search/pgroonga.rb
Comment thread test/unit/full_text_search/semantic_searcher_test.rb
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this class used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it's used.

--- a/lib/full_text_search/hooks/controller_search_index.rb
+++ b/lib/full_text_search/hooks/controller_search_index.rb
@@ -29,7 +29,12 @@ module FullTextSearch
           return
         end
 
-        searcher = Searcher.new(@search_request)
+        if @search_request.semantic? && SemanticIndex.exist?
+          searcher = SemanticSearcher.new(@search_request)
+        else
+          searcher = Searcher.new(@search_request)
+        end
+
         @result_set = searcher.search

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants