Skip to content

Commit

Permalink
Improved copy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jul 15, 2024
1 parent 2f1354f commit ea9b077
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions test/pg_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ def test_type_map_binary

def test_copy_text
embedding = Pgvector::Vector.new([1, 2, 3])
half_embedding = Pgvector::HalfVector.new([1, 2, 3])
binary_embedding = Pgvector::Bit.new([true, false, true])
sparse_embedding = Pgvector::SparseVector.new([1, 2, 3])
coder = PG::TextEncoder::CopyRow.new
conn.copy_data("COPY pg_items (embedding, sparse_embedding) FROM STDIN", coder) do
conn.put_copy_data([embedding, sparse_embedding])
conn.copy_data("COPY pg_items (embedding, half_embedding, binary_embedding, sparse_embedding) FROM STDIN", coder) do
conn.put_copy_data([embedding, half_embedding, binary_embedding, sparse_embedding])
end
res = conn.exec("SELECT * FROM pg_items").first
assert_equal embedding.to_a, res["embedding"].to_a
assert_equal sparse_embedding.to_a, res["sparse_embedding"].to_a
assert_equal [1, 2, 3], res["embedding"]
assert_equal [1, 2, 3], res["half_embedding"].to_a
assert_equal "101", res["binary_embedding"]
assert_equal [1, 2, 3], res["sparse_embedding"].to_a
end

def test_copy_binary
Expand All @@ -114,8 +118,8 @@ def test_copy_binary
conn.put_copy_data([embedding.to_binary, sparse_embedding.to_binary])
end
res = conn.exec("SELECT * FROM pg_items").first
assert_equal embedding.to_a, res["embedding"].to_a
assert_equal sparse_embedding.to_a, res["sparse_embedding"].to_a
assert_equal [1, 2, 3], res["embedding"]
assert_equal [1, 2, 3], res["sparse_embedding"].to_a
end

def conn
Expand Down

0 comments on commit ea9b077

Please # to comment.