Skip to content

Commit 9686270

Browse files
committed
Updated table names [skip ci]
1 parent 38dea36 commit 9686270

5 files changed

Lines changed: 39 additions & 39 deletions

File tree

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,20 @@ await register_vector_async(conn)
259259
Create a table
260260

261261
```python
262-
conn.execute('CREATE TABLE item (id bigserial PRIMARY KEY, embedding vector(3))')
262+
conn.execute('CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))')
263263
```
264264

265265
Insert a vector
266266

267267
```python
268268
embedding = np.array([1, 2, 3])
269-
conn.execute('INSERT INTO item (embedding) VALUES (%s)', (embedding,))
269+
conn.execute('INSERT INTO items (embedding) VALUES (%s)', (embedding,))
270270
```
271271

272272
Get the nearest neighbors to a vector
273273

274274
```python
275-
conn.execute('SELECT * FROM item ORDER BY embedding <-> %s LIMIT 5', (embedding,)).fetchall()
275+
conn.execute('SELECT * FROM items ORDER BY embedding <-> %s LIMIT 5', (embedding,)).fetchall()
276276
```
277277

278278
## Psycopg 2
@@ -295,20 +295,20 @@ register_vector(conn)
295295
Create a table
296296

297297
```python
298-
cur.execute('CREATE TABLE item (id bigserial PRIMARY KEY, embedding vector(3))')
298+
cur.execute('CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))')
299299
```
300300

301301
Insert a vector
302302

303303
```python
304304
embedding = np.array([1, 2, 3])
305-
cur.execute('INSERT INTO item (embedding) VALUES (%s)', (embedding,))
305+
cur.execute('INSERT INTO items (embedding) VALUES (%s)', (embedding,))
306306
```
307307

308308
Get the nearest neighbors to a vector
309309

310310
```python
311-
cur.execute('SELECT * FROM item ORDER BY embedding <-> %s LIMIT 5', (embedding,))
311+
cur.execute('SELECT * FROM items ORDER BY embedding <-> %s LIMIT 5', (embedding,))
312312
cur.fetchall()
313313
```
314314

@@ -340,20 +340,20 @@ pool = await asyncpg.create_pool(..., init=init)
340340
Create a table
341341

342342
```python
343-
await conn.execute('CREATE TABLE item (id bigserial PRIMARY KEY, embedding vector(3))')
343+
await conn.execute('CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))')
344344
```
345345

346346
Insert a vector
347347

348348
```python
349349
embedding = np.array([1, 2, 3])
350-
await conn.execute('INSERT INTO item (embedding) VALUES ($1)', embedding)
350+
await conn.execute('INSERT INTO items (embedding) VALUES ($1)', embedding)
351351
```
352352

353353
Get the nearest neighbors to a vector
354354

355355
```python
356-
await conn.fetch('SELECT * FROM item ORDER BY embedding <-> $1 LIMIT 5', embedding)
356+
await conn.fetch('SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5', embedding)
357357
```
358358

359359
## Peewee

examples/pytorch_image_search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ def generate_embeddings(inputs):
3838

3939
# generate, save, and index embeddings
4040
if seed:
41-
conn.execute('DROP TABLE IF EXISTS image')
42-
conn.execute('CREATE TABLE image (id bigserial PRIMARY KEY, embedding vector(512))')
41+
conn.execute('DROP TABLE IF EXISTS images')
42+
conn.execute('CREATE TABLE images (id bigserial PRIMARY KEY, embedding vector(512))')
4343

4444
print('Generating embeddings')
4545
for data in tqdm(dataloader):
4646
embeddings = generate_embeddings(data[0])
4747

48-
sql = 'INSERT INTO image (embedding) VALUES ' + ','.join(['(%s)' for _ in embeddings])
48+
sql = 'INSERT INTO images (embedding) VALUES ' + ','.join(['(%s)' for _ in embeddings])
4949
params = [embedding for embedding in embeddings]
5050
conn.execute(sql, params)
5151

@@ -67,5 +67,5 @@ def show_images(dataset_images):
6767
# generate and query embeddings
6868
embeddings = generate_embeddings(images)
6969
for image, embedding in zip(images, embeddings):
70-
result = conn.execute('SELECT id FROM image ORDER BY embedding <=> %s LIMIT 15', (embedding,)).fetchall()
70+
result = conn.execute('SELECT id FROM images ORDER BY embedding <=> %s LIMIT 15', (embedding,)).fetchall()
7171
show_images([image] + [dataset[row[0] - 1][0] for row in result])

tests/test_asyncpg.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ class TestAsyncpg:
1010
async def test_works(self):
1111
conn = await asyncpg.connect(database='pgvector_python_test')
1212
await conn.execute('CREATE EXTENSION IF NOT EXISTS vector')
13-
await conn.execute('DROP TABLE IF EXISTS item')
14-
await conn.execute('CREATE TABLE item (id bigserial PRIMARY KEY, embedding vector(3))')
13+
await conn.execute('DROP TABLE IF EXISTS items')
14+
await conn.execute('CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))')
1515

1616
await register_vector(conn)
1717

1818
embedding = np.array([1.5, 2, 3])
19-
await conn.execute("INSERT INTO item (embedding) VALUES ($1), (NULL)", embedding)
19+
await conn.execute("INSERT INTO items (embedding) VALUES ($1), (NULL)", embedding)
2020

21-
res = await conn.fetch("SELECT * FROM item ORDER BY id")
21+
res = await conn.fetch("SELECT * FROM items ORDER BY id")
2222
assert res[0]['id'] == 1
2323
assert res[1]['id'] == 2
2424
assert np.array_equal(res[0]['embedding'], embedding)
2525
assert res[0]['embedding'].dtype == np.float32
2626
assert res[1]['embedding'] is None
2727

2828
# ensures binary format is correct
29-
text_res = await conn.fetch("SELECT embedding::text FROM item ORDER BY id LIMIT 1")
29+
text_res = await conn.fetch("SELECT embedding::text FROM items ORDER BY id LIMIT 1")
3030
assert text_res[0]['embedding'] == '[1.5,2,3]'
3131

3232
await conn.close()
@@ -40,13 +40,13 @@ async def init(conn):
4040

4141
async with pool.acquire() as conn:
4242
await conn.execute('CREATE EXTENSION IF NOT EXISTS vector')
43-
await conn.execute('DROP TABLE IF EXISTS item')
44-
await conn.execute('CREATE TABLE item (id bigserial PRIMARY KEY, embedding vector(3))')
43+
await conn.execute('DROP TABLE IF EXISTS items')
44+
await conn.execute('CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))')
4545

4646
embedding = np.array([1.5, 2, 3])
47-
await conn.execute("INSERT INTO item (embedding) VALUES ($1), (NULL)", embedding)
47+
await conn.execute("INSERT INTO items (embedding) VALUES ($1), (NULL)", embedding)
4848

49-
res = await conn.fetch("SELECT * FROM item ORDER BY id")
49+
res = await conn.fetch("SELECT * FROM items ORDER BY id")
5050
assert res[0]['id'] == 1
5151
assert res[1]['id'] == 2
5252
assert np.array_equal(res[0]['embedding'], embedding)

tests/test_psycopg.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
conn = psycopg.connect(dbname='pgvector_python_test', autocommit=True)
77

88
conn.execute('CREATE EXTENSION IF NOT EXISTS vector')
9-
conn.execute('DROP TABLE IF EXISTS item')
10-
conn.execute('CREATE TABLE item (id bigserial PRIMARY KEY, embedding vector(3))')
9+
conn.execute('DROP TABLE IF EXISTS items')
10+
conn.execute('CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))')
1111

1212
register_vector(conn)
1313

1414

1515
class TestPsycopg:
1616
def setup_method(self, test_method):
17-
conn.execute('DELETE FROM item')
17+
conn.execute('DELETE FROM items')
1818

1919
def test_works(self):
2020
embedding = np.array([1.5, 2, 3])
21-
conn.execute('INSERT INTO item (embedding) VALUES (%s), (NULL)', (embedding,))
21+
conn.execute('INSERT INTO items (embedding) VALUES (%s), (NULL)', (embedding,))
2222

23-
res = conn.execute('SELECT * FROM item ORDER BY id').fetchall()
23+
res = conn.execute('SELECT * FROM items ORDER BY id').fetchall()
2424
assert np.array_equal(res[0][1], embedding)
2525
assert res[0][1].dtype == np.float32
2626
assert res[1][1] is None
@@ -55,19 +55,19 @@ def test_binary_format_non_contiguous(self):
5555
def test_text_copy(self):
5656
embedding = np.array([1.5, 2, 3])
5757
cur = conn.cursor()
58-
with cur.copy("COPY item (embedding) FROM STDIN") as copy:
58+
with cur.copy("COPY items (embedding) FROM STDIN") as copy:
5959
copy.write_row([embedding])
6060

6161
def test_binary_copy(self):
6262
embedding = np.array([1.5, 2, 3])
6363
cur = conn.cursor()
64-
with cur.copy("COPY item (embedding) FROM STDIN WITH (FORMAT BINARY)") as copy:
64+
with cur.copy("COPY items (embedding) FROM STDIN WITH (FORMAT BINARY)") as copy:
6565
copy.write_row([embedding])
6666

6767
def test_binary_copy_set_types(self):
6868
embedding = np.array([1.5, 2, 3])
6969
cur = conn.cursor()
70-
with cur.copy("COPY item (id, embedding) FROM STDIN WITH (FORMAT BINARY)") as copy:
70+
with cur.copy("COPY items (id, embedding) FROM STDIN WITH (FORMAT BINARY)") as copy:
7171
copy.set_types(['int8', 'vector'])
7272
copy.write_row([1, embedding])
7373

@@ -76,16 +76,16 @@ async def test_async(self):
7676
conn = await psycopg.AsyncConnection.connect(dbname='pgvector_python_test', autocommit=True)
7777

7878
await conn.execute('CREATE EXTENSION IF NOT EXISTS vector')
79-
await conn.execute('DROP TABLE IF EXISTS item')
80-
await conn.execute('CREATE TABLE item (id bigserial PRIMARY KEY, embedding vector(3))')
79+
await conn.execute('DROP TABLE IF EXISTS items')
80+
await conn.execute('CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))')
8181

8282
await register_vector_async(conn)
8383

8484
embedding = np.array([1.5, 2, 3])
85-
await conn.execute('INSERT INTO item (embedding) VALUES (%s), (NULL)', (embedding,))
85+
await conn.execute('INSERT INTO items (embedding) VALUES (%s), (NULL)', (embedding,))
8686

8787
async with conn.cursor() as cur:
88-
await cur.execute('SELECT * FROM item ORDER BY id')
88+
await cur.execute('SELECT * FROM items ORDER BY id')
8989
res = await cur.fetchall()
9090
assert np.array_equal(res[0][1], embedding)
9191
assert res[0][1].dtype == np.float32

tests/test_psycopg2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77

88
cur = conn.cursor()
99
cur.execute('CREATE EXTENSION IF NOT EXISTS vector')
10-
cur.execute('DROP TABLE IF EXISTS item')
11-
cur.execute('CREATE TABLE item (id bigserial PRIMARY KEY, embedding vector(3))')
10+
cur.execute('DROP TABLE IF EXISTS items')
11+
cur.execute('CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))')
1212

1313
register_vector(cur)
1414

1515

1616
class TestPsycopg2:
1717
def setup_method(self, test_method):
18-
cur.execute('DELETE FROM item')
18+
cur.execute('DELETE FROM items')
1919

2020
def test_works(self):
2121
embedding = np.array([1.5, 2, 3])
22-
cur.execute('INSERT INTO item (embedding) VALUES (%s), (NULL)', (embedding,))
22+
cur.execute('INSERT INTO items (embedding) VALUES (%s), (NULL)', (embedding,))
2323

24-
cur.execute('SELECT * FROM item ORDER BY id')
24+
cur.execute('SELECT * FROM items ORDER BY id')
2525
res = cur.fetchall()
2626
assert np.array_equal(res[0][1], embedding)
2727
assert res[0][1].dtype == np.float32

0 commit comments

Comments
 (0)