pgvector

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package pgvector provides PostgreSQL+pgvector based vector storage for engram.

Package pgvector provides PostgreSQL+pgvector based vector storage for engram.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchSyncConfig

type BatchSyncConfig struct {
	BatchSize       int // Number of items per batch (default: 50)
	ProgressLogFreq int // Log progress every N items (default: 100)
}

BatchSyncConfig configures batch synchronization behavior.

func DefaultBatchSyncConfig

func DefaultBatchSyncConfig() BatchSyncConfig

DefaultBatchSyncConfig returns sensible defaults for batch sync.

type Client

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

Client provides vector operations via PostgreSQL+pgvector.

func NewClient

func NewClient(cfg Config) (*Client, error)

NewClient creates a new pgvector client.

func (*Client) AddDocuments

func (c *Client) AddDocuments(ctx context.Context, docs []vector.Document) error

AddDocuments adds documents with their embeddings to the vector store.

func (*Client) Close

func (c *Client) Close() error

Close releases the underlying sql.DB connection.

func (*Client) Count

func (c *Client) Count(ctx context.Context) (int64, error)

Count returns the total number of vectors in the store.

func (*Client) DeleteByObservationID

func (c *Client) DeleteByObservationID(ctx context.Context, obsID int64) error

DeleteByObservationID removes all vectors associated with an observation ID. Doc IDs for observations follow the pattern obs_{id}_{field}.

func (*Client) DeleteDocuments

func (c *Client) DeleteDocuments(ctx context.Context, ids []string) error

DeleteDocuments removes documents by their IDs.

func (*Client) GetCacheStats

func (c *Client) GetCacheStats() vector.CacheStatsSnapshot

GetCacheStats returns cache performance statistics. pgvector does not maintain a local embedding result cache, so all counters are zero.

func (*Client) GetHealthStats

func (c *Client) GetHealthStats(ctx context.Context) (*vector.HealthStats, error)

GetHealthStats returns comprehensive health statistics using existing interface methods.

func (*Client) GetMetrics added in v1.1.0

func (c *Client) GetMetrics(ctx context.Context) vector.VectorMetricsSnapshot

GetMetrics returns real query instrumentation metrics.

func (*Client) GetStaleVectors

func (c *Client) GetStaleVectors(ctx context.Context) ([]vector.StaleVectorInfo, error)

GetStaleVectors returns info about vectors with mismatched or null model versions.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected checks whether the PostgreSQL connection is alive.

func (*Client) ModelVersion

func (c *Client) ModelVersion() string

ModelVersion returns the current embedding model version.

func (*Client) NeedsRebuild

func (c *Client) NeedsRebuild(ctx context.Context) (bool, string)

NeedsRebuild reports whether any vectors use a stale model version.

func (*Client) Query

func (c *Client) Query(ctx context.Context, query string, limit int, where vector.WhereFilter) ([]vector.QueryResult, error)

Query performs a vector similarity search using cosine distance.

type Config

type Config struct {
	DB       *gorm.DB           // PostgreSQL GORM connection (required)
	EmbedSvc *embedding.Service // Embedding service (required)
}

Config holds configuration for the pgvector client.

type Sync

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

Sync provides synchronization between PostgreSQL data and vector embeddings.

func NewSync

func NewSync(client *Client) *Sync

NewSync creates a new sync service.

func (*Sync) BatchSyncObservations

func (s *Sync) BatchSyncObservations(ctx context.Context, observations []*models.Observation, cfg BatchSyncConfig) (synced int, errors int)

BatchSyncObservations syncs multiple observations efficiently in batches. This reduces memory pressure during large rebuilds by processing in chunks.

func (*Sync) BatchSyncPrompts

func (s *Sync) BatchSyncPrompts(ctx context.Context, prompts []*models.UserPromptWithSession, cfg BatchSyncConfig) (synced int, errors int)

BatchSyncPrompts syncs multiple user prompts efficiently in batches.

func (*Sync) BatchSyncSummaries

func (s *Sync) BatchSyncSummaries(ctx context.Context, summaries []*models.SessionSummary, cfg BatchSyncConfig) (synced int, errors int)

BatchSyncSummaries syncs multiple summaries efficiently in batches.

func (*Sync) DeleteObservations

func (s *Sync) DeleteObservations(ctx context.Context, observationIDs []int64) error

DeleteObservations removes observation documents from the vector store.

func (*Sync) DeletePatterns

func (s *Sync) DeletePatterns(ctx context.Context, patternIDs []int64) error

DeletePatterns removes pattern documents from the vector store.

func (*Sync) DeleteUserPrompts

func (s *Sync) DeleteUserPrompts(ctx context.Context, promptIDs []int64) error

DeleteUserPrompts removes user prompt documents from the vector store.

func (*Sync) SyncObservation

func (s *Sync) SyncObservation(ctx context.Context, obs *models.Observation) error

SyncObservation syncs a single observation to the vector store.

func (*Sync) SyncPattern

func (s *Sync) SyncPattern(ctx context.Context, pattern *models.Pattern) error

SyncPattern syncs a single pattern to the vector store.

func (*Sync) SyncSummary

func (s *Sync) SyncSummary(ctx context.Context, summary *models.SessionSummary) error

SyncSummary syncs a single session summary to the vector store.

func (*Sync) SyncUserPrompt

func (s *Sync) SyncUserPrompt(ctx context.Context, prompt *models.UserPromptWithSession) error

SyncUserPrompt syncs a single user prompt to the vector store.

Jump to

Keyboard shortcuts

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