Documentation
¶
Overview ¶
Package capture provides memory extraction and analysis pipelines.
Index ¶
- func InvalidateContradictions(ctx context.Context, st store.Store, results []ContradictionResult, ...)
- func ShouldCapture(userMsg, assistantMsg string, cfg config.CaptureQualityConfig) bool
- type Capturer
- type ClaudeCapturer
- type ConflictDetector
- type ContradictionConfig
- type ContradictionResult
- type ConversationTurn
- type EntityExtractor
- type MemoryContradictionDetector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InvalidateContradictions ¶ added in v0.8.0
func InvalidateContradictions(ctx context.Context, st store.Store, results []ContradictionResult, logger *slog.Logger)
InvalidateContradictions invalidates each contradicted memory by setting valid_to = now(). This is a convenience helper for callers that have a store but don't want to iterate themselves.
func ShouldCapture ¶ added in v0.4.0
func ShouldCapture(userMsg, assistantMsg string, cfg config.CaptureQualityConfig) bool
ShouldCapture returns true if the conversation turn passes quality filters and is worth sending to Claude for memory extraction. It checks minimum message lengths and blocklist patterns (case-insensitive substring match).
Types ¶
type Capturer ¶
type Capturer interface {
Extract(ctx context.Context, userMsg, assistantMsg string) ([]models.CapturedMemory, error)
// ExtractWithContext is like Extract but includes prior conversation turns
// for better context-aware extraction.
ExtractWithContext(ctx context.Context, userMsg, assistantMsg string, priorTurns []ConversationTurn) ([]models.CapturedMemory, error)
}
Capturer extracts structured memories from conversation text.
type ClaudeCapturer ¶
type ClaudeCapturer struct {
// contains filtered or unexported fields
}
ClaudeCapturer uses Claude Haiku to extract memories.
func NewCapturer ¶
NewCapturer creates a new Claude-based memory capturer.
func (*ClaudeCapturer) Extract ¶
func (c *ClaudeCapturer) Extract(ctx context.Context, userMsg, assistantMsg string) ([]models.CapturedMemory, error)
Extract analyzes a conversation turn and returns captured memories above the confidence threshold.
func (*ClaudeCapturer) ExtractWithContext ¶ added in v0.4.0
func (c *ClaudeCapturer) ExtractWithContext(ctx context.Context, userMsg, assistantMsg string, priorTurns []ConversationTurn) ([]models.CapturedMemory, error)
ExtractWithContext is like Extract but includes prior conversation turns for better extraction.
type ConflictDetector ¶ added in v0.4.0
type ConflictDetector struct {
// contains filtered or unexported fields
}
ConflictDetector uses Claude to detect when a new memory contradicts existing ones. On any API error or JSON parse failure the detector degrades gracefully and returns (false, "", "", nil) so that the caller can always proceed with storing the memory.
func NewConflictDetector ¶ added in v0.4.0
NewConflictDetector creates a ConflictDetector backed by the Anthropic Claude API.
func (*ConflictDetector) Detect ¶ added in v0.4.0
func (d *ConflictDetector) Detect(ctx context.Context, newContent string, candidates []models.Memory) (bool, string, string, error)
Detect returns (true, contradictedID, reason, nil) if newContent contradicts any candidate memory. On any API error or parse failure it logs a warning and returns (false, "", "", nil) — the safe default is to store the memory anyway.
type ContradictionConfig ¶ added in v0.8.0
type ContradictionConfig struct {
// Enabled gates the entire pipeline. Default: true.
Enabled bool `mapstructure:"enabled"`
// SimilarityThreshold is the minimum cosine similarity for a candidate memory
// to be considered in Stage 1. Default: 0.75.
SimilarityThreshold float64 `mapstructure:"similarity_threshold"`
// MaxCandidates caps the Stage 1 candidate pool. Default: 20.
MaxCandidates int `mapstructure:"max_candidates"`
// LLMConfirmThreshold is the cosine similarity above which Stage 3 LLM
// confirmation is skipped and the contradiction is auto-confirmed.
// Default: 0.82.
LLMConfirmThreshold float64 `mapstructure:"llm_confirm_threshold"`
// LLMTimeoutMs is the maximum milliseconds to wait for the Stage 3 LLM call.
// If exceeded the candidate is skipped (safe default). Default: 150.
LLMTimeoutMs int `mapstructure:"llm_timeout_ms"`
}
ContradictionConfig controls the contradiction detection pipeline.
func DefaultContradictionConfig ¶ added in v0.8.0
func DefaultContradictionConfig() ContradictionConfig
DefaultContradictionConfig returns sensible production defaults.
type ContradictionResult ¶ added in v0.8.0
ContradictionResult holds the detection outcome for a single candidate.
func DetectContradictions ¶ added in v0.8.0
func DetectContradictions(ctx context.Context, st store.Store, _ interface{}, newMemory models.Memory, newEmbedding []float32) ([]ContradictionResult, error)
DetectContradictions is a convenience wrapper for simple heuristic-only contradiction detection. It creates a MemoryContradictionDetector with defaults and runs FindContradictions.
type ConversationTurn ¶ added in v0.4.0
type ConversationTurn struct {
Role string `json:"role"` // "user" or "assistant"
Content string `json:"content"`
}
ConversationTurn is a single message in a conversation history.
type EntityExtractor ¶ added in v0.4.0
type EntityExtractor struct {
// contains filtered or unexported fields
}
EntityExtractor identifies named entities in memory content using Claude.
func NewEntityExtractor ¶ added in v0.4.0
NewEntityExtractor creates a new entity extractor backed by the Claude API.
type MemoryContradictionDetector ¶ added in v0.8.0
type MemoryContradictionDetector struct {
// contains filtered or unexported fields
}
MemoryContradictionDetector implements the 3-stage contradiction pipeline described in the design spec (section 4.2, 6.1):
Stage 1 (~10ms) — candidate retrieval via vector search + entity-linked facts Stage 2 (~2ms) — heuristic filter: shared entities + exclusive predicate conflict Stage 3 (~50-150ms, optional) — LLM confirmation for ambiguous cases
All stages degrade gracefully; errors cause candidates to be skipped rather than blocking the store operation.
func NewContradictionDetector ¶ added in v0.8.0
func NewContradictionDetector( st store.Store, graphClient graph.Client, emb embedder.Embedder, llmCli llm.LLMClient, model string, cfg ContradictionConfig, logger *slog.Logger, ) *MemoryContradictionDetector
NewContradictionDetector creates a MemoryContradictionDetector. graphClient and llmClient may be nil; the detector degrades gracefully.
func (*MemoryContradictionDetector) FindContradictions ¶ added in v0.8.0
func (d *MemoryContradictionDetector) FindContradictions( ctx context.Context, newContent string, newEmbedding []float32, ) ([]ContradictionResult, error)
FindContradictions runs the 3-stage pipeline and returns the IDs of memories that the new memory content contradicts. Callers should invalidate those memories.
The function returns (nil, nil) when no contradictions are found, and never returns errors for graceful degradation failures (those are logged as warnings).