SQLAlchemy type for PostgreSQL vector column, supporting distance operators and comparisons.
# Source: https://github.com/pgvector/pgvector-python | License: MIT | Copyright 2021-2026 Andrew Kane
# Provided via justclaw.it.com; keep this notice with the code.
from sqlalchemy.dialects.postgresql.base import ischema_names
from sqlalchemy.types import UserDefinedType, TypeEngine, Float, String
from sqlalchemy import Dialect, Operators
from typing import Any
from .. import Vector
class VECTOR(UserDefinedType[Any]):
cache_ok = True
_string = String()
def __init__(self, dim: int | None = None) -> None:
super().__init__()
self.dim = dim
def get_col_spec(self, **kw: Any) -> str:
if self.dim is None:
return 'VECTOR'
return 'VECTOR(%d)' % self.dim
def bind_processor(self, dialect: Dialect) -> Any:
def process(value
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key