memory

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("memory: not found")

Functions

func EncodeRecord added in v0.1.5

func EncodeRecord(record CognitiveRecord) (json.RawMessage, error)

EncodeRecord serializes a cognitive record for repository storage.

Types

type CognitiveMemory added in v0.1.5

type CognitiveMemory interface {
	Remember(ctx context.Context, ns Namespace, record CognitiveRecord) error
	Recall(ctx context.Context, ns Namespace, query string, limit int) ([]CognitiveRecord, error)
}

CognitiveMemory stores and recalls scored memories for agents.

type CognitiveRecord added in v0.1.5

type CognitiveRecord struct {
	ID         string            `json:"id"`
	Content    string            `json:"content"`
	Scope      string            `json:"scope"`
	Categories []string          `json:"categories,omitempty"`
	Importance float64           `json:"importance"`
	CreatedAt  time.Time         `json:"created_at"`
	Metadata   map[string]string `json:"metadata,omitempty"`
}

CognitiveRecord is a scored long-term memory entry.

func DecodeRecord added in v0.1.5

func DecodeRecord(raw json.RawMessage) (CognitiveRecord, error)

DecodeRecord deserializes a cognitive record from repository storage.

type Entry

type Entry struct {
	Key   string          `json:"key"`
	Value json.RawMessage `json:"value"`
}

type Namespace

type Namespace struct {
	RunID     string `json:"run_id,omitempty"`
	SessionID string `json:"session_id,omitempty"`
	Agent     string `json:"agent,omitempty"`
	Scope     Scope  `json:"scope"`
}

func (Namespace) KeyPrefix

func (n Namespace) KeyPrefix() string

type RecallScore added in v0.1.5

type RecallScore struct {
	Record CognitiveRecord
	Score  float64
}

RecallScore ranks a memory for composite recall scoring.

func RankMemories added in v0.1.5

func RankMemories(query string, records []CognitiveRecord, now time.Time, semanticWeight, recencyWeight, importanceWeight float64) []RecallScore

RankMemories applies semantic overlap, recency, and importance weighting.

type Repository

type Repository interface {
	Get(ctx context.Context, ns Namespace, key string) (json.RawMessage, error)
	Set(ctx context.Context, ns Namespace, key string, value json.RawMessage) error
	Append(ctx context.Context, ns Namespace, key string, value json.RawMessage) error
	Delete(ctx context.Context, ns Namespace, key string) error
	// List returns all entries whose keys begin with prefix within the
	// namespace. An empty prefix matches all keys in the namespace.
	List(ctx context.Context, ns Namespace, prefix string) ([]Entry, error)
}

type Scope

type Scope string
const (
	ScopeConversation Scope = "conversation"
	ScopeSession      Scope = "session"
	ScopeLongTerm     Scope = "long_term"
	ScopeAudit        Scope = "audit"
)

Jump to

Keyboard shortcuts

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