Skip to content

Feat/pgvector numpy support - #93

Open
DavidHein96 wants to merge 2 commits into
sqlc-dev:mainfrom
DavidHein96:feat/pgvector-numpy-support
Open

Feat/pgvector numpy support#93
DavidHein96 wants to merge 2 commits into
sqlc-dev:mainfrom
DavidHein96:feat/pgvector-numpy-support

Conversation

@DavidHein96

Copy link
Copy Markdown

This addresses #61

The default format is a a numpy float 32 to match pgvector

numpy was chosen over pytorch tensor for the lighter dependencies

This might need a special section in the docs though that to actually be able to do this you may need to coerce first to actually ensure the correct form.

def_coerce_embedding(x: NDArray[np.floating]) ->NDArray[np.float32]:
# pgvector elements are single-precision floats; enforce dtype + 1Darr=np.asarray(x, dtype=np.float32)
ifarr.ndim!=1:
raiseValueError(f"embedding must be 1-D, got shape {arr.shape}")
returnarr

As well as some kind of way of registering pgvector

fromsqlalchemyimporteventfrompgvector.psycopgimportregister_vector@event.listens_for(engine, "connect")def_pgvector_connect(dbapi_connection, _):
register_vector(dbapi_connection)

devsteinand others added 2 commits December 16, 2025 18:31
 Add support for PostgreSQL vector type with proper numpy typing:
- Map 'vector' type to NDArray[numpy.float32]
- Auto-import numpy and numpy.typing.NDArray
- Add test case for vector type generation
- Add .DS_Store to .gitignore
This enables type-safe pgvector usage in generated Python code.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@DavidHein96@devstein