Documentation
¶
Index ¶
- type DB
- func (db *DB) BatchUpsertEntries(ctx context.Context, entries []domain.Entry) (int, error)
- func (db *DB) Close()
- func (db *DB) Counts(ctx context.Context) (total, embedded int64, err error)
- func (db *DB) DeleteEntries(ctx context.Context, ids []uuid.UUID) (int64, error)
- func (db *DB) DeleteEntry(ctx context.Context, id uuid.UUID) error
- func (db *DB) GetRecent(ctx context.Context, limit int, agentID string) ([]domain.Entry, error)
- func (db *DB) GetUnembedded(ctx context.Context) ([]domain.Entry, error)
- func (db *DB) Healthy(ctx context.Context) bool
- func (db *DB) InsertEntry(ctx context.Context, e domain.Entry) (domain.InsertResult, error)
- func (db *DB) ListAllEntries(ctx context.Context) ([]domain.Entry, error)
- func (db *DB) Migrate(ctx context.Context, migrationDir fs.FS) error
- func (db *DB) SearchSimilar(ctx context.Context, p domain.SearchParams) ([]domain.SearchResult, error)
- func (db *DB) TruncateEntries(ctx context.Context) error
- func (db *DB) UpdateEmbedding(ctx context.Context, id uuid.UUID, vec []float32) error
- func (db *DB) UpsertEntry(ctx context.Context, e domain.Entry) error
- type Pool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps a Pool and provides all Postgres operations for Eidetic.
func NewDB ¶
NewDB connects to Postgres and returns a DB. The pool is ready to use immediately; callers should defer DB.Close.
func NewDBFromPool ¶ added in v0.5.0
NewDBFromPool creates a DB from an existing Pool implementation. Useful for testing with pgxmock.
func (*DB) BatchUpsertEntries ¶
BatchUpsertEntries upserts entries in batches for better performance during reindex. Returns the number of successfully upserted entries.
func (*DB) DeleteEntries ¶ added in v0.3.0
DeleteEntries removes multiple entries by ID in a single batch.
func (*DB) DeleteEntry ¶ added in v0.3.0
DeleteEntry removes a single entry by ID.
func (*DB) GetUnembedded ¶
GetUnembedded returns all entries that have no embedding, ordered by created_at ascending. Used at startup to re-queue pending embed jobs.
func (*DB) InsertEntry ¶
InsertEntry inserts a new entry (without an embedding). On duplicate (same agent_id + content_hash), it updates timestamp and tags instead, returning the existing row's ID and Deduplicated=true.
func (*DB) ListAllEntries ¶ added in v0.3.0
ListAllEntries returns all entries ordered by timestamp ascending.
func (*DB) Migrate ¶ added in v0.4.0
Migrate applies any unapplied SQL migrations from the provided filesystem. Migration files must be named like "001_init.sql" — they are sorted lexicographically and executed in order. Each migration is expected to insert its version (filename without .sql) into the migrations table; already-applied versions are skipped.
Call once at startup, after NewDB, before serving traffic.
func (*DB) SearchSimilar ¶
func (db *DB) SearchSimilar(ctx context.Context, p domain.SearchParams) ([]domain.SearchResult, error)
SearchSimilar runs a cosine-similarity search against embedded entries. When p.Hybrid is true and p.QueryText is set, it combines vector similarity with Postgres full-text ranking (ts_rank) using Reciprocal Rank Fusion, plus a small temporal decay boost for recency.
func (*DB) TruncateEntries ¶
TruncateEntries removes all rows from the entries table. Used by reindex.
func (*DB) UpdateEmbedding ¶
UpdateEmbedding stores the computed vector for an entry.
type Pool ¶ added in v0.5.0
type Pool interface {
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
Ping(ctx context.Context) error
Close()
}
Pool is the interface satisfied by *pgxpool.Pool and pgxmock for testing.