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 integerI16/INT16: 16-bit integerI32/INT32: 32-bit integerI64/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
BindParameterinstance), 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_noneflag 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
F16F32F64FLOAT16FLOAT32FLOAT64I16I32I64I8INT16INT32INT64INT8hashableFlag, if False, means values from this type aren't hashable.
python_typeReturn the Python type object expected to be returned by instances of this type, if known.
render_bind_castRender bind casts for
BindTyping.RENDER_CASTSmode.render_literal_castrender casts when rendering a value as an inline literal, e.g. with
TypeEngine.literal_processor().should_evaluate_noneIf True, the Python constant
Noneis considered to be handled explicitly by this type.sort_key_functionA sorting function that can be passed as the key to sorted.
length