decay

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package decay implements salience decay, reinforcement, and scheduling as specified in RFC 15A.7.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exponential

func Exponential(currentSalience, elapsedSeconds float64, profile schema.DecayProfile) float64

Exponential computes exponential decay: salience * 2^(-elapsed/halfLife), floored at MinSalience. RFC 15A.7: Exponential decay with half-life parameter.

Types

type DecayFunc

type DecayFunc func(currentSalience float64, elapsedSeconds float64, profile schema.DecayProfile) float64

DecayFunc takes current salience, elapsed seconds since last reinforcement, and the decay profile, returns new salience.

func GetDecayFunc

func GetDecayFunc(curve schema.DecayCurve) DecayFunc

GetDecayFunc returns the decay function used by the implementation. Membrane currently supports exponential decay only.

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

Scheduler runs periodic decay sweeps across all records.

func NewScheduler

func NewScheduler(service *Service, interval time.Duration) *Scheduler

NewScheduler creates a new decay scheduler that runs ApplyDecayAll at the given interval.

func (*Scheduler) Start

func (s *Scheduler) Start(ctx context.Context)

Start begins the periodic decay loop in a goroutine. It runs until the context is cancelled or Stop is called.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop gracefully shuts down the scheduler and waits for the goroutine to finish. Safe to call even if Start was never called.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service applies decay and reinforcement to memory records.

func NewService

func NewService(store storage.Store) *Service

NewService creates a new decay service backed by the given store.

func (*Service) ApplyDecay

func (s *Service) ApplyDecay(ctx context.Context, id string) error

ApplyDecay calculates and applies decay to a single record's salience based on elapsed time since LastReinforcedAt.

func (*Service) ApplyDecayAll

func (s *Service) ApplyDecayAll(ctx context.Context) (int, error)

ApplyDecayAll applies decay to all non-pinned records and returns the count of records processed.

func (*Service) Penalize

func (s *Service) Penalize(ctx context.Context, id string, amount float64, actor string, rationale string) error

Penalize reduces a record's salience by the given amount, floored at MinSalience, and adds an audit entry.

func (*Service) Prune

func (s *Service) Prune(ctx context.Context) (int, error)

Prune deletes records whose salience has dropped to their floor and whose deletion policy is auto_prune. Pinned records are never pruned.

func (*Service) Reinforce

func (s *Service) Reinforce(ctx context.Context, id string, actor string, rationale string) error

Reinforce boosts a record's salience by its ReinforcementGain, updates LastReinforcedAt, and adds an audit entry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL