Skip to content

Commit

Permalink
Improved Sequel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jul 9, 2024
1 parent 7297d44 commit b364a45
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/sequel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ def test_model_vector_inner_product
assert_equal [6, 4, 3], results.map { |r| r[:neighbor_distance] }
end

def test_model_vector_cosine
create_items
results = Item.nearest_neighbors(:embedding, [1, 1, 1], distance: "cosine").limit(5)
assert_equal [1, 2, 3], results.map(&:id)
end

def test_model_vector_taxicab
create_items
results = Item.nearest_neighbors(:embedding, [1, 1, 1], distance: "taxicab").limit(5)
Expand All @@ -79,6 +85,12 @@ def test_instance_vector_inner_product
assert_equal [6, 4], results.map { |r| r[:neighbor_distance] }
end

def test_instance_vector_cosine
create_items
results = Item.first.nearest_neighbors(:embedding, distance: "cosine").limit(5)
assert_equal [2, 3], results.map(&:id)
end

def test_instance_vector_taxicab
create_items
results = Item.first.nearest_neighbors(:embedding, distance: "taxicab").limit(5)
Expand All @@ -102,6 +114,13 @@ def test_model_bit_hamming
assert_equal ["101", "111", "000"], results.map(&:binary_embedding)
end

def test_model_bit_jaccard
create_items
results = Item.nearest_neighbors(:binary_embedding, "101", distance: "jaccard").limit(5)
assert_equal [2, 3, 1], results.map(&:id)
assert_equal ["101", "111", "000"], results.map(&:binary_embedding)
end

def test_model_sparsevec_euclidean
create_items
results = Item.nearest_neighbors(:sparse_embedding, Pgvector::SparseVector.new([1, 1, 1]), distance: "euclidean").limit(5)
Expand Down

0 comments on commit b364a45

Please sign in to comment.