memory

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func ContentHash

func ContentHash(content string) string

Types

type Manager

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

func NewManager

func NewManager(s VectorStore, e embedding.Provider) *Manager

func (*Manager) Add

func (m *Manager) Add(ctx context.Context, content string, memType MemoryType, filter *SearchFilter, metadata map[string]any) (*Memory, error)

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, id string) error

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, id string) (*Memory, error)

func (*Manager) List

func (m *Manager) List(ctx context.Context, filter *SearchFilter, limit, offset int) ([]*Memory, int, error)

func (*Manager) Search

func (m *Manager) Search(ctx context.Context, query string, k int, filter *SearchFilter) ([]SearchResult, error)

func (*Manager) Stats

func (m *Manager) Stats(ctx context.Context, filter *SearchFilter) (*Stats, error)

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, id string, content *string, metadata map[string]any) (*Memory, error)

type Memory

type Memory struct {
	ID          string         `json:"id"`
	Content     string         `json:"content"`
	MemoryType  MemoryType     `json:"memory_type"`
	UserID      string         `json:"user_id,omitempty"`
	AgentID     string         `json:"agent_id,omitempty"`
	AppID       string         `json:"app_id,omitempty"`
	RunID       string         `json:"run_id,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
	ContentHash string         `json:"content_hash"`
	Embedding   []float32      `json:"-"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
}

type MemoryType

type MemoryType string
const (
	TypeFact         MemoryType = "fact"
	TypeConversation MemoryType = "conversation"
	TypeDecision     MemoryType = "decision"
	TypeCodePattern  MemoryType = "code_pattern"
	TypeCorrection   MemoryType = "correction"
)

func (MemoryType) Valid

func (mt MemoryType) Valid() bool

type SearchFilter

type SearchFilter struct {
	UserID     string     `json:"user_id,omitempty"`
	AgentID    string     `json:"agent_id,omitempty"`
	AppID      string     `json:"app_id,omitempty"`
	RunID      string     `json:"run_id,omitempty"`
	MemoryType MemoryType `json:"memory_type,omitempty"`
	Since      *time.Time `json:"since,omitempty"`
	Until      *time.Time `json:"until,omitempty"`
}

type SearchResult

type SearchResult struct {
	Memory   Memory  `json:"memory"`
	Score    float64 `json:"score"`
	Distance float64 `json:"distance"`
}

type Stats

type Stats struct {
	Total    int            `json:"total"`
	ByType   map[string]int `json:"by_type"`
	ByUser   map[string]int `json:"by_user,omitempty"`
	OldestAt *time.Time     `json:"oldest_at,omitempty"`
	NewestAt *time.Time     `json:"newest_at,omitempty"`
}

type VectorStore

type VectorStore interface {
	Insert(ctx context.Context, mem *Memory) error
	Update(ctx context.Context, mem *Memory) error
	Delete(ctx context.Context, id string) error
	Get(ctx context.Context, id string) (*Memory, error)
	GetByHash(ctx context.Context, contentHash string, filter *SearchFilter) (*Memory, error)
	Search(ctx context.Context, vector []float32, k int, filter *SearchFilter) ([]SearchResult, error)
	List(ctx context.Context, filter *SearchFilter, limit, offset int) ([]*Memory, int, error)
	Stats(ctx context.Context, filter *SearchFilter) (*Stats, error)
	Close() error
}

VectorStore is the storage interface for memories. Implementations live in internal/store.

Jump to

Keyboard shortcuts

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