memory

package
v0.0.93 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSourceMine = "mine"
)

Variables

This section is empty.

Functions

func GetDBPath

func GetDBPath() (string, error)

GetDBPath returns the default memory.db path.

func GetDataDir

func GetDataDir() (string, error)

GetDataDir returns the XDG data directory for term-llm.

func ResolveDBPath

func ResolveDBPath(pathOverride string) (string, error)

ResolveDBPath resolves an optional DB path override.

Types

type Config

type Config struct {
	Path string // Optional DB path override (supports :memory:)
}

Config controls memory store initialization.

type Fragment

type Fragment struct {
	ID          string
	Agent       string
	Path        string
	Content     string
	Source      string
	CreatedAt   time.Time
	UpdatedAt   time.Time
	AccessedAt  *time.Time
	AccessCount int
	DecayScore  float64
	Pinned      bool
}

Fragment is a durable memory item extracted from sessions.

type ListOptions

type ListOptions struct {
	Agent string
	Since *time.Time
	Limit int
}

ListOptions configures fragment listing.

type MiningState

type MiningState struct {
	SessionID       string
	Agent           string
	LastMinedOffset int
	MinedAt         time.Time
}

MiningState tracks per-session mining progress.

type SearchResult

type SearchResult struct {
	Agent   string  `json:"agent"`
	Path    string  `json:"path"`
	Snippet string  `json:"snippet"`
	Score   float64 `json:"score"`
}

SearchResult is a BM25 result from FTS.

type Store

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

Store persists memory fragments and mining state.

func NewStore

func NewStore(cfg Config) (*Store, error)

NewStore opens memory.db and initializes schema.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying DB.

func (*Store) CreateFragment

func (s *Store) CreateFragment(ctx context.Context, f *Fragment) error

CreateFragment inserts a new fragment and syncs FTS explicitly.

func (*Store) DeleteFragment

func (s *Store) DeleteFragment(ctx context.Context, agent, path string) (deleted bool, err error)

DeleteFragment removes a fragment and syncs FTS. Returns deleted=false when no matching fragment exists.

func (*Store) FindFragmentsByPath

func (s *Store) FindFragmentsByPath(ctx context.Context, path string) ([]Fragment, error)

FindFragmentsByPath fetches fragments for a path across all agents.

func (*Store) FragmentCountsByAgent

func (s *Store) FragmentCountsByAgent(ctx context.Context) (map[string]int, error)

FragmentCountsByAgent returns count(fragment) grouped by agent.

func (*Store) GetFragment

func (s *Store) GetFragment(ctx context.Context, agent, path string) (*Fragment, error)

GetFragment fetches a fragment by (agent,path).

func (*Store) GetState

func (s *Store) GetState(ctx context.Context, sessionID string) (*MiningState, error)

GetState returns mining state for a session.

func (*Store) LastMinedByAgent

func (s *Store) LastMinedByAgent(ctx context.Context) (map[string]time.Time, error)

LastMinedByAgent returns MAX(mined_at) grouped by agent.

func (*Store) ListFragments

func (s *Store) ListFragments(ctx context.Context, opts ListOptions) ([]Fragment, error)

ListFragments returns fragments sorted by updated_at descending.

func (*Store) SearchFragments

func (s *Store) SearchFragments(ctx context.Context, query string, limit int, agent string) ([]SearchResult, error)

SearchFragments performs BM25 search over FTS5.

func (*Store) UpdateFragment

func (s *Store) UpdateFragment(ctx context.Context, agent, path, content string) (updated bool, err error)

UpdateFragment updates content for an existing (agent,path) fragment and syncs FTS. Returns updated=false when no matching fragment exists.

func (*Store) UpsertState

func (s *Store) UpsertState(ctx context.Context, st *MiningState) error

UpsertState inserts or updates mining state.

Jump to

Keyboard shortcuts

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