memory

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package memory provides core memory service layer.

Implements business logic for memory operations including validation, UUID generation, session detection, and domain auto-creation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAgentContext

func GetAgentContext() string

GetAgentContext returns context information about the current agent

func GetAgentType

func GetAgentType() string

GetAgentType returns the agent type based on invocation context VERIFIED: 4 valid agent types from local-memory

Types

type Chunk

type Chunk struct {
	Content  string
	Index    int
	Level    int // 1 = paragraph level
	StartPos int // Position in original content
	EndPos   int
}

Chunk represents a piece of a larger memory

type ChunkConfig

type ChunkConfig struct {
	// MaxChunkSize is the maximum number of characters per chunk (not tokens, for simplicity)
	// Default: 1000 characters (~200-250 tokens)
	MaxChunkSize int

	// OverlapSize is the number of characters to overlap between chunks
	// Default: 100 characters
	OverlapSize int

	// MinChunkSize is the minimum size to consider creating chunks
	// If content is smaller than this, don't chunk at all
	// Default: 1500 characters
	MinChunkSize int
}

ChunkConfig contains configuration for memory chunking

func DefaultChunkConfig

func DefaultChunkConfig() *ChunkConfig

DefaultChunkConfig returns the default chunking configuration

type Chunker

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

Chunker handles splitting content into hierarchical chunks

func NewChunker

func NewChunker(config *ChunkConfig) *Chunker

NewChunker creates a new Chunker with the given configuration

func (*Chunker) ChunkContent

func (c *Chunker) ChunkContent(content string) []Chunk

ChunkContent splits content into chunks with overlap Returns nil if content doesn't need chunking

func (*Chunker) ShouldChunk

func (c *Chunker) ShouldChunk(content string) bool

ShouldChunk determines if content should be chunked based on size

type GetOptions

type GetOptions struct {
	ID   string
	Slug string
}

GetOptions contains options for retrieving a memory

type ListOptions

type ListOptions struct {
	SessionID         string
	Domain            string
	Tags              []string
	MinImportance     int
	MaxImportance     int
	StartDate         *time.Time
	EndDate           *time.Time
	Limit             int
	Offset            int
	SessionFilterMode string // "all", "session_only", "session_and_shared"
}

ListOptions contains options for listing memories

type Service

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

Service provides the business logic layer for memory operations VERIFIED: Implements all local-memory memory operations

func NewService

func NewService(db *database.Database, cfg *config.Config) *Service

NewService creates a new memory service

func (*Service) Delete

func (s *Service) Delete(id string) error

Delete removes a memory by ID VERIFIED: Matches local-memory delete_memory behavior (CASCADE deletes relationships)

func (*Service) Get

func (s *Service) Get(opts *GetOptions) (*database.Memory, error)

Get retrieves a memory by ID or slug VERIFIED: Matches local-memory get_memory_by_id behavior

func (*Service) GetSessionID

func (s *Service) GetSessionID() string

GetSessionID returns the current session ID

func (*Service) GetStats

func (s *Service) GetStats() (*Stats, error)

GetStats returns memory statistics

func (*Service) List

func (s *Service) List(opts *ListOptions) ([]*database.Memory, error)

List retrieves memories with optional filters VERIFIED: Matches local-memory list behavior with session filtering

func (*Service) Store

func (s *Service) Store(opts *StoreOptions) (*StoreResult, error)

Store creates a new memory with validation and enrichment VERIFIED: Matches local-memory store_memory behavior Enhanced with hierarchical chunking for better retrieval (Phase 1 benchmark improvement)

func (*Service) Update

func (s *Service) Update(opts *UpdateOptions) (*database.Memory, error)

Update modifies an existing memory VERIFIED: Matches local-memory update_memory behavior

type SessionDetector

type SessionDetector struct {
	Strategy SessionStrategy
	ManualID string
	Prefix   string // Default: "daemon-"
	// contains filtered or unexported fields
}

SessionDetector handles session ID detection based on strategy

func NewSessionDetector

func NewSessionDetector(strategy SessionStrategy) *SessionDetector

NewSessionDetector creates a new session detector

func (*SessionDetector) DetectSessionID

func (d *SessionDetector) DetectSessionID() string

DetectSessionID returns the session ID based on the configured strategy VERIFIED: Matches local-memory session detection behavior

type SessionStrategy

type SessionStrategy string

SessionStrategy defines how session IDs are detected

const (
	// SessionStrategyGitDirectory uses the git repository root directory name
	// VERIFIED: Local Memory uses "daemon-{directory_name}" format
	SessionStrategyGitDirectory SessionStrategy = "git-directory"

	// SessionStrategyManual requires explicit session ID
	SessionStrategyManual SessionStrategy = "manual"

	// SessionStrategyHash uses a hash of the git remote URL
	SessionStrategyHash SessionStrategy = "hash"
)

type Stats

type Stats struct {
	TotalMemories   int
	TotalSessions   int
	TotalDomains    int
	TotalCategories int
	SessionID       string
}

Stats returns memory statistics

type StoreOptions

type StoreOptions struct {
	Content      string
	Importance   int
	Tags         []string
	Domain       string
	Source       string
	SessionID    string // Optional override
	AgentType    string // Optional override
	AgentContext string // Optional override
	AccessScope  string // "session", "shared", "global"
	Slug         string
}

StoreOptions contains options for storing a memory

type StoreResult

type StoreResult struct {
	Memory    *database.Memory
	IsNew     bool
	SessionID string
}

StoreResult contains the result of storing a memory

type UpdateOptions

type UpdateOptions struct {
	ID         string
	Content    *string
	Importance *int
	Tags       []string
	Source     *string
	Domain     *string
}

UpdateOptions contains options for updating a memory

Jump to

Keyboard shortcuts

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