Documentation
¶
Index ¶
- Constants
- func GetDBPath() (string, error)
- func GetDataDir() (string, error)
- func ResolveDBPath(pathOverride string) (string, error)
- type Config
- type Fragment
- type ImageListOptions
- type ImageRecord
- type ListOptions
- type MiningState
- type ScoredFragment
- type SearchResult
- type Store
- func (s *Store) BumpAccess(ctx context.Context, fragmentID string) error
- func (s *Store) Close() error
- func (s *Store) CountGCCandidates(ctx context.Context, agent string) (int, error)
- func (s *Store) CreateFragment(ctx context.Context, f *Fragment) error
- func (s *Store) DeleteFragment(ctx context.Context, agent, path string) (deleted bool, err error)
- func (s *Store) FindFragmentsByPath(ctx context.Context, path string) ([]Fragment, error)
- func (s *Store) FragmentCountsByAgent(ctx context.Context) (map[string]int, error)
- func (s *Store) GCFragments(ctx context.Context, agent string) (int, error)
- func (s *Store) GetEmbedding(ctx context.Context, fragmentID, provider, model string) ([]float64, error)
- func (s *Store) GetEmbeddingsByIDs(ctx context.Context, fragmentIDs []string, provider, model string) (map[string][]float64, error)
- func (s *Store) GetFragment(ctx context.Context, agent, path string) (*Fragment, error)
- func (s *Store) GetFragmentsNeedingEmbedding(ctx context.Context, agent, provider, model string) ([]Fragment, error)
- func (s *Store) GetMeta(ctx context.Context, key string) (string, error)
- func (s *Store) GetState(ctx context.Context, sessionID string) (*MiningState, error)
- func (s *Store) LastMinedByAgent(ctx context.Context) (map[string]time.Time, error)
- func (s *Store) ListAgents(ctx context.Context) ([]string, error)
- func (s *Store) ListFragments(ctx context.Context, opts ListOptions) ([]Fragment, error)
- func (s *Store) ListImageAgents(ctx context.Context) ([]string, error)
- func (s *Store) ListImages(ctx context.Context, opts ImageListOptions) ([]ImageRecord, error)
- func (s *Store) ListImagesSince(ctx context.Context, agent string, since time.Time) ([]ImageRecord, error)
- func (s *Store) RecalcDecayScores(ctx context.Context, agent string, halfLifeDays float64) (int, error)
- func (s *Store) RecordImage(ctx context.Context, r *ImageRecord) error
- func (s *Store) SearchBM25(ctx context.Context, query string, limit int, agent string) ([]ScoredFragment, error)
- func (s *Store) SearchFragments(ctx context.Context, query string, limit int, agent string) ([]SearchResult, error)
- func (s *Store) SearchImages(ctx context.Context, query, agent string, limit int) ([]ImageRecord, error)
- func (s *Store) SetMeta(ctx context.Context, key, value string) error
- func (s *Store) UpdateFragment(ctx context.Context, agent, path, content string) (updated bool, err error)
- func (s *Store) UpsertEmbedding(ctx context.Context, fragmentID, provider, model string, dims int, ...) error
- func (s *Store) UpsertState(ctx context.Context, st *MiningState) error
- func (s *Store) VectorSearch(ctx context.Context, agent, provider, model string, queryVec []float64, ...) ([]ScoredFragment, error)
Constants ¶
const (
DefaultSourceMine = "mine"
)
Variables ¶
This section is empty.
Functions ¶
func GetDataDir ¶
GetDataDir returns the XDG data directory for term-llm.
func ResolveDBPath ¶
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 ImageListOptions ¶ added in v0.0.94
ImageListOptions controls listing of generated images.
type ImageRecord ¶ added in v0.0.94
type ImageRecord struct {
ID string `json:"id"`
Agent string `json:"agent"`
SessionID string `json:"session_id"`
Prompt string `json:"prompt"`
OutputPath string `json:"output_path"`
MimeType string `json:"mime_type"`
Provider string `json:"provider"`
Width int `json:"width"`
Height int `json:"height"`
FileSize int `json:"file_size"`
CreatedAt time.Time `json:"created_at"`
}
ImageRecord is a record of a generated image.
type ListOptions ¶
ListOptions configures fragment listing.
type MiningState ¶
MiningState tracks per-session mining progress.
type ScoredFragment ¶ added in v0.0.94
type ScoredFragment struct {
ID string `json:"id"`
Agent string `json:"agent"`
Path string `json:"path"`
Content string `json:"-"`
Source string `json:"-"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
AccessedAt *time.Time
AccessCount int `json:"-"`
DecayScore float64 `json:"-"`
Pinned bool `json:"-"`
Snippet string `json:"snippet"`
Score float64 `json:"score"`
Vector []float64 `json:"-"`
}
ScoredFragment is a fragment paired with a relevance score.
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 (*Store) BumpAccess ¶ added in v0.0.94
BumpAccess marks a fragment as recently accessed, increments access_count, and gives decay_score a small recency boost.
func (*Store) CountGCCandidates ¶ added in v0.0.94
CountGCCandidates counts fragments eligible for GC.
func (*Store) CreateFragment ¶
CreateFragment inserts a new fragment and syncs FTS explicitly.
func (*Store) DeleteFragment ¶
DeleteFragment removes a fragment and syncs FTS. Returns deleted=false when no matching fragment exists.
func (*Store) FindFragmentsByPath ¶
FindFragmentsByPath fetches fragments for a path across all agents.
func (*Store) FragmentCountsByAgent ¶
FragmentCountsByAgent returns count(fragment) grouped by agent.
func (*Store) GCFragments ¶ added in v0.0.94
GCFragments deletes decayed, non-pinned fragments and keeps FTS in sync.
func (*Store) GetEmbedding ¶ added in v0.0.94
func (s *Store) GetEmbedding(ctx context.Context, fragmentID, provider, model string) ([]float64, error)
GetEmbedding fetches a stored embedding vector for a fragment+provider+model.
func (*Store) GetEmbeddingsByIDs ¶ added in v0.0.94
func (*Store) GetFragment ¶
GetFragment fetches a fragment by (agent,path).
func (*Store) GetFragmentsNeedingEmbedding ¶ added in v0.0.94
func (s *Store) GetFragmentsNeedingEmbedding(ctx context.Context, agent, provider, model string) ([]Fragment, error)
GetFragmentsNeedingEmbedding returns fragments missing an embedding row for provider+model.
func (*Store) GetMeta ¶ added in v0.0.94
GetMeta returns a value from memory_meta. Missing keys return "", nil.
func (*Store) LastMinedByAgent ¶
LastMinedByAgent returns MAX(mined_at) grouped by agent.
SQLite aggregate functions like MAX() return the underlying value as a plain string, bypassing the driver's column-type inference that makes direct column scans into time.Time work. We therefore scan as a string and parse manually, accepting both RFC3339 (current format written by UpsertState) and the legacy Go time.String() format that older rows may contain.
func (*Store) ListAgents ¶ added in v0.0.94
ListAgents returns distinct agent names that have stored fragments.
func (*Store) ListFragments ¶
ListFragments returns fragments sorted by updated_at descending.
func (*Store) ListImageAgents ¶ added in v0.0.94
ListImageAgents returns distinct agent names for generated images.
func (*Store) ListImages ¶ added in v0.0.94
func (s *Store) ListImages(ctx context.Context, opts ImageListOptions) ([]ImageRecord, error)
ListImages returns generated images ordered by creation time (newest first).
func (*Store) ListImagesSince ¶ added in v0.0.94
func (s *Store) ListImagesSince(ctx context.Context, agent string, since time.Time) ([]ImageRecord, error)
ListImagesSince returns generated images for an agent created after the given time.
func (*Store) RecalcDecayScores ¶ added in v0.0.94
func (s *Store) RecalcDecayScores(ctx context.Context, agent string, halfLifeDays float64) (int, error)
RecalcDecayScores recalculates decay_score for non-pinned fragments. halfLifeDays defaults to 30 when <= 0.
func (*Store) RecordImage ¶ added in v0.0.94
func (s *Store) RecordImage(ctx context.Context, r *ImageRecord) error
RecordImage inserts a generated image record into the store. Non-fatal in callers: errors do not stop image generation.
func (*Store) SearchBM25 ¶ added in v0.0.94
func (s *Store) SearchBM25(ctx context.Context, query string, limit int, agent string) ([]ScoredFragment, error)
SearchBM25 performs BM25 search over FTS5 and returns fragment details.
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) SearchImages ¶ added in v0.0.94
func (s *Store) SearchImages(ctx context.Context, query, agent string, limit int) ([]ImageRecord, error)
SearchImages searches generated images by prompt/path using 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) UpsertEmbedding ¶ added in v0.0.94
func (s *Store) UpsertEmbedding(ctx context.Context, fragmentID, provider, model string, dims int, vec []float64) error
UpsertEmbedding inserts or updates an embedding vector for a fragment.
func (*Store) UpsertState ¶
func (s *Store) UpsertState(ctx context.Context, st *MiningState) error
UpsertState inserts or updates mining state.
func (*Store) VectorSearch ¶ added in v0.0.94
func (s *Store) VectorSearch(ctx context.Context, agent, provider, model string, queryVec []float64, limit int) ([]ScoredFragment, error)
VectorSearch performs a full cosine similarity scan over embeddings.