InvalidRequestError: Unknown PG numeric type when using postgres pgvector extension #580
-
First Check
Commit to Help
Example Codefrom pgvector.sqlalchemy import Vector
## model
class Record(SQLModel, table=True):
id: UUID = Field(default_factory=uuid4, primary_key=True)
text: str = Field(default=None)
start: int = Field(default=None)
token_count: int = Field(default=None)
embedding: List[float] = Field(default=None, sa_column=Vector(1536))
## controllers
def get_record(session: Session, id: UUID):
return session.get(Record, id)
def create_or_update_record(session: Session, record: RecordCreate):
db_record = session.exec(
select(Record).where(Record.id == record.id)
).first()
# rest of the function DescriptionI'm using pgvector to insert vectors to the database. But when I need to query the table (for updating a row for example), I get the following error:
I had the issue with inserting vectors as well, but I fixed it by changing from: def create_record(session: Session, record: RecordCreate):
new_record = Record(**record.dict())
session.add(new_record)
session.commit()
session.refresh(new_record)
return new_record to: def create_record(session: Session, record: RecordCreate):
new_record = Record(**record.dict())
session.add(new_record)
session.commit()
# session.refresh(new_record)
return dict(new_record) Any idea how can I fix this? Operating SystemmacOS Operating System DetailsNo response SQLModel Version0.0.8 Python Version3.9.13 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Was this ever resolved? I am also using pgvector. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot! This helped |
Beta Was this translation helpful? Give feedback.
Yeah I fixed it by changing:
to: