Skip to content

Commit 69e1e92

Browse files
committed
Improved examples in readme [skip ci]
1 parent 2836dd3 commit 69e1e92

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ Get the nearest neighbors to a vector
298298
conn.execute('SELECT * FROM items ORDER BY embedding <-> %s LIMIT 5', (embedding,)).fetchall()
299299
```
300300

301+
Add an approximate index
302+
303+
```python
304+
conn.execute('CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)')
305+
# or
306+
conn.execute('CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)')
307+
```
308+
309+
Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance
310+
301311
## Psycopg 2
302312

303313
Enable the extension
@@ -335,6 +345,16 @@ cur.execute('SELECT * FROM items ORDER BY embedding <-> %s LIMIT 5', (embedding,
335345
cur.fetchall()
336346
```
337347

348+
Add an approximate index
349+
350+
```python
351+
cur.execute('CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)')
352+
# or
353+
cur.execute('CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)')
354+
```
355+
356+
Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance
357+
338358
## asyncpg
339359

340360
Enable the extension
@@ -379,6 +399,16 @@ Get the nearest neighbors to a vector
379399
await conn.fetch('SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5', embedding)
380400
```
381401

402+
Add an approximate index
403+
404+
```python
405+
await conn.execute('CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)')
406+
# or
407+
await conn.execute('CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)')
408+
```
409+
410+
Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance
411+
382412
## Peewee
383413

384414
Add a vector column

0 commit comments

Comments
 (0)