sqlalchemy_singlestoredb.VectorKey

class sqlalchemy_singlestoredb.VectorKey(*columns: str, name: str | None = None, index_options: str | Dict[str, Any] | None = None)

SingleStore VECTOR INDEX DDL element.

Represents a VECTOR INDEX for similarity search on vector data columns, enabling fast nearest-neighbor searches for AI/ML applications.

Parameters:
  • *columns (str) – Variable number of column names to include in the vector index. Usually a single vector column.

  • name (str, optional, keyword-only) – Index name for the vector index. If not provided, SingleStore will auto-generate a name.

  • index_options (str or Dict[str, Any], optional, keyword-only) – Index options for the vector index. Can be either a JSON string or a dictionary that will be automatically JSON-serialized. Common metric types: ‘EUCLIDEAN_DISTANCE’, ‘DOT_PRODUCT’, ‘COSINE_SIMILARITY’

Examples

Basic vector index:

>>> VectorKey('embedding')

Named vector index:

>>> VectorKey('embedding', name='vec_idx')

Vector index with metric type (dict):

>>> VectorKey('embedding', index_options={'metric_type': 'COSINE_SIMILARITY'})

Vector index with metric type (string):

>>> VectorKey('embedding', index_options='{"metric_type":"EUCLIDEAN_DISTANCE"}')

Table Usage:

from sqlalchemy import Column, Integer, MetaData, Table
from sqlalchemy_singlestoredb import VECTOR, VectorKey
metadata = MetaData()
embeddings = Table(
    'embeddings', metadata,
    Column('id', Integer, primary_key=True),
    Column('embedding', VECTOR(1536)),
    singlestoredb_vector_keys=[VectorKey('embedding')],
)
# Named vector index with options
documents = Table(
    'documents', metadata,
    Column('id', Integer, primary_key=True),
    Column('embedding', VECTOR(768)),
    singlestoredb_vector_keys=[
        VectorKey(
            'embedding',
            name='doc_vec_idx',
            index_options={'metric_type': 'COSINE_SIMILARITY'},
        ),
    ],
)

ORM Usage:

from sqlalchemy import Column, Integer
from sqlalchemy.orm import declarative_base
from sqlalchemy_singlestoredb import VECTOR, VectorKey
Base = declarative_base()
class Embedding(Base):
    __tablename__ = 'embeddings'
    id = Column(Integer, primary_key=True)
    embedding = Column(VECTOR(1536))
    __table_args__ = {
        'singlestoredb_vector_keys': [VectorKey('embedding')],
    }
class Document(Base):
    __tablename__ = 'documents'
    id = Column(Integer, primary_key=True)
    embedding = Column(VECTOR(768))
    __table_args__ = {
        'singlestoredb_vector_keys': [
            VectorKey(
                'embedding',
                name='doc_vec_idx',
                index_options={'metric_type': 'COSINE_SIMILARITY'},
            ),
        ],
    }
__init__(*columns: str, name: str | None = None, index_options: str | Dict[str, Any] | None = None) None

Methods

__init__(*columns[, name, index_options])

against(target)

Return a copy of this _schema.ExecutableDDLElement which will include the given target.

compare(other, **kw)

Compare this _expression.ClauseElement to the given _expression.ClauseElement.

compile([bind, dialect])

Compile this SQL expression.

execute_if([dialect, callable_, state])

Return a callable that will execute this _ddl.ExecutableDDLElement conditionally within an event handler.

execution_options(**kw)

Set non-SQL options for the statement which take effect during execution.

get_children(*[, omit_attrs])

Return immediate child visitors.HasTraverseInternals elements of this visitors.HasTraverseInternals.

get_execution_options()

Get the non-SQL options which will take effect during execution.

memoized_instancemethod(fn)

Decorate a method memoize its return value.

options(*options)

Apply options to this statement.

params([_ClauseElement__optionaldict])

Return a copy with _expression.bindparam() elements replaced.

self_group([against])

Apply a 'grouping' to this _expression.ClauseElement.

unique_params([_ClauseElement__optionaldict])

Return a copy with _expression.bindparam() elements replaced.

Attributes

allows_lambda

description

entity_namespace

inherit_cache

Indicate if this HasCacheKey instance should make use of the cache key generation scheme used by its immediate superclass.

is_clause_element

is_delete

is_dml

is_from_statement

is_insert

is_select

is_selectable

is_text

is_update

stringify_dialect

supports_execution

target

uses_inspection

name

columns

index_options

negation_clause

proxy_set