Skip to content

Commit

Permalink
Added support for hybrid search
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Sep 3, 2024
1 parent 7dbe96b commit c1ebc2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/searchkick/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,10 @@ def prepare
# knn
knn = options[:knn]
if knn
if term != "*"
raise ArgumentError, "Hybrid search not supported yet"
end

field = knn[:field]
vector = knn[:vector]
k = per_page + offset
filter = payload.delete(:query)
filter = term == "*" ? payload.delete(:query) : payload[:query]

if Searchkick.opensearch?
payload[:query] = {
Expand Down
17 changes: 17 additions & 0 deletions test/hybrid_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative "test_helper"

class HybridTest < Minitest::Test
def setup
skip unless Searchkick.knn_support?
super
end

def test_basic
store [
{name: "Product A", embedding: [1, 2, 3]},
{name: "Item B", embedding: [1, 2, 3]},
{name: "Product C", embedding: [-1, -2, -3]}
]
assert_order "product", ["Product A", "Product C"], knn: {field: :embedding, vector: [1, 2, 3]}
end
end

0 comments on commit c1ebc2f

Please sign in to comment.