From 884db5e9865535d05502c2cb43202c47ead41f04 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 31 Dec 2024 09:38:28 -0800 Subject: [PATCH] Added basic test for Postgres arrays --- test/neighbor_test.rb | 1 + test/support/postgresql.rb | 1 + test/vector_test.rb | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/test/neighbor_test.rb b/test/neighbor_test.rb index 1d35032..1c5b548 100644 --- a/test/neighbor_test.rb +++ b/test/neighbor_test.rb @@ -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 diff --git a/test/support/postgresql.rb b/test/support/postgresql.rb index 4bc81af..72cf859 100644 --- a/test/support/postgresql.rb +++ b/test/support/postgresql.rb @@ -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 diff --git a/test/vector_test.rb b/test/vector_test.rb index b5d106c..a68dc5c 100644 --- a/test/vector_test.rb +++ b/test/vector_test.rb @@ -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