learning

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Extractor

type Extractor struct {
}

Extractor extracts learning data from messages

func NewExtractor

func NewExtractor() *Extractor

NewExtractor creates a new extractor

func (*Extractor) ExtractKnowledge

func (e *Extractor) ExtractKnowledge(messages []types.Message) []Knowledge

ExtractKnowledge extracts transferable knowledge from messages

func (*Extractor) ExtractMemories

func (e *Extractor) ExtractMemories(userID string, messages []types.Message) []UserMemory

ExtractMemories extracts memories from messages

type Knowledge

type Knowledge struct {
	ID        string                 `json:"id"`
	Topic     string                 `json:"topic"`
	Content   string                 `json:"content"`
	Source    string                 `json:"source"` // "user", "system", "extracted"
	Relevance float64                `json:"relevance"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt time.Time              `json:"created_at"`
}

Knowledge represents learned knowledge that can be shared across users

type LearningEvent

type LearningEvent struct {
	ID         string                 `json:"id"`
	UserID     string                 `json:"user_id"`
	EventType  string                 `json:"event_type"`
	Data       map[string]interface{} `json:"data"`
	OccurredAt time.Time              `json:"occurred_at"`
}

LearningEvent represents a learning event for auditing

type LearningMachine

type LearningMachine interface {
	// Learn extracts information from messages and stores it
	Learn(ctx context.Context, userID string, messages []types.Message) error

	// GetUserProfile returns the profile for a user
	GetUserProfile(ctx context.Context, userID string) (*UserProfile, error)

	// GetUserMemories returns memories for a user
	GetUserMemories(ctx context.Context, userID string, limit int) ([]UserMemory, error)

	// GetLearnedKnowledge returns learned knowledge on a topic
	GetLearnedKnowledge(ctx context.Context, topic string, limit int) ([]Knowledge, error)

	// DeleteUserData removes all data for a user (GDPR compliance)
	DeleteUserData(ctx context.Context, userID string) error
}

LearningMachine is the interface for the learning system

type Machine

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

Machine is the default implementation of LearningMachine

func NewMachine

func NewMachine(storage Storage) (*Machine, error)

NewMachine creates a new learning machine

func (*Machine) Close

func (m *Machine) Close() error

Close closes the learning machine and its storage

func (*Machine) DeleteUserData

func (m *Machine) DeleteUserData(ctx context.Context, userID string) error

DeleteUserData removes all data for a user (GDPR compliance)

func (*Machine) Disable

func (m *Machine) Disable()

Disable disables the learning system

func (*Machine) Enable

func (m *Machine) Enable()

Enable enables the learning system

func (*Machine) GetLearnedKnowledge

func (m *Machine) GetLearnedKnowledge(ctx context.Context, topic string, limit int) ([]Knowledge, error)

GetLearnedKnowledge returns learned knowledge on a topic

func (*Machine) GetUserMemories

func (m *Machine) GetUserMemories(ctx context.Context, userID string, limit int) ([]UserMemory, error)

GetUserMemories returns memories for a user

func (*Machine) GetUserProfile

func (m *Machine) GetUserProfile(ctx context.Context, userID string) (*UserProfile, error)

GetUserProfile returns the profile for a user

func (*Machine) IsEnabled

func (m *Machine) IsEnabled() bool

IsEnabled returns whether the learning system is enabled

func (*Machine) Learn

func (m *Machine) Learn(ctx context.Context, userID string, messages []types.Message) error

Learn extracts information from messages and stores it

type MemoryType

type MemoryType string

MemoryType represents the type of memory

const (
	MemoryTypeFact       MemoryType = "fact"
	MemoryTypePreference MemoryType = "preference"
	MemoryTypeContext    MemoryType = "context"
	MemoryTypeSkill      MemoryType = "skill"
)

type Storage

type Storage interface {
	// User Profiles
	SaveUserProfile(ctx context.Context, profile *UserProfile) error
	GetUserProfile(ctx context.Context, userID string) (*UserProfile, error)

	// User Memories
	SaveUserMemory(ctx context.Context, memory *UserMemory) error
	GetUserMemories(ctx context.Context, userID string, limit int) ([]UserMemory, error)
	DeleteUserMemories(ctx context.Context, userID string) error

	// Learned Knowledge
	SaveKnowledge(ctx context.Context, knowledge *Knowledge) error
	GetKnowledge(ctx context.Context, topic string, limit int) ([]Knowledge, error)
	SearchKnowledge(ctx context.Context, query string, limit int) ([]Knowledge, error)

	// Learning Events
	SaveLearningEvent(ctx context.Context, event *LearningEvent) error
	GetLearningEvents(ctx context.Context, userID string, limit int) ([]LearningEvent, error)

	// Cleanup
	DeleteUserData(ctx context.Context, userID string) error

	// Close closes the storage connection
	Close() error
}

Storage is the interface for learning data persistence

type UserMemory

type UserMemory struct {
	ID        string                 `json:"id"`
	UserID    string                 `json:"user_id"`
	Content   string                 `json:"content"`
	Type      MemoryType             `json:"type"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
	CreatedAt time.Time              `json:"created_at"`
}

UserMemory represents a memory associated with a user

type UserProfile

type UserProfile struct {
	UserID      string                 `json:"user_id"`
	Name        string                 `json:"name,omitempty"`
	Preferences map[string]interface{} `json:"preferences,omitempty"`
	Context     map[string]interface{} `json:"context,omitempty"`
	CreatedAt   time.Time              `json:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at"`
}

UserProfile represents a user's profile

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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