pgvector

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package pgvector implements the vector.Backend interface using PostgreSQL with pgvector.

Index

Constants

View Source
const DefaultEmbeddingDimension = 1536

DefaultEmbeddingDimension is the default dimension for the pgvector chunk_embeddings column. Must match the vector(N) in the migration.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

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

Backend implements vector.Backend using pgvector cosine similarity.

func New

func New(db DBTX) *Backend

New creates a new pgvector backend with the default embedding dimension (1536).

func NewWithDimension

func NewWithDimension(db DBTX, dim int) *Backend

NewWithDimension creates a new pgvector backend with a custom embedding dimension.

func (*Backend) Delete

func (b *Backend) Delete(ctx context.Context, id string) error

Delete removes a chunk's embedding.

func (*Backend) DeleteBatch

func (b *Backend) DeleteBatch(ctx context.Context, ids []string) error

DeleteBatch removes multiple embeddings.

func (*Backend) EmbeddingDimension

func (b *Backend) EmbeddingDimension() int

EmbeddingDimension returns the number of dimensions this backend expects.

func (*Backend) Ping

func (b *Backend) Ping(ctx context.Context) error

Ping checks backend connectivity.

func (*Backend) Search

func (b *Backend) Search(ctx context.Context, query []float64, filter vector.Filter, topK int) ([]vector.SearchResult, error)

Search returns chunk IDs ranked by cosine similarity.

func (*Backend) Store

func (b *Backend) Store(ctx context.Context, id string, embedding []float64, metadata map[string]any) error

Store persists a chunk's embedding.

func (*Backend) StoreBatch

func (b *Backend) StoreBatch(ctx context.Context, items []vector.StoreItem) error

StoreBatch persists multiple embeddings.

type DBTX added in v0.1.3

type DBTX interface {
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
}

DBTX is the database interface used by Backend. Both *pgxpool.Pool and *pgx.Conn satisfy this interface.

Jump to

Keyboard shortcuts

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