pgvector

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package pgvector implements vectorsearch.Index against a PostgreSQL database running the pgvector extension. It uses an existing platform/database.Client for connection management and otelsql instrumentation.

Filter contract: QueryRequest.Filter is interpreted as a string SQL fragment appended to the WHERE clause. Pass it as e.g. "metadata->>'kind' = 'doc'". The fragment is concatenated verbatim — callers are responsible for sanitizing any values they interpolate. Use parameter placeholders ($N) only if you also extend the QueryRequest with a corresponding args slice; the current shape is opaque on purpose.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidIdentifier = platformerrors.New("identifier must match [A-Za-z_][A-Za-z0-9_]*")

ErrInvalidIdentifier indicates an index or column name does not meet the bare-identifier constraint required by this provider.

Functions

func ProvideIndex

func ProvideIndex[T any](
	ctx context.Context,
	logger logging.Logger,
	tracerProvider tracing.TracerProvider,
	metricsProvider metrics.Provider,
	cfg *Config,
	db database.Client,
	indexName string,
	cb circuitbreaking.CircuitBreaker,
) (vectorsearch.Index[T], error)

ProvideIndex builds a pgvector-backed vectorsearch.Index. It runs an idempotent schema migration on construction (CREATE EXTENSION + CREATE TABLE + CREATE INDEX) so the table for indexName is guaranteed to exist after the constructor returns.

Types

type Config

type Config struct {
	MetadataColumn string                      `env:"METADATA_COLUMN" envDefault:"metadata" json:"metadataColumn"`
	Metric         vectorsearch.DistanceMetric `env:"METRIC"          envDefault:"cosine"   json:"metric"`
	Dimension      int                         `env:"DIMENSION"       json:"dimension"`
}

Config configures the pgvector-backed vectorsearch.Index.

Dimension must match the embedding dimension produced by the upstream model and is enforced at index creation time via vector(<Dimension>).

MetadataColumn is the JSONB column used to store the per-vector payload (the generic T type). It defaults to "metadata" and must be a bare identifier.

func (*Config) ValidateWithContext

func (cfg *Config) ValidateWithContext(ctx context.Context) error

ValidateWithContext validates a Config struct.

Jump to

Keyboard shortcuts

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