Skip to content

Commit 1c7e6a5

Browse files
committed
Added docs for arrays with SQLAlchemy [skip ci]
1 parent 664b8ee commit 1c7e6a5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,27 @@ order = func.cast(Item.embedding, HALFVEC(3)).l2_distance([3, 1, 2])
268268
session.scalars(select(Item).order_by(order).limit(5))
269269
```
270270

271+
#### Arrays
272+
273+
Add an array column
274+
275+
```python
276+
from pgvector.sqlalchemy import Vector
277+
from sqlalchemy import ARRAY
278+
279+
class Item(Base):
280+
embeddings = mapped_column(ARRAY(Vector(3)))
281+
```
282+
283+
And register the types with the underlying driver
284+
285+
```python
286+
from pgvector.psycopg2 import register_vector
287+
288+
with engine.connect() as connection:
289+
register_vector(connection.connection.dbapi_connection, globally=True, arrays=True)
290+
```
291+
271292
## SQLModel
272293

273294
Enable the extension

0 commit comments

Comments
 (0)