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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user