tidb

package module
v0.61.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package tidb indexes precomputed vectors in a Host-provisioned SQL table. Upsert and ranked queries recheck the durable space marker and native fixed vector dimension. Deletion uses the table selected by the Host directly. Dimensions in StoreConfig seeds only a newly created column; no model, tokenization or embedding call occurs inside the adapter. Configured schema, table and column names are native names, not SQL fragments; SQL quotes each name so reserved words retain the same catalog identity. Content requires a utf8mb4 TEXT-family column. CheckDocuments and Upsert derive its byte capacity from the actual native column type and reject the complete batch before writes; the default TEXT schema permits at most 65,535 UTF-8 bytes per document. Other server limits, including transaction row size, still apply. Cosine vectors must have a finite positive squared norm accumulated in float32, on both write and query paths. Nonzero finite coordinates can still underflow or overflow in TiDB's native calculation and produce NULL distances.

Query performs native nearest-neighbor ranking without enumerating metadata. The stored metadata representation cannot implement exact Core predicates natively, so a filtered Query fails with vectorstore.ErrUnsupportedFilter. A Host authorized for the whole table can explicitly QueryByScan or DeleteMatching using a finite vectorstore.ScanBudget. In the scan transaction, the adapter bounds source records and the ID/metadata bytes of its two passes before reading their payload; native ranking, protocol overhead and server work are not included in the payload bound. On exhaustion there is no partial result.

Upsert prepares every vector before issuing writes. One failed row reports prior native acknowledgments, its unknown status and subsequent unattempted rows. The Host owns the DB handle and any decision to reconcile or retry. Rebuild unmarked tables; do not label previously unverified coordinates.

Index

Constants

View Source
const (
	DefaultTableName       = "vector_store"
	DefaultIDColumn        = "id"
	DefaultContentColumn   = "content"
	DefaultMetadataColumn  = "metadata"
	DefaultEmbeddingColumn = "embedding"
	DefaultDistanceMetric  = DistanceCosine
)
View Source
const Provider = "TiDB"

Variables

This section is empty.

Functions

This section is empty.

Types

type DistanceMetric

type DistanceMetric string
const (
	DistanceCosine     DistanceMetric = "COSINE"
	DistanceL2         DistanceMetric = "L2"
	DistanceNegativeIP DistanceMetric = "NEGATIVE_INNER_PRODUCT"
)

The metric is a closed vocabulary because score direction and threshold semantics depend on it: the same raw number means "near" under one metric and "far" under another, so an unrecognized value must be rejected rather than guessed.

func (DistanceMetric) String

func (d DistanceMetric) String() string

func (DistanceMetric) Valid

func (d DistanceMetric) Valid() bool

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(ctx context.Context, config StoreConfig) (*Store, error)

NewStore creates the schema when requested and verifies the current storage contract. The caller owns the database handle.

func (*Store) CheckDocuments added in v0.59.0

func (s *Store) CheckDocuments(ctx context.Context, space vectorstore.SpaceID, docs []*document.Document) error

func (*Store) CheckQuery added in v0.59.0

func (s *Store) CheckQuery(ctx context.Context, space vectorstore.SpaceID, opts vectorstore.SearchOptions) error

func (*Store) DeleteIDs

func (s *Store) DeleteIDs(ctx context.Context, ids []string) error

func (*Store) DeleteMatching added in v0.59.0

func (s *Store) DeleteMatching(ctx context.Context, predicate filter.Predicate, budget vectorstore.ScanBudget) (err error)

func (*Store) Query added in v0.59.0

func (*Store) QueryByScan added in v0.60.0

func (*Store) Upsert added in v0.59.0

func (s *Store) Upsert(ctx context.Context, batch *vectorstore.Batch) (err error)

type StoreConfig

type StoreConfig struct {
	// DB must be a *sql.DB built from github.com/go-sql-driver/mysql pointed
	// at a TiDB v8.4+ cluster.
	DB *sql.DB

	SchemaName      string
	TableName       string
	IDColumn        string
	ContentColumn   string
	MetadataColumn  string
	EmbeddingColumn string

	Space vectorstore.SpaceID

	Dimensions       int
	DistanceMetric   DistanceMetric
	InitializeSchema bool
}

func (StoreConfig) Validate

func (s StoreConfig) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL