Skip to content

SQLModel SQLAlchemy ArgumentError when using HalfVector instead of Vector #142

@fkarg

Description

@fkarg

Hi, using a simple model like

from sqlalchemy import SQLModel
from pgvector.sqlalchemy import HalfVector

class Item(SQLModel, table=True):
    embedding: Any = Field(sa_type=HalfVector((3072,)))

Results in a sqlalchemy.exc.ArgumentError: 'SchemaItem' object, such as a 'Column' or a 'Constraint' expected, got HalfVector([3072.0]) when attempting to load it. Using Vector instead works fine.

The difference seems to be that Vector is an alias for VECTOR, which derives from sqlalchemy.types.UserDefinedTypes, whereas HalfVector is distinct from HALFVEC. Using HALFVEC instead appears to work.

It appears to be the same situation for SparseVector.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions