From 43535a6372aee9cbaf2502ab530429b9e7177d8d Mon Sep 17 00:00:00 2001 From: Felix Karg Date: Sun, 24 Aug 2025 17:30:01 +0200 Subject: [PATCH 1/3] Refactor imports to include HalfVector and SparseVector aliases Closes #142 SQLModel SQLAlchemy ArgumentError when using HalfVector instead of Vector --- pgvector/sqlalchemy/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pgvector/sqlalchemy/__init__.py b/pgvector/sqlalchemy/__init__.py index 52adf88..ca10e3e 100644 --- a/pgvector/sqlalchemy/__init__.py +++ b/pgvector/sqlalchemy/__init__.py @@ -1,12 +1,12 @@ from .bit import BIT from .functions import avg, sum from .halfvec import HALFVEC +from .halfvec import HALFVEC as HalfVector from .sparsevec import SPARSEVEC +from .sparsevec import SPARSEVEC as SparseVector from .vector import VECTOR from .vector import VECTOR as Vector -# TODO remove -from .. import HalfVector, SparseVector __all__ = [ 'Vector', From 159c9e199a8aaa5a2065f9be6ea9316830abf4cd Mon Sep 17 00:00:00 2001 From: Felix Karg Date: Wed, 27 Aug 2025 20:01:43 +0200 Subject: [PATCH 2/3] Add import alias for BIT and rearrange __all__ exports --- pgvector/sqlalchemy/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pgvector/sqlalchemy/__init__.py b/pgvector/sqlalchemy/__init__.py index ca10e3e..7b145ee 100644 --- a/pgvector/sqlalchemy/__init__.py +++ b/pgvector/sqlalchemy/__init__.py @@ -1,4 +1,5 @@ from .bit import BIT +from .bit import BIT as Bit from .functions import avg, sum from .halfvec import HALFVEC from .halfvec import HALFVEC as HalfVector @@ -11,11 +12,12 @@ __all__ = [ 'Vector', 'VECTOR', - 'HALFVEC', + 'Bit', 'BIT', - 'SPARSEVEC', 'HalfVector', + 'HALFVEC', 'SparseVector', + 'SPARSEVEC', 'avg', 'sum' ] From e4ddda245bb7208a02cdc2621761dd7eeb5ca0be Mon Sep 17 00:00:00 2001 From: Felix Karg Date: Wed, 27 Aug 2025 20:02:49 +0200 Subject: [PATCH 3/3] docs: make README consistent with PascalCase names like other libraries --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7c302b1..1551f38 100644 --- a/README.md +++ b/README.md @@ -183,7 +183,7 @@ class Item(Base): embedding = mapped_column(Vector(3)) ``` -Also supports `HALFVEC`, `BIT`, and `SPARSEVEC` +Also supports `HalfVector`, `Bit`, and `SparseVector` Insert a vector @@ -252,12 +252,12 @@ Use `vector_ip_ops` for inner product and `vector_cosine_ops` for cosine distanc Index vectors at half-precision ```python -from pgvector.sqlalchemy import HALFVEC +from pgvector.sqlalchemy import HalfVector from sqlalchemy.sql import func index = Index( 'my_index', - func.cast(Item.embedding, HALFVEC(3)).label('embedding'), + func.cast(Item.embedding, HalfVector(3)).label('embedding'), postgresql_using='hnsw', postgresql_with={'m': 16, 'ef_construction': 64}, postgresql_ops={'embedding': 'halfvec_l2_ops'} @@ -267,7 +267,7 @@ index = Index( Get the nearest neighbors ```python -order = func.cast(Item.embedding, HALFVEC(3)).l2_distance([3, 1, 2]) +order = func.cast(Item.embedding, HalfVector(3)).l2_distance([3, 1, 2]) session.scalars(select(Item).order_by(order).limit(5)) ``` @@ -335,7 +335,7 @@ class Item(SQLModel, table=True): embedding: Any = Field(sa_type=Vector(3)) ``` -Also supports `HALFVEC`, `BIT`, and `SPARSEVEC` +Also supports `HalfVector`, `Bit`, and `SparseVector` Insert a vector