Documentation
¶
Overview ¶
Package postgres provides a PostgreSQL + pgvector implementation of the core.Store interface.
The store handles everything: connection, schema migration, embeddings, and retrieval. Callers only need to provide a DSN.
Usage:
store, err := postgres.NewStore("postgres://postgres@localhost/loci?sslmode=disable")
if err != nil { ... }
defer store.Close()
Index ¶
- func Migrate(ctx context.Context, pool *pgxpool.Pool) error
- type HealthCheckable
- type Migration
- type RetrieverConfig
- type ScoredRetriever
- type Store
- func (s *Store) AddFactTags(ctx context.Context, factID string, tags []string) error
- func (s *Store) ArchiveFacts(ctx context.Context, factIDs []string) (int, error)
- func (s *Store) CleanWriteBackQueue(ctx context.Context, cutoffTimestamp int64) (int64, error)
- func (s *Store) ClearEmbeddings(ctx context.Context) error
- func (s *Store) Close() error
- func (s *Store) CompleteWriteBack(ctx context.Context, id int64) error
- func (s *Store) ComputeMemoryDiff(ctx context.Context, entityID string, fromTime, toTime int64) (*core.MemoryDiff, error)
- func (s *Store) CreateSnapshot(ctx context.Context, entityID string) (*core.MemorySnapshot, error)
- func (s *Store) DecayAllFacts(ctx context.Context, decayFactor float64, archiveBelow float64) (int64, error)
- func (s *Store) DeleteEntity(ctx context.Context, id string) error
- func (s *Store) DeleteEpisodesByEntity(ctx context.Context, entityID string) error
- func (s *Store) DeleteFactRelations(ctx context.Context, factID string) error
- func (s *Store) DeleteFactsByEntity(ctx context.Context, entityID string) error
- func (s *Store) DeleteNotification(ctx context.Context, id string) error
- func (s *Store) DeleteOldNotifications(ctx context.Context, cutoffTime int64) (int64, error)
- func (s *Store) DeleteSessionsByEntity(ctx context.Context, entityID string) error
- func (s *Store) DeleteSessionsOlderThan(ctx context.Context, cutoffTime int64) (int64, error)
- func (s *Store) DequeueWriteBack(ctx context.Context) (*core.WriteBackQueueItem, error)
- func (s *Store) EnqueueWriteBack(ctx context.Context, payload string) (int64, error)
- func (s *Store) FailWriteBack(ctx context.Context, id int64) error
- func (s *Store) FollowEntity(ctx context.Context, follow core.EntityFollow) error
- func (s *Store) GetAllEntities(ctx context.Context) ([]core.Entity, error)
- func (s *Store) GetChangelog(ctx context.Context, entityID string, fromTime, toTime int64, ...) ([]core.FactChangelogEntry, error)
- func (s *Store) GetEmbedding(ctx context.Context, factID string) ([]float32, error)
- func (s *Store) GetEmbeddingCount(ctx context.Context) (int64, error)
- func (s *Store) GetEmbeddingMetadata(ctx context.Context) (*core.EmbeddingMetadata, error)
- func (s *Store) GetEntity(ctx context.Context, id string) (*core.Entity, error)
- func (s *Store) GetEpisode(ctx context.Context, id string) (*core.Episode, error)
- func (s *Store) GetFact(ctx context.Context, id string) (*core.Fact, error)
- func (s *Store) GetFactCount(ctx context.Context) (int64, error)
- func (s *Store) GetFactLineage(ctx context.Context, factID string) (*core.FactLineage, error)
- func (s *Store) GetFactRelations(ctx context.Context, factID string) ([]core.FactRelation, error)
- func (s *Store) GetFactRelationsBatch(ctx context.Context, factIDs []string) (map[string][]core.FactRelation, error)
- func (s *Store) GetFactTags(ctx context.Context, factID string) ([]string, error)
- func (s *Store) GetFactsByEntity(ctx context.Context, entityID string) ([]core.Fact, error)
- func (s *Store) GetFactsByIDs(ctx context.Context, ids []string) ([]core.Fact, error)
- func (s *Store) GetFollowers(ctx context.Context, followingEntityID string) ([]core.EntityFollow, error)
- func (s *Store) GetFollowing(ctx context.Context, followerEntityID string) ([]core.EntityFollow, error)
- func (s *Store) GetNotifications(ctx context.Context, entityID string, unreadOnly bool) ([]core.Notification, error)
- func (s *Store) GetRelatedEntities(ctx context.Context, entityID string, depth int) ([]core.EntityRelation, error)
- func (s *Store) GetSession(ctx context.Context, sessionID string) (*core.Session, error)
- func (s *Store) GetSessionTurns(ctx context.Context, sessionID string) ([]core.SessionTurn, error)
- func (s *Store) GetSessionsByEntity(ctx context.Context, entityID string) ([]core.Session, error)
- func (s *Store) GetSnapshots(ctx context.Context, entityID string) ([]core.MemorySnapshot, error)
- func (s *Store) GetTemporalFactsByEntity(ctx context.Context, entityID string) ([]core.Fact, error)
- func (s *Store) GetTimeline(ctx context.Context, entityID string, days int) ([]core.DaySummary, error)
- func (s *Store) GetUnconsolidatedEpisodes(ctx context.Context, entityID string) ([]core.Episode, error)
- func (s *Store) GetWriteBackStats(ctx context.Context) (core.WriteBackStats, error)
- func (s *Store) HealthCheck() error
- func (s *Store) MarkConsolidated(ctx context.Context, episodeID string) error
- func (s *Store) MarkNotificationRead(ctx context.Context, id string) error
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) Pool() *pgxpool.Pool
- func (s *Store) RecordSessionFact(ctx context.Context, sessionID, factID string) error
- func (s *Store) RecordSessionTurn(ctx context.Context, turn core.SessionTurn) error
- func (s *Store) RecoverPendingWriteBacks(ctx context.Context) ([]core.WriteBackQueueItem, error)
- func (s *Store) SearchFacts(ctx context.Context, query core.SearchQuery) ([]core.ScoredFact, error)
- func (s *Store) SearchFactsByTags(ctx context.Context, tags []string, limit int) ([]core.ScoredFact, error)
- func (s *Store) SetEmbeddingMetadata(ctx context.Context, modelName string, dimensions int) error
- func (s *Store) StoreEmbedding(ctx context.Context, factID string, embedding []float32) error
- func (s *Store) SupersedeFact(ctx context.Context, oldID, newID string) error
- func (s *Store) UnfollowEntity(ctx context.Context, followerEntityID, followingEntityID string) error
- func (s *Store) UpsertEntity(ctx context.Context, entity core.Entity) error
- func (s *Store) WriteChangelog(ctx context.Context, entry core.FactChangelogEntry) error
- func (s *Store) WriteEntityRelations(ctx context.Context, relations []core.EntityRelation) error
- func (s *Store) WriteEpisode(ctx context.Context, ep core.Episode) error
- func (s *Store) WriteEpisodes(ctx context.Context, episodes []core.Episode) (*core.BatchResult, error)
- func (s *Store) WriteFact(ctx context.Context, fact core.Fact) error
- func (s *Store) WriteFactRelation(ctx context.Context, rel core.FactRelation) error
- func (s *Store) WriteFacts(ctx context.Context, facts []core.Fact) (*core.BatchResult, error)
- func (s *Store) WriteNotification(ctx context.Context, n core.Notification) error
- func (s *Store) WriteSession(ctx context.Context, session core.Session) error
- type StoreConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HealthCheckable ¶
type HealthCheckable interface {
HealthCheck() error
}
HealthCheckable is implemented by the store.
type Migration ¶
type Migration struct {
ID int
Name string
Apply func(ctx context.Context, pool *pgxpool.Pool) error
}
Migration defines a single schema change step.
type RetrieverConfig ¶
type RetrieverConfig struct {
SemanticWeight float64
RecencyWeight float64
StrengthWeight float64
EndorsementWeight float64
MinStrength float64
GraphExpansion string
IntentBoostFactor float64
EnableIntentRouting bool
FilterContradictions bool
}
RetrieverConfig configures the scored retriever.
func DefaultRetrieverConfig ¶
func DefaultRetrieverConfig() RetrieverConfig
DefaultRetrieverConfig returns sensible defaults.
type ScoredRetriever ¶
type ScoredRetriever struct {
// contains filtered or unexported fields
}
ScoredRetriever implements core.Retriever using pgvector KNN + scoring.
func NewScoredRetriever ¶
func NewScoredRetriever(store *Store, embedder core.Embedder, cfg RetrieverConfig) *ScoredRetriever
NewScoredRetriever creates a retriever using pgvector KNN.
func (*ScoredRetriever) Retrieve ¶
func (r *ScoredRetriever) Retrieve(ctx context.Context, query core.RetrievalQuery) ([]core.ScoredFact, error)
Retrieve performs semantic + scoring retrieval.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements core.Store using PostgreSQL + pgvector.
func NewStore ¶
func NewStore(dsn string, cfg StoreConfig) (*Store, error)
NewStore connects to PostgreSQL, enables pgvector, and runs migrations. The caller is blind to internals — just pass a DSN.
Examples:
postgres://postgres@localhost/loci?sslmode=disable host=localhost user=postgres dbname=loci sslmode=disable
func (*Store) AddFactTags ¶
func (*Store) ArchiveFacts ¶
func (*Store) CleanWriteBackQueue ¶ added in v1.0.3
func (*Store) CompleteWriteBack ¶
func (*Store) ComputeMemoryDiff ¶
func (*Store) CreateSnapshot ¶
func (*Store) DecayAllFacts ¶ added in v1.0.3
func (*Store) DeleteEpisodesByEntity ¶
func (*Store) DeleteFactRelations ¶
func (*Store) DeleteFactsByEntity ¶
func (*Store) DeleteNotification ¶
func (*Store) DeleteOldNotifications ¶
func (*Store) DeleteSessionsByEntity ¶
func (*Store) DeleteSessionsOlderThan ¶
func (*Store) DequeueWriteBack ¶
func (*Store) EnqueueWriteBack ¶
func (*Store) FollowEntity ¶
func (*Store) GetAllEntities ¶
func (*Store) GetChangelog ¶
func (*Store) GetEmbedding ¶
func (*Store) GetEmbeddingCount ¶
func (*Store) GetEmbeddingMetadata ¶
func (*Store) GetEpisode ¶
func (*Store) GetFactLineage ¶
func (*Store) GetFactRelations ¶
func (*Store) GetFactRelationsBatch ¶ added in v1.1.0
func (*Store) GetFactTags ¶
func (*Store) GetFactsByEntity ¶
func (*Store) GetFactsByIDs ¶ added in v1.1.0
func (*Store) GetFollowers ¶
func (*Store) GetFollowing ¶
func (*Store) GetNotifications ¶
func (*Store) GetRelatedEntities ¶
func (*Store) GetSession ¶
func (*Store) GetSessionTurns ¶
func (*Store) GetSessionsByEntity ¶
func (*Store) GetSnapshots ¶
func (*Store) GetTemporalFactsByEntity ¶ added in v1.1.0
func (*Store) GetTimeline ¶
func (*Store) GetUnconsolidatedEpisodes ¶
func (*Store) GetWriteBackStats ¶
func (*Store) HealthCheck ¶
func (*Store) MarkConsolidated ¶
func (*Store) MarkNotificationRead ¶
func (*Store) RecordSessionFact ¶
func (*Store) RecordSessionTurn ¶
func (*Store) RecoverPendingWriteBacks ¶
func (*Store) SearchFacts ¶
func (s *Store) SearchFacts(ctx context.Context, query core.SearchQuery) ([]core.ScoredFact, error)
func (*Store) SearchFactsByTags ¶
func (*Store) SetEmbeddingMetadata ¶
func (*Store) StoreEmbedding ¶
func (*Store) SupersedeFact ¶
func (*Store) UnfollowEntity ¶
func (*Store) UpsertEntity ¶
func (*Store) WriteChangelog ¶
func (*Store) WriteEntityRelations ¶
func (*Store) WriteEpisode ¶
func (*Store) WriteEpisodes ¶
func (*Store) WriteFactRelation ¶
func (*Store) WriteFacts ¶
func (*Store) WriteNotification ¶
type StoreConfig ¶ added in v1.1.0
type StoreConfig struct {
MaxConns int32
MinConns int32
MaxConnLifetime time.Duration
MaxConnIdleTime time.Duration
QueryTimeout time.Duration
}
StoreConfig configures the PostgreSQL connection pool.
func DefaultStoreConfig ¶ added in v1.1.0
func DefaultStoreConfig() StoreConfig
DefaultStoreConfig returns safe production defaults.