Skip to content

Commit

Permalink
Added basic test for Postgres arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Dec 31, 2024
1 parent cd6875b commit 884db5e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/neighbor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def test_schema
assert_match %{t.halfvec "half_embedding", limit: 3}, contents
assert_match %{t.bit "binary_embedding", limit: 3}, contents
assert_match %{t.sparsevec "sparse_embedding", limit: 3}, contents
assert_match %{t.vector "embeddings", limit: 3, array: true}, contents
end

def test_connection_leasing
Expand Down
1 change: 1 addition & 0 deletions test/support/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PostgresRecord < ActiveRecord::Base
t.bit :binary_embedding, limit: 3
t.sparsevec :sparse_embedding, limit: 3
t.sparsevec :sparse_factors, limit: 5
t.vector :embeddings, limit: 3, array: true
end
add_index :items, :cube_embedding, using: :gist
add_index :items, :embedding, using: :hnsw, opclass: :vector_cosine_ops
Expand Down
6 changes: 6 additions & 0 deletions test/vector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,10 @@ def test_nan
end
assert_equal "Validation failed: Embedding must have finite values", error.message
end

def test_array
Item.connection.execute("INSERT INTO items (embeddings) VALUES (ARRAY['[1,2,3]', '[4,5,6]']::vector[])")
item = Item.last
assert_equal [[1, 2, 3], [4, 5, 6]], item.embeddings
end
end

0 comments on commit 884db5e

Please sign in to comment.