Skip to content

Commit 2f1354f

Browse files
committed
Added copy tests
1 parent 85d70b9 commit 2f1354f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

test/pg_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,30 @@ def test_type_map_binary
9494
assert_match sparse_vec.to_binary, coder.encode([sparse_vec])
9595
end
9696

97+
def test_copy_text
98+
embedding = Pgvector::Vector.new([1, 2, 3])
99+
sparse_embedding = Pgvector::SparseVector.new([1, 2, 3])
100+
coder = PG::TextEncoder::CopyRow.new
101+
conn.copy_data("COPY pg_items (embedding, sparse_embedding) FROM STDIN", coder) do
102+
conn.put_copy_data([embedding, sparse_embedding])
103+
end
104+
res = conn.exec("SELECT * FROM pg_items").first
105+
assert_equal embedding.to_a, res["embedding"].to_a
106+
assert_equal sparse_embedding.to_a, res["sparse_embedding"].to_a
107+
end
108+
109+
def test_copy_binary
110+
embedding = Pgvector::Vector.new([1, 2, 3])
111+
sparse_embedding = Pgvector::SparseVector.new([1, 2, 3])
112+
coder = PG::BinaryEncoder::CopyRow.new
113+
conn.copy_data("COPY pg_items (embedding, sparse_embedding) FROM STDIN WITH (FORMAT BINARY)", coder) do
114+
conn.put_copy_data([embedding.to_binary, sparse_embedding.to_binary])
115+
end
116+
res = conn.exec("SELECT * FROM pg_items").first
117+
assert_equal embedding.to_a, res["embedding"].to_a
118+
assert_equal sparse_embedding.to_a, res["sparse_embedding"].to_a
119+
end
120+
97121
def conn
98122
@@conn ||= begin
99123
conn = PG.connect(dbname: "pgvector_ruby_test")

0 commit comments

Comments
 (0)