sqlalchemy_singlestoredb.VECTOR

class sqlalchemy_singlestoredb.VECTOR(n_elems: int | None = None, elem_type: str | None = None)

SingleStore VECTOR data type for storing fixed-dimension vectors.

VECTOR is commonly used in AI/ML applications for embeddings and similarity search.

Parameters:
  • n_elems (int, optional) – Number of elements (dimensions) in the vector. Defaults to 1.

  • elem_type (str, optional) –

    Element type for the vector. Defaults to ‘F32’.

    Floating Point Types:

    • F16 / FLOAT16: 16-bit float (half precision)

    • F32 / FLOAT32: 32-bit float (single precision, default)

    • F64 / FLOAT64: 64-bit float (double precision)

    Integer Types:

    • I8 / INT8: 8-bit integer

    • I16 / INT16: 16-bit integer

    • I32 / INT32: 32-bit integer

    • I64 / INT64: 64-bit integer

Examples

Basic vector column:

>>> VECTOR(1536)

With element type:

>>> VECTOR(768, elem_type=VECTOR.F16)

Table Usage:

from sqlalchemy import Column, Integer, MetaData, Table
from sqlalchemy_singlestoredb import VECTOR
metadata = MetaData()
embeddings = Table(
    'embeddings', metadata,
    Column('id', Integer, primary_key=True),
    Column('embedding', VECTOR(1536)),
)
# With different element types
documents = Table(
    'documents', metadata,
    Column('id', Integer, primary_key=True),
    Column('embedding_f16', VECTOR(768, elem_type=VECTOR.F16)),
    Column('embedding_i8', VECTOR(768, elem_type=VECTOR.I8)),
)

ORM Usage:

from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import declarative_base
from sqlalchemy_singlestoredb import VECTOR
Base = declarative_base()
class Embedding(Base):
    __tablename__ = 'embeddings'
    id = Column(Integer, primary_key=True)
    name = Column(String(100))
    embedding = Column(VECTOR(1536))
class Document(Base):
    __tablename__ = 'documents'
    id = Column(Integer, primary_key=True)
    content = Column(String(10000))
    embedding = Column(VECTOR(768, elem_type=VECTOR.F16))
__init__(n_elems: int | None = None, elem_type: str | None = None) None

Construct a LargeBinary type.

Parameters:

length – optional, a length for the column for use in DDL statements, for those binary types that accept a length, such as the MySQL BLOB type.

Methods

__init__([n_elems, elem_type])

Construct a LargeBinary type.

adapt(cls, **kw)

Produce an "adapted" form of this type, given an "impl" class to work with.

as_generic([allow_nulltype])

Return an instance of the generic type corresponding to this type using heuristic rule.

bind_expression(bindvalue)

Given a bind value (i.e. a BindParameter instance), return a SQL expression in its place.

bind_processor(dialect)

Return a conversion function for processing bind values.

coerce_compared_value(op, value)

See TypeEngine.coerce_compared_value() for a description.

column_expression(colexpr)

Given a SELECT column expression, return a wrapping SQL expression.

compare_values(x, y)

Compare two values for equality.

compile([dialect])

Produce a string-compiled form of this TypeEngine.

copy(**kw)

copy_value(value)

dialect_impl(dialect)

Return a dialect-specific implementation for this TypeEngine.

evaluates_none()

Return a copy of this type which has the should_evaluate_none flag set to True.

get_dbapi_type(dbapi)

Return the corresponding type object from the underlying DB-API, if any.

literal_processor(dialect)

Return a conversion function for processing literal values that are to be rendered directly without using binds.

result_processor(dialect, coltype)

Return a conversion function for processing result row values.

with_variant(type_, *dialect_names)

Produce a copy of this type object that will utilize the given type when applied to the dialect of the given name.

Attributes

F16

F32

F64

FLOAT16

FLOAT32

FLOAT64

I16

I32

I64

I8

INT16

INT32

INT64

INT8

hashable

Flag, if False, means values from this type aren't hashable.

python_type

Return the Python type object expected to be returned by instances of this type, if known.

render_bind_cast

Render bind casts for BindTyping.RENDER_CASTS mode.

render_literal_cast

render casts when rendering a value as an inline literal, e.g. with TypeEngine.literal_processor().

should_evaluate_none

If True, the Python constant None is considered to be handled explicitly by this type.

sort_key_function

A sorting function that can be passed as the key to sorted.

length