Skip to content

Commit 7887a34

Browse files
committed
Added test for arrays with asyncpg
1 parent 82b7ab9 commit 7887a34

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/test_asyncpg.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ async def test_sparsevec(self):
9494

9595
await conn.close()
9696

97+
@pytest.mark.asyncio
98+
async def test_vector_array(self):
99+
conn = await asyncpg.connect(database='pgvector_python_test')
100+
await conn.execute('CREATE EXTENSION IF NOT EXISTS vector')
101+
await conn.execute('DROP TABLE IF EXISTS asyncpg_items')
102+
await conn.execute('CREATE TABLE asyncpg_items (id bigserial PRIMARY KEY, embeddings vector[])')
103+
104+
await register_vector(conn)
105+
106+
embeddings = [np.array([1.5, 2, 3]), np.array([4.5, 5, 6])]
107+
await conn.execute("INSERT INTO asyncpg_items (embeddings) VALUES (ARRAY[$1, $2]::vector[])", embeddings[0], embeddings[1])
108+
109+
res = await conn.fetch("SELECT * FROM asyncpg_items ORDER BY id")
110+
assert np.array_equal(res[0]['embeddings'][0], embeddings[0])
111+
assert np.array_equal(res[0]['embeddings'][1], embeddings[1])
112+
113+
await conn.close()
114+
97115
@pytest.mark.asyncio
98116
async def test_pool(self):
99117
async def init(conn):

0 commit comments

Comments
 (0)