Documentation
¶
Index ¶
- Variables
- type Cache
- func (c *Cache) Clear(ctx context.Context) error
- func (c *Cache) Delete(ctx context.Context, key string) error
- func (c *Cache) Get(ctx context.Context, key string) (interface{}, bool)
- func (c *Cache) Set(ctx context.Context, key string, value interface{}) error
- func (c *Cache) Size() int
- func (c *Cache) Start()
- func (c *Cache) Stop()
- type CacheItem
- type CacheWithTTL
- func (c *CacheWithTTL) Clear(ctx context.Context) error
- func (c *CacheWithTTL) Delete(ctx context.Context, key string) error
- func (c *CacheWithTTL) Get(ctx context.Context, key string) (interface{}, bool)
- func (c *CacheWithTTL) SetWithTTL(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (c *CacheWithTTL) Size() int
- func (c *CacheWithTTL) Start()
- func (c *CacheWithTTL) Stop()
- type Interaction
- type KnowledgeEntry
- type LRUCache
- type LRUItem
- type Message
- type Option
- type Preference
- type RAG
- func (r *RAG) Add(ctx context.Context, entry *KnowledgeEntry) error
- func (r *RAG) Delete(ctx context.Context, id string) error
- func (r *RAG) Get(ctx context.Context, id string) (*KnowledgeEntry, bool)
- func (r *RAG) InitStorage(ctx context.Context) error
- func (r *RAG) IsPersistent() bool
- func (r *RAG) Search(ctx context.Context, query []float64, topK int) ([]*KnowledgeEntry, error)
- func (r *RAG) SearchByText(ctx context.Context, query string, topK int) ([]*KnowledgeEntry, error)
- func (r *RAG) Size() int
- type ResultRecord
- type SessionData
- type SessionMemory
- func (m *SessionMemory) AddMessage(ctx context.Context, sessionID string, msg Message) error
- func (m *SessionMemory) Cleanup(ctx context.Context) int
- func (m *SessionMemory) Clear(ctx context.Context) error
- func (m *SessionMemory) Close(ctx context.Context) error
- func (m *SessionMemory) Delete(ctx context.Context, sessionID string) error
- func (m *SessionMemory) Get(ctx context.Context, sessionID string) (*SessionData, bool)
- func (m *SessionMemory) GetMessages(ctx context.Context, sessionID string) ([]Message, error)
- func (m *SessionMemory) Set(ctx context.Context, sessionID, userID string, messages []Message) error
- func (m *SessionMemory) Size() int
- func (m *SessionMemory) StartCleanup()
- func (m *SessionMemory) StopCleanup()
- type StepRecord
- type StyleEntry
- type TaskData
- type TaskMemory
- func (m *TaskMemory) AddResult(ctx context.Context, taskID string, result ResultRecord) error
- func (m *TaskMemory) AddStep(ctx context.Context, taskID string, step StepRecord) error
- func (m *TaskMemory) Delete(ctx context.Context, taskID string) error
- func (m *TaskMemory) Distill(ctx context.Context, taskID string) (*models.Task, error)
- func (m *TaskMemory) Get(ctx context.Context, taskID string) (*TaskData, bool)
- func (m *TaskMemory) GetContext(ctx context.Context, taskID string, key string) (interface{}, bool)
- func (m *TaskMemory) GetResults(ctx context.Context, taskID string) ([]ResultRecord, error)
- func (m *TaskMemory) GetSteps(ctx context.Context, taskID string) ([]StepRecord, error)
- func (m *TaskMemory) Set(ctx context.Context, taskID, sessionID, userID, input string) error
- func (m *TaskMemory) SetContext(ctx context.Context, taskID string, key string, value interface{}) error
- func (m *TaskMemory) Size() int
- func (m *TaskMemory) Start(ctx context.Context)
- func (m *TaskMemory) Stop()
- func (m *TaskMemory) UpdateOutput(ctx context.Context, taskID, output string) error
- type UserData
- type UserMemory
- func (m *UserMemory) AddInteraction(ctx context.Context, userID string, interaction Interaction) error
- func (m *UserMemory) AddPreference(ctx context.Context, userID string, pref Preference) error
- func (m *UserMemory) Delete(ctx context.Context, userID string) error
- func (m *UserMemory) Get(ctx context.Context, userID string) (*UserData, bool)
- func (m *UserMemory) GetHistory(ctx context.Context, userID string) ([]Interaction, error)
- func (m *UserMemory) GetPreferences(ctx context.Context, userID string) ([]Preference, error)
- func (m *UserMemory) GetStyleEvolution(ctx context.Context, userID string) ([]StyleEntry, error)
- func (m *UserMemory) Set(ctx context.Context, userID string, profile *models.UserProfile) error
- func (m *UserMemory) Size() int
- func (m *UserMemory) UpdateProfile(ctx context.Context, userID string, profile *models.UserProfile) error
- func (m *UserMemory) UpdateStyleEvolution(ctx context.Context, userID string, entry StyleEntry) error
- type VectorIndex
- type VectorSearcher
Constants ¶
This section is empty.
Variables ¶
var ( ErrSessionNotFound = errors.New("session not found") ErrTaskNotFound = errors.New("task not found") )
Memory errors.
var (
ErrUserNotFound = errors.New("user not found")
)
Memory errors.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides in-memory caching capabilities.
func NewCache ¶
NewCache creates a new Cache. The cleanup goroutine is started automatically to prevent memory leaks.
type CacheWithTTL ¶
type CacheWithTTL struct {
// contains filtered or unexported fields
}
CacheWithTTL creates a cache with custom TTL per item.
func NewCacheWithTTL ¶
func NewCacheWithTTL(maxSize int) *CacheWithTTL
NewCacheWithTTL creates a new CacheWithTTL. The cleanup goroutine is started automatically to prevent memory leaks.
func (*CacheWithTTL) Clear ¶
func (c *CacheWithTTL) Clear(ctx context.Context) error
Clear removes all entries.
func (*CacheWithTTL) Delete ¶
func (c *CacheWithTTL) Delete(ctx context.Context, key string) error
Delete removes a cache entry.
func (*CacheWithTTL) Get ¶
func (c *CacheWithTTL) Get(ctx context.Context, key string) (interface{}, bool)
Get retrieves a value from cache.
func (*CacheWithTTL) SetWithTTL ¶
func (c *CacheWithTTL) SetWithTTL(ctx context.Context, key string, value interface{}, ttl time.Duration) error
SetWithTTL stores a value with custom TTL.
func (*CacheWithTTL) Start ¶
func (c *CacheWithTTL) Start()
Start starts the cleanup goroutine. This method is idempotent - calling it multiple times has no additional effect.
func (*CacheWithTTL) Stop ¶
func (c *CacheWithTTL) Stop()
Stop stops the cleanup goroutine. This method is idempotent and safe to call multiple times.
type Interaction ¶
type Interaction struct {
Type string `json:"type"`
SessionID string `json:"session_id"`
Items []string `json:"items"`
Feedback string `json:"feedback"`
Time time.Time `json:"time"`
Metadata map[string]interface{} `json:"metadata"`
}
Interaction represents a user interaction.
type KnowledgeEntry ¶
type KnowledgeEntry struct {
ID string
Content string
Embedding []float64
Metadata map[string]interface{}
}
KnowledgeEntry represents a knowledge base entry.
type LRUCache ¶
type LRUCache struct {
// contains filtered or unexported fields
}
LRU Cache implementation.
type LRUItem ¶
type LRUItem struct {
Key string
Value interface{}
// contains filtered or unexported fields
}
LRUItem represents a cache item with doubly-linked list pointers.
type Message ¶
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
Time time.Time `json:"time"`
}
Message represents a chat message.
type Option ¶
type Option func(*RAG)
Option is a function that configures RAG.
func WithPersistentStorage ¶
func WithPersistentStorage(searcher VectorSearcher, tableName string) Option
WithPersistentStorage enables pgvector storage.
type Preference ¶
type Preference struct {
Category string `json:"category"`
Value string `json:"value"`
Score float64 `json:"score"`
UpdatedAt time.Time `json:"updated_at"`
}
Preference represents a user preference.
type RAG ¶
type RAG struct {
// contains filtered or unexported fields
}
RAG provides retrieval-augmented generation capabilities.
func NewRAGWithOptions ¶
NewRAGWithOptions creates a new RAG instance with options.
func (*RAG) Add ¶
func (r *RAG) Add(ctx context.Context, entry *KnowledgeEntry) error
Add adds a knowledge entry.
func (*RAG) InitStorage ¶
InitStorage initializes the persistent storage table.
func (*RAG) IsPersistent ¶
IsPersistent returns true if using persistent storage.
func (*RAG) SearchByText ¶
SearchByText searches for entries matching text content.
type ResultRecord ¶
type ResultRecord struct {
Type string `json:"type"`
Content string `json:"content"`
Score float64 `json:"score"`
Metadata map[string]interface{} `json:"metadata"`
Timestamp time.Time `json:"timestamp"`
}
ResultRecord represents a task result.
type SessionData ¶
type SessionData struct {
SessionID string
UserID string
Messages []Message
Context map[string]interface{}
AccessedAt time.Time
CreatedAt time.Time
}
SessionData holds session information.
type SessionMemory ¶
type SessionMemory struct {
// contains filtered or unexported fields
}
SessionMemory stores conversation context for a session.
func NewSessionMemory ¶
func NewSessionMemory(maxSize int, ttl time.Duration) *SessionMemory
NewSessionMemory creates a new SessionMemory.
func (*SessionMemory) AddMessage ¶
AddMessage adds a message to the session.
func (*SessionMemory) Cleanup ¶
func (m *SessionMemory) Cleanup(ctx context.Context) int
Cleanup removes all expired sessions and returns the count of removed sessions. Limits cleanup to avoid long lock holding that blocks other operations.
func (*SessionMemory) Clear ¶
func (m *SessionMemory) Clear(ctx context.Context) error
Clear removes all sessions.
func (*SessionMemory) Close ¶
func (m *SessionMemory) Close(ctx context.Context) error
Close stops the background cleanup task and clears all sessions.
func (*SessionMemory) Delete ¶
func (m *SessionMemory) Delete(ctx context.Context, sessionID string) error
Delete removes a session.
func (*SessionMemory) Get ¶
func (m *SessionMemory) Get(ctx context.Context, sessionID string) (*SessionData, bool)
Get retrieves session data and updates access time.
func (*SessionMemory) GetMessages ¶
GetMessages returns session messages.
func (*SessionMemory) Set ¶
func (m *SessionMemory) Set(ctx context.Context, sessionID, userID string, messages []Message) error
Set stores session data.
func (*SessionMemory) Size ¶
func (m *SessionMemory) Size() int
Size returns the number of sessions.
func (*SessionMemory) StartCleanup ¶
func (m *SessionMemory) StartCleanup()
StartCleanup starts the background cleanup task.
func (*SessionMemory) StopCleanup ¶
func (m *SessionMemory) StopCleanup()
StopCleanup stops the background cleanup task.
type StepRecord ¶
type StepRecord struct {
Name string `json:"name"`
Input string `json:"input"`
Output string `json:"output"`
Duration time.Duration `json:"duration"`
Metadata map[string]interface{} `json:"metadata"`
Timestamp time.Time `json:"timestamp"`
}
StepRecord represents a task execution step.
type StyleEntry ¶
type StyleEntry struct {
Style []string `json:"style"`
Occasion string `json:"occasion"`
Confidence float64 `json:"confidence"`
Time time.Time `json:"time"`
}
StyleEntry represents a style preference change over time.
type TaskData ¶
type TaskData struct {
TaskID string
SessionID string
UserID string
Input string
Output string
Context map[string]interface{}
Steps []StepRecord
Results []ResultRecord
CreatedAt time.Time
AccessedAt time.Time
}
TaskData holds task information.
type TaskMemory ¶
type TaskMemory struct {
// contains filtered or unexported fields
}
TaskMemory stores task-specific context and distillation.
func NewTaskMemory ¶
func NewTaskMemory(maxSize int, ttl time.Duration) *TaskMemory
NewTaskMemory creates a new TaskMemory.
func (*TaskMemory) AddResult ¶
func (m *TaskMemory) AddResult(ctx context.Context, taskID string, result ResultRecord) error
AddResult adds a result record.
func (*TaskMemory) AddStep ¶
func (m *TaskMemory) AddStep(ctx context.Context, taskID string, step StepRecord) error
AddStep adds a step record.
func (*TaskMemory) Delete ¶
func (m *TaskMemory) Delete(ctx context.Context, taskID string) error
Delete removes a task.
func (*TaskMemory) GetContext ¶
GetContext returns a context value.
func (*TaskMemory) GetResults ¶
func (m *TaskMemory) GetResults(ctx context.Context, taskID string) ([]ResultRecord, error)
GetResults returns task results.
func (*TaskMemory) GetSteps ¶
func (m *TaskMemory) GetSteps(ctx context.Context, taskID string) ([]StepRecord, error)
GetSteps returns task steps.
func (*TaskMemory) Set ¶
func (m *TaskMemory) Set(ctx context.Context, taskID, sessionID, userID, input string) error
Set stores task data.
func (*TaskMemory) SetContext ¶
func (m *TaskMemory) SetContext(ctx context.Context, taskID string, key string, value interface{}) error
SetContext sets a context value.
func (*TaskMemory) Start ¶
func (m *TaskMemory) Start(ctx context.Context)
Start starts the background cleanup goroutine. This should be called after creating TaskMemory to enable automatic TTL cleanup.
func (*TaskMemory) Stop ¶
func (m *TaskMemory) Stop()
Stop stops the background cleanup goroutine. This should be called during application shutdown.
func (*TaskMemory) UpdateOutput ¶
func (m *TaskMemory) UpdateOutput(ctx context.Context, taskID, output string) error
UpdateOutput updates task output.
type UserData ¶
type UserData struct {
UserID string
Profile *models.UserProfile
Preferences []Preference
History []Interaction
StyleEvolution []StyleEntry
LastUpdated time.Time
CreatedAt time.Time
}
UserData holds user information.
type UserMemory ¶
type UserMemory struct {
// contains filtered or unexported fields
}
UserMemory stores long-term user preferences and history.
func NewUserMemory ¶
func NewUserMemory(maxSize int) *UserMemory
NewUserMemory creates a new UserMemory.
func (*UserMemory) AddInteraction ¶
func (m *UserMemory) AddInteraction(ctx context.Context, userID string, interaction Interaction) error
AddInteraction adds a user interaction.
func (*UserMemory) AddPreference ¶
func (m *UserMemory) AddPreference(ctx context.Context, userID string, pref Preference) error
AddPreference adds a user preference.
func (*UserMemory) Delete ¶
func (m *UserMemory) Delete(ctx context.Context, userID string) error
Delete removes user data.
func (*UserMemory) GetHistory ¶
func (m *UserMemory) GetHistory(ctx context.Context, userID string) ([]Interaction, error)
GetHistory returns user interaction history.
func (*UserMemory) GetPreferences ¶
func (m *UserMemory) GetPreferences(ctx context.Context, userID string) ([]Preference, error)
GetPreferences returns user preferences.
func (*UserMemory) GetStyleEvolution ¶
func (m *UserMemory) GetStyleEvolution(ctx context.Context, userID string) ([]StyleEntry, error)
GetStyleEvolution returns style preference evolution.
func (*UserMemory) Set ¶
func (m *UserMemory) Set(ctx context.Context, userID string, profile *models.UserProfile) error
Set stores user data.
func (*UserMemory) UpdateProfile ¶
func (m *UserMemory) UpdateProfile(ctx context.Context, userID string, profile *models.UserProfile) error
UpdateProfile updates user profile.
func (*UserMemory) UpdateStyleEvolution ¶
func (m *UserMemory) UpdateStyleEvolution(ctx context.Context, userID string, entry StyleEntry) error
UpdateStyleEvolution updates style preference evolution.
type VectorIndex ¶
type VectorIndex struct {
// contains filtered or unexported fields
}
VectorIndex is a simple in-memory vector index.
type VectorSearcher ¶
type VectorSearcher interface {
Search(ctx context.Context, table string, query []float64, limit int) ([]*postgres.SearchResult, error)
AddEmbedding(ctx context.Context, table, id string, embedding []float64, metadata map[string]any) error
DeleteEmbedding(ctx context.Context, table, id string) error
CreateVectorTable(ctx context.Context, table string, metadataSchema string) error
}
VectorSearcher defines the interface for vector storage operations.