pgvector

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package pgvector provides a PostgreSQL-backed vector driver using the pgvector extension.

Index

Constants

View Source
const (
	// DefaultTableName is the default table name for storing vector documents.
	DefaultTableName = "tapes_embeddings"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ConnString is the PostgreSQL connection string (e.g. "postgres://user:pass@host:5432/db").
	ConnString string

	// TableName is the name of the table to store embeddings in.
	// Defaults to DefaultTableName if empty.
	TableName string

	// Dimensions is the number of dimensions for the embedding vectors.
	Dimensions uint
}

Config holds configuration for the pgvector driver.

type Driver

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

Driver implements vector.Driver using PostgreSQL with the pgvector extension.

func NewDriver

func NewDriver(c Config, log *slog.Logger) (*Driver, error)

NewDriver creates a new pgvector driver connected to PostgreSQL.

func (*Driver) Add

func (d *Driver) Add(ctx context.Context, docs []vector.Document) error

Add stores documents with their embeddings. If a document with the same ID already exists, it is updated.

func (*Driver) Close

func (d *Driver) Close() error

Close releases resources held by the driver.

func (*Driver) Delete

func (d *Driver) Delete(ctx context.Context, ids []string) error

Delete removes documents by their IDs.

func (*Driver) Get

func (d *Driver) Get(ctx context.Context, ids []string) ([]vector.Document, error)

Get retrieves documents by their IDs.

func (*Driver) Query

func (d *Driver) Query(ctx context.Context, embedding []float32, topK int) ([]vector.QueryResult, error)

Query finds the topK most similar documents to the given embedding. Uses cosine distance; results are ordered by similarity (highest first).

Jump to

Keyboard shortcuts

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