sqlitevec

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: LGPL-3.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sqlitevec is a vector.Store backed by SQLite with the sqlite-vec extension. The extension is compiled in (CGO) and registered for every SQLite connection the process opens afterwards, so an application that opens its connections elsewhere (through an ORM, say) imports this package, blank if need be, before it opens the first one.

Each index has a table set of its own; the vectors are BLOB columns of packed float32s, and a search ranks the chunks of its scope exactly with sqlite-vec's vec_distance_cosine, so there is no cap on how many it returns.

SQLite allows one writer at a time. Every write transaction of the store starts with a write, so it takes the write lock as it begins, and a busy timeout makes a second writer wait for its turn rather than fail with "database is locked". Open a file database (every connection of an in-memory one is a database of its own) with a busy timeout, and in WAL mode so that readers do not wait for writers, for example with github.com/mattn/go-sqlite3:

db, err := sql.Open("sqlite3", "search.db?_busy_timeout=5000&_journal_mode=WAL")

_txlock=immediate is not needed for this store; an application whose own transactions on the same database read before they write still needs it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*options)

Option customizes a Store.

func WithGeneration

func WithGeneration(generation string) Option

WithGeneration keeps the store's tables apart from those of every other generation in the same database, so the vectors of a different embedding model can be built next to the current ones before an application switches over; DropGeneration retires the old ones afterwards. generation is "" (the default) or 1-12 lowercase letters and digits. An index's tables are named ss_<generation>_<hash>_<suffix>, where <hash> is the first 16 hex digits of the SHA-256 of the index, so any index string makes a safe identifier and two indexes never share tables; the default generation's are ss_<hash>_<suffix>, the names the stores used before generations existed.

type Store

type Store struct {
	*sqlstore.Store
}

Store implements vector.Store on SQLite + sqlite-vec with one physical table set per index (e.g. a tenant) and generation, created by the first write. It is safe for concurrent use.

func New

func New(ctx context.Context, db *sql.DB, dims int, opts ...Option) (*Store, error)

New returns a Store using db and checks the sqlite-vec extension is loaded. dims must match the embedder's Dimensions(); an index whose tables hold vectors of other dimensions fails with vector.ErrDimensions, and the vectors of another model, whatever their size, belong in another generation (WithGeneration).

Jump to

Keyboard shortcuts

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