pgvec

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: 9 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 pgvec is a vector.Store backed by Postgres with the pgvector extension. The database user must be able to run CREATE EXTENSION vector, or the extension must already be installed.

Each index has a table set of its own, created by the first write; a role that only reads can search an index another role created. A search ranks the chunks of its scope exactly: an approximate (HNSW) index would filter the scope only after collecting its nearest rows of the whole table, so a scope without rows among those would come back short. Text columns sort by byte (COLLATE "C"), the order the other stores use.

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 Postgres + pgvector, with one physical table set per index (e.g. a tenant) and generation. 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 ensures the pgvector extension exists. 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