pgvector

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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) EnsureTable

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

EnsureTable creates the embeddings table if it doesn't exist. Called during startup to ensure the table is ready.

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, 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) ([]driven.VectorSearchResult, error)

SearchWithContent finds similar vectors and returns chunk content alongside IDs/distances.

Jump to

Keyboard shortcuts

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