pgvector

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Down added in v0.3.0

func Down(ctx context.Context, db *sql.DB) error

Down rolls back the most recently applied pgvector migration. The initial migration's Down is intentionally a no-op (it would destroy all vectors).

func EnsureClean added in v0.3.0

func EnsureClean(ctx context.Context, db *sql.DB) error

EnsureClean returns nil if the database's currently-applied pgvector migration version equals the highest version registered in the binary.

func MaxEmbeddedVersion added in v0.3.0

func MaxEmbeddedVersion() (int64, error)

MaxEmbeddedVersion returns the highest pgvector migration version registered in this binary. Returns 0 if none are registered.

func Status added in v0.3.0

func Status(ctx context.Context, db *sql.DB) error

Status prints applied / pending status of every registered pgvector migration to stdout.

func Up added in v0.3.0

func Up(ctx context.Context, db *sql.DB) error

Up applies all pending pgvector migrations against the supplied DB. The DB must be a *sql.DB (lib/pq driver) — pgvector's runtime path uses pgx, but goose itself targets database/sql.

func Version added in v0.3.0

func Version(ctx context.Context, db *sql.DB) (int64, error)

Version returns the highest pgvector migration version currently applied. Returns 0 against a database that has never been migrated for pgvector.

Types

type Config

type Config struct {
	// URL is the PostgreSQL connection string with pgvector extension
	URL string

	// Dimensions is the embedding vector dimension (default: 1536 for OpenAI ada-002)
	Dimensions int

	// IndexType is the vector index type: "hnsw" or "ivfflat" (default: "hnsw")
	IndexType string

	// DistanceMetric is the distance function: "cosine", "l2", or "inner_product" (default: "cosine")
	DistanceMetric string

	// MaxOpenConns is the maximum number of open connections in the pool
	MaxOpenConns int32

	// MinConns is the minimum number of connections in the pool
	MinConns int32

	// MaxConnLifetime is the maximum lifetime of a connection
	MaxConnLifetime time.Duration

	// MaxConnIdleTime is the maximum idle time of a connection
	MaxConnIdleTime time.Duration

	// ConnTimeout is the connection timeout
	ConnTimeout time.Duration
}

Config holds pgvector connection and index configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a configuration with sensible defaults

type VectorIndex

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

VectorIndex implements the driven.VectorIndex interface using pgvector

func New

func New(ctx context.Context, cfg Config) (*VectorIndex, error)

New creates a new pgvector VectorIndex adapter

func (*VectorIndex) Close

func (v *VectorIndex) Close()

Close closes the connection pool

func (*VectorIndex) Delete

func (v *VectorIndex) Delete(ctx context.Context, id string) error

Delete removes a single embedding by chunk ID

func (*VectorIndex) DeleteBatch

func (v *VectorIndex) DeleteBatch(ctx context.Context, ids []string) error

DeleteBatch removes multiple embeddings by chunk IDs

func (*VectorIndex) DeleteByDocument

func (v *VectorIndex) DeleteByDocument(ctx context.Context, documentID string) error

DeleteByDocument removes all embeddings for a document

func (*VectorIndex) DeleteByDocuments

func (v *VectorIndex) DeleteByDocuments(ctx context.Context, documentIDs []string) error

DeleteByDocuments removes all embeddings for multiple documents in a single operation

func (*VectorIndex) DeleteBySourceAndContainer added in v0.2.1

func (v *VectorIndex) DeleteBySourceAndContainer(ctx context.Context, sourceID, containerID string) error

DeleteBySourceAndContainer removes all embeddings for a specific container within a source Joins with documents table to filter by container_id from document metadata

func (*VectorIndex) HealthCheck

func (v *VectorIndex) HealthCheck(ctx context.Context) error

HealthCheck verifies the connection and vector extension availability

func (*VectorIndex) Index

func (v *VectorIndex) Index(ctx context.Context, id string, documentID string, embedding []float32) error

Index inserts or updates a single embedding

func (*VectorIndex) IndexBatch

func (v *VectorIndex) IndexBatch(ctx context.Context, ids []string, documentIDs []string, sourceIDs []string, contents []string, embeddings [][]float32) error

IndexBatch inserts or updates multiple embeddings with their chunk content using batch operations

func (*VectorIndex) Search

func (v *VectorIndex) Search(ctx context.Context, embedding []float32, k int) ([]string, []float64, error)

Search finds the k most similar chunks by embedding distance

func (*VectorIndex) SearchWithContent

func (v *VectorIndex) SearchWithContent(ctx context.Context, embedding []float32, k int, sourceIDs []string, documentFilter *domain.DocumentIDFilter) ([]driven.VectorSearchResult, error)

SearchWithContent finds similar vectors and returns chunk content alongside IDs/distances. sourceIDs optionally filters results to specific sources (nil or empty = no filter). documentFilter applies the three-case document-id contract; see domain.DocumentIDFilter godoc.

Directories

Path Synopsis
Package migrations holds the pgvector schema migrations as Go code so the embedding dimension (which must appear as a literal in the column type) can be read from PGVECTOR_DIMENSIONS at migrate-time rather than baked into a SQL file at compile-time.
Package migrations holds the pgvector schema migrations as Go code so the embedding dimension (which must appear as a literal in the column type) can be read from PGVECTOR_DIMENSIONS at migrate-time rather than baked into a SQL file at compile-time.

Jump to

Keyboard shortcuts

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