@@ -69,17 +69,19 @@ def test_halfvec(self):
6969 conn .execute ('INSERT INTO psycopg_items (half_embedding) VALUES (%s)' , (embedding ,))
7070
7171 res = conn .execute ('SELECT half_embedding FROM psycopg_items ORDER BY id' ).fetchone ()[0 ]
72- assert res . to_list () == [1.5 , 2 , 3 ]
72+ assert res == HalfVector ( [1.5 , 2 , 3 ])
7373
7474 def test_halfvec_binary_format (self ):
7575 embedding = HalfVector ([1.5 , 2 , 3 ])
7676 res = conn .execute ('SELECT %b::halfvec' , (embedding ,), binary = True ).fetchone ()[0 ]
77+ assert res == HalfVector ([1.5 , 2 , 3 ])
7778 assert res .to_list () == [1.5 , 2 , 3 ]
7879 assert np .array_equal (res .to_numpy (), np .array ([1.5 , 2 , 3 ]))
7980
8081 def test_halfvec_text_format (self ):
8182 embedding = HalfVector ([1.5 , 2 , 3 ])
8283 res = conn .execute ('SELECT %t::halfvec' , (embedding ,)).fetchone ()[0 ]
84+ assert res == HalfVector ([1.5 , 2 , 3 ])
8385 assert res .to_list () == [1.5 , 2 , 3 ]
8486 assert np .array_equal (res .to_numpy (), np .array ([1.5 , 2 , 3 ]))
8587
@@ -106,11 +108,12 @@ def test_sparsevec(self):
106108 conn .execute ('INSERT INTO psycopg_items (sparse_embedding) VALUES (%s)' , (embedding ,))
107109
108110 res = conn .execute ('SELECT sparse_embedding FROM psycopg_items ORDER BY id' ).fetchone ()[0 ]
109- assert res . to_list () == [1.5 , 2 , 3 ]
111+ assert res == SparseVector ( [1.5 , 2 , 3 ])
110112
111113 def test_sparsevec_binary_format (self ):
112114 embedding = SparseVector ([1.5 , 0 , 2 , 0 , 3 , 0 ])
113115 res = conn .execute ('SELECT %b::sparsevec' , (embedding ,), binary = True ).fetchone ()[0 ]
116+ assert res == embedding
114117 assert res .dimensions () == 6
115118 assert res .indices () == [0 , 2 , 4 ]
116119 assert res .values () == [1.5 , 2 , 3 ]
@@ -120,6 +123,7 @@ def test_sparsevec_binary_format(self):
120123 def test_sparsevec_text_format (self ):
121124 embedding = SparseVector ([1.5 , 0 , 2 , 0 , 3 , 0 ])
122125 res = conn .execute ('SELECT %t::sparsevec' , (embedding ,)).fetchone ()[0 ]
126+ assert res == embedding
123127 assert res .dimensions () == 6
124128 assert res .indices () == [0 , 2 , 4 ]
125129 assert res .values () == [1.5 , 2 , 3 ]
0 commit comments