Skip to content

Commit 9abfa4d

Browse files
committed
Fix the sample code to use the connection context manager and update the definition of the vector column
1 parent 60739df commit 9abfa4d

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ def connect(dbapi_connection, connection_record):
353353
Enable the extension
354354

355355
```python
356-
session.exec(text('CREATE EXTENSION IF NOT EXISTS vector'))
356+
with engine.begin() as conn:
357+
conn.execute(text("CREATE EXTENSION IF NOT EXISTS vector"))
357358
```
358359

359360
Add a vector column
@@ -362,7 +363,7 @@ Add a vector column
362363
from pgvector.sqlalchemy import VECTOR
363364

364365
class Item(SQLModel, table=True):
365-
embedding: list[float] = Field(sa_type=VECTOR(3))
366+
embedding: list[float] = Field(sa_column=Column(VECTOR(3)))
366367
```
367368

368369
Also supports `HALFVEC`, `BIT`, and `SPARSEVEC`

0 commit comments

Comments
 (0)