forked from pgvector/pgvector-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_psycopg2.py
More file actions
28 lines (21 loc) · 850 Bytes
/
test_psycopg2.py
File metadata and controls
28 lines (21 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import numpy as np
from pgvector.psycopg2 import register_vector
import psycopg2
conn = psycopg2.connect(dbname='pgvector_python_test')
conn.autocommit = True
cur = conn.cursor()
cur.execute('CREATE EXTENSION IF NOT EXISTS vector')
cur.execute('DROP TABLE IF EXISTS item')
cur.execute('CREATE TABLE item (id bigserial primary key, embedding vector(3))')
register_vector(cur)
class TestPsycopg2:
def setup_method(self, test_method):
cur.execute('DELETE FROM item')
def test_works(self):
embedding = np.array([1.5, 2, 3])
cur.execute('INSERT INTO item (embedding) VALUES (%s), (NULL)', (embedding,))
cur.execute('SELECT * FROM item ORDER BY id')
res = cur.fetchall()
assert np.array_equal(res[0][1], embedding)
assert res[0][1].dtype == np.float32
assert res[1][1] is None