Changeset 0.30.1 (#200)

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit is contained in:
2026-03-18 13:22:15 +00:00
committed by xcaliber
parent 7d14e6a439
commit 8fee53e440
23 changed files with 1294 additions and 846 deletions

View File

@@ -301,3 +301,36 @@ func (s *MemoryStore) UpsertExtractionLog(ctx context.Context, channelID, userID
`, channelID, userID, lastMessageID, count)
return err
}
// ── v0.30.1 — Memory Compaction ────────────────────────────────────────
func (s *MemoryStore) DecayConfidence(ctx context.Context, olderThan string, decayFactor float64) (int, error) {
res, err := DB.ExecContext(ctx, `
UPDATE memories
SET confidence = confidence * $1,
updated_at = now()
WHERE status = 'active'
AND updated_at < $2::timestamptz
AND confidence > 0.1
`, decayFactor, olderThan)
if err != nil {
return 0, err
}
n, _ := res.RowsAffected()
return int(n), nil
}
func (s *MemoryStore) Prune(ctx context.Context, belowConfidence float64) (int, error) {
res, err := DB.ExecContext(ctx, `
UPDATE memories
SET status = 'archived',
updated_at = now()
WHERE status = 'active'
AND confidence < $1
`, belowConfidence)
if err != nil {
return 0, err
}
n, _ := res.RowsAffected()
return int(n), nil
}

View File

@@ -285,3 +285,36 @@ func (s *MemoryStore) UpsertExtractionLog(ctx context.Context, channelID, userID
`, store.NewID(), channelID, userID, lastMessageID, count)
return err
}
// ── v0.30.1 — Memory Compaction ────────────────────────────────────────
func (s *MemoryStore) DecayConfidence(ctx context.Context, olderThan string, decayFactor float64) (int, error) {
res, err := DB.ExecContext(ctx, `
UPDATE memories
SET confidence = confidence * ?,
updated_at = datetime('now')
WHERE status = 'active'
AND updated_at < ?
AND confidence > 0.1
`, decayFactor, olderThan)
if err != nil {
return 0, err
}
n, _ := res.RowsAffected()
return int(n), nil
}
func (s *MemoryStore) Prune(ctx context.Context, belowConfidence float64) (int, error) {
res, err := DB.ExecContext(ctx, `
UPDATE memories
SET status = 'archived',
updated_at = datetime('now')
WHERE status = 'active'
AND confidence < ?
`, belowConfidence)
if err != nil {
return 0, err
}
n, _ := res.RowsAffected()
return int(n), nil
}

View File

@@ -64,4 +64,15 @@ type MemoryStore interface {
// UpsertExtractionLog creates or updates the memory extraction log entry.
UpsertExtractionLog(ctx context.Context, channelID, userID, lastMessageID string, count int) error
// ── v0.30.1 — Memory Compaction ──
// DecayConfidence reduces confidence for active memories not updated since olderThan.
// Formula: new_confidence = confidence * decayFactor. Skips memories with confidence <= 0.1.
// Returns the number of affected rows.
DecayConfidence(ctx context.Context, olderThan string, decayFactor float64) (int, error)
// Prune archives active memories whose confidence has dropped below the threshold.
// Returns the number of archived rows.
Prune(ctx context.Context, belowConfidence float64) (int, error)
}