Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Sep 3, 2024
1 parent f571a36 commit d5f0301
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion test/knn_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ class KnnTest < Minitest::Test
def test_works
store [{name: "A", embedding: [1, 2, 3]}, {name: "B", embedding: [-1, -2, -3]}]
assert_order "*", ["A", "B"], knn: {embedding: [1, 2, 3]}

expected = Searchkick.opensearch? ? [1, 0] : [2, 1]
assert_equal expected, Product.search(knn: {embedding: [1, 2, 3]}).hits.map { |v| v["_score"] }
scores = Product.search(knn: {embedding: [1, 2, 3]}).hits.map { |v| v["_score"] }
assert_in_delta expected[0], scores[0]
assert_in_delta expected[1], scores[1]
end
end
6 changes: 0 additions & 6 deletions test/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ class Product
match: ENV["MATCH"] ? ENV["MATCH"].to_sym : nil,
knn: {embedding: {dimensions: 3}}

if ActiveRecord::VERSION::STRING.to_f >= 7.1
serialize :embedding, coder: JSON
else
serialize :embedding, JSON
end

attr_accessor :conversions, :user_ids, :aisle, :details

class << self
Expand Down
6 changes: 6 additions & 0 deletions test/support/activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@

class Product < ActiveRecord::Base
belongs_to :store

if ActiveRecord::VERSION::STRING.to_f >= 7.1
serialize :embedding, coder: JSON
else
serialize :embedding, JSON
end
end

class Store < ActiveRecord::Base
Expand Down
1 change: 1 addition & 0 deletions test/support/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Product
field :longitude, type: BigDecimal
field :description
field :alt_description
field :embedding, type: Array
end

class Store
Expand Down

0 comments on commit d5f0301

Please sign in to comment.