Skip to content

Commit 32a8d04

Browse files
committed
Added docs for half-precision indexing with SQLAlchemy - #98 [skip ci]
1 parent 1037d7e commit 32a8d04

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,29 @@ index.create(engine)
214214

215215
Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distance
216216

217+
#### Half-Precision Indexing
218+
219+
Index vectors at half-precision
220+
221+
```python
222+
from pgvector.sqlalchemy import HALFVEC
223+
from sqlalchemy.sql import func
224+
225+
index = Index(
226+
'my_index',
227+
func.cast(Item.embedding, HALFVEC(3)).label('embedding'),
228+
postgresql_using='hnsw',
229+
postgresql_with={'m': 16, 'ef_construction': 64},
230+
postgresql_ops={'embedding': 'vector_l2_ops'}
231+
)
232+
```
233+
234+
Get the nearest neighbors
235+
236+
```python
237+
session.scalars(select(Item).order_by(func.cast(Item.embedding, HALFVEC(3)).l2_distance([3, 1, 2])).limit(5))
238+
```
239+
217240
## SQLModel
218241

219242
Enable the extension

0 commit comments

Comments
 (0)