Documentation
¶
Overview ¶
Package memory provides persistent conversation storage and fact extraction for AI assistants.
Index ¶
- type ClaudeExtractor
- type Context
- type Conversation
- type ConversationTurn
- type Extractor
- type Fact
- type FactCategory
- type Filter
- type MemoryService
- type RecallOptions
- type Retriever
- type SQLiteStorage
- func (s *SQLiteStorage) Close() error
- func (s *SQLiteStorage) LoadConversations(ctx context.Context, filter Filter) ([]Conversation, error)
- func (s *SQLiteStorage) LoadFacts(ctx context.Context, filter Filter) ([]Fact, error)
- func (s *SQLiteStorage) MarkExtracted(ctx context.Context, convIDs []int64, extractedAt time.Time) error
- func (s *SQLiteStorage) SaveConversation(ctx context.Context, conv Conversation) error
- func (s *SQLiteStorage) SaveFact(ctx context.Context, fact Fact) error
- type Service
- func (s *Service) Close() error
- func (s *Service) ExtractFacts(ctx context.Context) error
- func (s *Service) Recall(ctx context.Context, query string, opts RecallOptions) (Context, error)
- func (s *Service) Remember(ctx context.Context, turn ConversationTurn) error
- func (s *Service) StartBackgroundExtraction(interval time.Duration)
- type SimpleRetriever
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClaudeExtractor ¶
type ClaudeExtractor struct {
// contains filtered or unexported fields
}
ClaudeExtractor implements Extractor using Claude CLI
func NewClaudeExtractor ¶
func NewClaudeExtractor( claudePath string, workingDir string, timeout time.Duration, maxConversations int, ) (*ClaudeExtractor, error)
NewClaudeExtractor creates a new Claude-based extractor
func (*ClaudeExtractor) Extract ¶
func (e *ClaudeExtractor) Extract( ctx context.Context, conversations []Conversation, ) ([]Fact, error)
Extract analyzes conversations and extracts facts
type Context ¶
type Context struct {
Facts []Fact
Conversations []Conversation
}
Context represents memory context to inject into prompts
type Conversation ¶
type Conversation struct {
ID int64
SessionID string
Timestamp time.Time
Query string
Response string
Metadata map[string]string
ExtractedAt *time.Time // Tracks when facts were extracted to prevent duplicates
}
Conversation represents a stored conversation in the database
type ConversationTurn ¶
ConversationTurn represents a single Q&A exchange
type Extractor ¶
type Extractor interface {
Extract(ctx context.Context, conversations []Conversation) ([]Fact, error)
}
Extractor abstracts fact extraction (swappable LLM)
type Fact ¶
type Fact struct {
ID int64
Category FactCategory
Text string
Confidence float64 // 0.0-1.0
SourceIDs []int64 // conversation IDs
CreatedAt time.Time
UpdatedAt time.Time
}
Fact represents an extracted piece of user information
type FactCategory ¶
type FactCategory string
FactCategory classifies different types of extracted facts
const ( CategoryPreference FactCategory = "preference" // coffee, temperature CategoryHAPattern FactCategory = "ha_pattern" // automation behaviors CategoryKnowledge FactCategory = "knowledge" // general facts CategorySchedule FactCategory = "schedule" // time-based )
type Filter ¶
type Filter struct {
SessionID string
Since time.Time
NotExtractedSince time.Time // Load conversations not extracted since this time
Categories []FactCategory
Limit int
}
Filter configures database queries
type MemoryService ¶
type MemoryService interface {
// Remember stores a conversation turn
Remember(ctx context.Context, turn ConversationTurn) error
// Recall retrieves relevant context for a query
Recall(ctx context.Context, query string, opts RecallOptions) (Context, error)
// ExtractFacts extracts facts from recent conversations
ExtractFacts(ctx context.Context) error
// StartBackgroundExtraction starts periodic fact extraction
StartBackgroundExtraction(interval time.Duration)
// Close cleans up resources
Close() error
}
MemoryService is the main interface for memory operations
type RecallOptions ¶
type RecallOptions struct {
IncludeFacts bool
IncludeConversations bool
FactLimit int
ConversationLimit int
}
RecallOptions configures what to retrieve
type Retriever ¶
type Retriever interface {
GetRelevantFacts(ctx context.Context, query string, limit int) ([]Fact, error)
}
Retriever abstracts context assembly
type SQLiteStorage ¶
type SQLiteStorage struct {
// contains filtered or unexported fields
}
SQLiteStorage implements Storage interface using SQLite
func NewSQLiteStorage ¶
func NewSQLiteStorage(dbPath string) (*SQLiteStorage, error)
NewSQLiteStorage creates a new SQLite storage instance
func (*SQLiteStorage) Close ¶
func (s *SQLiteStorage) Close() error
Close closes the database connection
func (*SQLiteStorage) LoadConversations ¶
func (s *SQLiteStorage) LoadConversations( ctx context.Context, filter Filter, ) ([]Conversation, error)
LoadConversations retrieves conversations matching filter
func (*SQLiteStorage) MarkExtracted ¶
func (s *SQLiteStorage) MarkExtracted( ctx context.Context, convIDs []int64, extractedAt time.Time, ) error
MarkExtracted marks conversations as having been processed for fact extraction
func (*SQLiteStorage) SaveConversation ¶
func (s *SQLiteStorage) SaveConversation(ctx context.Context, conv Conversation) error
SaveConversation stores a conversation
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements MemoryService interface
func NewService ¶
NewService creates a new memory service
func (*Service) ExtractFacts ¶
ExtractFacts extracts facts from recent conversations
func (*Service) Remember ¶
func (s *Service) Remember(ctx context.Context, turn ConversationTurn) error
Remember stores a conversation turn
func (*Service) StartBackgroundExtraction ¶
StartBackgroundExtraction starts periodic fact extraction
type SimpleRetriever ¶
type SimpleRetriever struct {
// contains filtered or unexported fields
}
SimpleRetriever implements Retriever using keyword matching
func NewSimpleRetriever ¶
func NewSimpleRetriever(storage Storage) *SimpleRetriever
NewSimpleRetriever creates a new retriever
func (*SimpleRetriever) GetRelevantFacts ¶
func (r *SimpleRetriever) GetRelevantFacts( ctx context.Context, query string, limit int, ) ([]Fact, error)
GetRelevantFacts retrieves facts relevant to the query
type Storage ¶
type Storage interface {
SaveConversation(ctx context.Context, conv Conversation) error
LoadConversations(ctx context.Context, filter Filter) ([]Conversation, error)
MarkExtracted(ctx context.Context, convIDs []int64, extractedAt time.Time) error
SaveFact(ctx context.Context, fact Fact) error
LoadFacts(ctx context.Context, filter Filter) ([]Fact, error)
Close() error
}
Storage abstracts the persistence layer