Documentation
¶
Overview ¶
Package pgvector provides PostgreSQL+pgvector based vector storage for engram.
Package pgvector provides PostgreSQL+pgvector based vector storage for engram.
Index ¶
- type BatchSyncConfig
- type Client
- func (c *Client) AddDocuments(ctx context.Context, docs []vector.Document) error
- func (c *Client) Close() error
- func (c *Client) Count(ctx context.Context) (int64, error)
- func (c *Client) DeleteByObservationID(ctx context.Context, obsID int64) error
- func (c *Client) DeleteDocuments(ctx context.Context, ids []string) error
- func (c *Client) GetCacheStats() vector.CacheStatsSnapshot
- func (c *Client) GetHealthStats(ctx context.Context) (*vector.HealthStats, error)
- func (c *Client) GetMetrics(ctx context.Context) vector.VectorMetricsSnapshot
- func (c *Client) GetStaleVectors(ctx context.Context) ([]vector.StaleVectorInfo, error)
- func (c *Client) IsConnected() bool
- func (c *Client) ModelVersion() string
- func (c *Client) NeedsRebuild(ctx context.Context) (bool, string)
- func (c *Client) Query(ctx context.Context, query string, limit int, where vector.WhereFilter) ([]vector.QueryResult, error)
- type Config
- type Sync
- func (s *Sync) BatchSyncObservations(ctx context.Context, observations []*models.Observation, cfg BatchSyncConfig) (synced int, errors int)
- func (s *Sync) BatchSyncPrompts(ctx context.Context, prompts []*models.UserPromptWithSession, ...) (synced int, errors int)
- func (s *Sync) BatchSyncSummaries(ctx context.Context, summaries []*models.SessionSummary, cfg BatchSyncConfig) (synced int, errors int)
- func (s *Sync) DeleteObservations(ctx context.Context, observationIDs []int64) error
- func (s *Sync) DeletePatterns(ctx context.Context, patternIDs []int64) error
- func (s *Sync) DeleteUserPrompts(ctx context.Context, promptIDs []int64) error
- func (s *Sync) SyncObservation(ctx context.Context, obs *models.Observation) error
- func (s *Sync) SyncPattern(ctx context.Context, pattern *models.Pattern) error
- func (s *Sync) SyncSummary(ctx context.Context, summary *models.SessionSummary) error
- func (s *Sync) SyncUserPrompt(ctx context.Context, prompt *models.UserPromptWithSession) error
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 (*Client) AddDocuments ¶
AddDocuments adds documents with their embeddings to the vector store.
func (*Client) DeleteByObservationID ¶
DeleteByObservationID removes all vectors associated with an observation ID. Doc IDs for observations follow the pattern obs_{id}_{field}.
func (*Client) DeleteDocuments ¶
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 ¶
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 ¶
GetStaleVectors returns info about vectors with mismatched or null model versions.
func (*Client) IsConnected ¶
IsConnected checks whether the PostgreSQL connection is alive.
func (*Client) ModelVersion ¶
ModelVersion returns the current embedding model version.
func (*Client) NeedsRebuild ¶
NeedsRebuild reports whether any vectors use a stale model version.
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 (*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 ¶
DeleteObservations removes observation documents from the vector store.
func (*Sync) DeletePatterns ¶
DeletePatterns removes pattern documents from the vector store.
func (*Sync) DeleteUserPrompts ¶
DeleteUserPrompts removes user prompt documents from the vector store.
func (*Sync) SyncObservation ¶
SyncObservation syncs a single observation to the vector store.
func (*Sync) SyncPattern ¶
SyncPattern syncs a single pattern to the vector store.
func (*Sync) SyncSummary ¶
SyncSummary syncs a single session summary to the vector store.
func (*Sync) SyncUserPrompt ¶
SyncUserPrompt syncs a single user prompt to the vector store.