Documentation
¶
Index ¶
- Variables
- type AppendOpts
- type Engine
- func (e *Engine) Append(ctx context.Context, namespace, threadID, role, content string, ...) (*types.Message, error)
- func (e *Engine) Clear(ctx context.Context, namespace, threadID string) error
- func (e *Engine) GetThread(ctx context.Context, namespace, threadID string) (*types.Thread, error)
- func (e *Engine) History(ctx context.Context, namespace, threadID string, opts *HistoryOpts) (*HistoryResult, error)
- func (e *Engine) ListThreads(ctx context.Context, namespace string, cursor string, limit int) ([]*types.Thread, string, error)
- func (e *Engine) MarkSummarized(ctx context.Context, namespace, threadID string, beforeTime time.Time) error
- func (e *Engine) Search(ctx context.Context, namespace, query string, opts *SearchOpts) (*SearchResult, error)
- func (e *Engine) SetExtractionEnqueuer(eq ExtractionEnqueuer)
- func (e *Engine) SetSummarizer(s Summarizer)
- func (e *Engine) ShouldSummarize(ctx context.Context, namespace, threadID string) (bool, error)
- func (e *Engine) Summarize(ctx context.Context, namespace, threadID string, opts *SummarizeOpts) (*SummarizeResult, error)
- func (e *Engine) UpdateThread(ctx context.Context, thread *types.Thread) error
- type ExtractionEnqueuer
- type HistoryOpts
- type HistoryResult
- type SearchMode
- type SearchOpts
- type SearchResult
- type SummarizeOpts
- type SummarizeResult
- type Summarizer
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyContent = errors.New("message content cannot be empty") ErrInvalidRole = errors.New("invalid message role") ErrThreadNotFound = errors.New("thread not found") ErrNothingToSummarize = errors.New("not enough messages to summarize") ErrSummarizerNotSet = errors.New("summarizer not configured") )
Common errors returned by the conversation engine.
var ValidRoles = map[string]bool{ "user": true, "assistant": true, "system": true, "tool": true, }
ValidRoles defines the allowed message roles.
Functions ¶
This section is empty.
Types ¶
type AppendOpts ¶
type AppendOpts struct {
MaxContentLength int // Truncate content if exceeds this (0 = no truncation)
Metadata map[string]string // Optional metadata
SkipEmbedding bool // Skip embedding generation even if enabled
}
AppendOpts contains options for appending a message.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine implements the conversation memory logic layer. It orchestrates storage and embedding operations for conversation management.
func NewEngine ¶
func NewEngine(store storage.Backend, emb embedding.Provider, cfg *config.ConversationConfig) (*Engine, error)
NewEngine creates a new conversation engine. The embedding provider can be nil if semantic search is disabled. The summarizer can be nil if summarization is not needed.
func (*Engine) Append ¶
func (e *Engine) Append(ctx context.Context, namespace, threadID, role, content string, opts *AppendOpts) (*types.Message, error)
Append adds a message to a conversation thread. Creates the thread if it doesn't exist. Generates embedding if semantic search is enabled.
func (*Engine) History ¶
func (e *Engine) History(ctx context.Context, namespace, threadID string, opts *HistoryOpts) (*HistoryResult, error)
History retrieves conversation history for a thread. Returns messages in chronological order (oldest first). Auto-triggers summarization if message count exceeds threshold.
func (*Engine) ListThreads ¶
func (e *Engine) ListThreads(ctx context.Context, namespace string, cursor string, limit int) ([]*types.Thread, string, error)
ListThreads returns all threads in a namespace.
func (*Engine) MarkSummarized ¶
func (e *Engine) MarkSummarized(ctx context.Context, namespace, threadID string, beforeTime time.Time) error
MarkSummarized marks messages as having been included in a summary. This is used after summarization to track which messages were summarized.
func (*Engine) Search ¶
func (e *Engine) Search(ctx context.Context, namespace, query string, opts *SearchOpts) (*SearchResult, error)
Search performs semantic search across messages in a namespace. Requires semantic search to be enabled and embedding provider configured. Supports vector (default), hybrid, or text search modes.
func (*Engine) SetExtractionEnqueuer ¶
func (e *Engine) SetExtractionEnqueuer(eq ExtractionEnqueuer)
SetExtractionEnqueuer sets the extraction enqueuer for entity extraction. When set, messages will be queued for background entity extraction.
func (*Engine) SetSummarizer ¶
func (e *Engine) SetSummarizer(s Summarizer)
SetSummarizer sets the summarizer for conversation summarization. This is optional and can be called after engine creation.
func (*Engine) ShouldSummarize ¶
ShouldSummarize checks if a thread should be auto-summarized based on message count.
func (*Engine) Summarize ¶
func (e *Engine) Summarize(ctx context.Context, namespace, threadID string, opts *SummarizeOpts) (*SummarizeResult, error)
Summarize compresses older messages into a summary via LLM. The summary is stored in the thread record and older messages are marked as summarized. Recent messages (controlled by KeepRecent) are left unsummarized.
type ExtractionEnqueuer ¶
type ExtractionEnqueuer interface {
EnqueueForExtraction(ctx context.Context, namespace, sourceType, sourceID, content string) error
}
ExtractionEnqueuer queues content for entity extraction.
type HistoryOpts ¶
type HistoryOpts struct {
LastN int // Number of recent messages to retrieve (0 = use default)
IncludeSummary bool // Prepend thread summary if available
Cursor string // Pagination cursor
SkipAutoSummarize bool // Skip auto-summarization check (internal use)
}
HistoryOpts contains options for retrieving conversation history.
type HistoryResult ¶
type HistoryResult struct {
Messages []*types.Message `json:"messages"`
Summary string `json:"summary,omitempty"`
NextCursor string `json:"next_cursor,omitempty"`
ThreadID string `json:"thread_id"`
}
HistoryResult contains the result of a history query.
type SearchMode ¶
type SearchMode string
SearchMode defines the type of search to perform.
const ( SearchModeVector SearchMode = "vector" // Vector similarity search only SearchModeHybrid SearchMode = "hybrid" // Combined vector + full-text search (RRF) SearchModeText SearchMode = "text" // Full-text search only (falls back to vector if unavailable) )
type SearchOpts ¶
type SearchOpts struct {
ThreadID *string // Optional: limit search to specific thread
TopK int // Number of results (0 = default 10)
MinScore float64 // Minimum similarity score (0-1)
SearchMode SearchMode // Search mode: "vector" (default), "hybrid", or "text"
Alpha float64 // Hybrid search weight (0=pure text, 1=pure vector, 0.5=equal)
}
SearchOpts contains options for semantic search.
type SearchResult ¶
type SearchResult struct {
Results []*types.MessageResult `json:"results"`
Query string `json:"query"`
}
SearchResult contains search results.
type SummarizeOpts ¶
type SummarizeOpts struct {
KeepRecent int // Number of recent messages to keep unsummarized (default: 10)
}
SummarizeOpts contains options for summarization.