Documentation
¶
Index ¶
- Constants
- Variables
- func Activation(m Memory, at time.Time, p RetentionPolicy) float64
- func Migrations() fs.FS
- func ObservationID(sender, text, createdAt, conversationUUID string) string
- type API
- type Consolidation
- type ConsolidationCounts
- type ConsolidationOptions
- type ConsolidationResult
- type Embedder
- type Engine
- func (e *Engine) Consolidate(ctx context.Context, userID string, opts ConsolidationOptions) (ConsolidationResult, error)
- func (e *Engine) Evidence(ctx context.Context, user, id string) ([]Observation, error)
- func (e *Engine) Feedback(ctx context.Context, f Feedback) error
- func (e *Engine) Forget(ctx context.Context, user, id string) (ForgetResult, error)
- func (e *Engine) ForgetObservation(ctx context.Context, user, id string) (ForgetResult, error)
- func (e *Engine) Index(ctx context.Context, user string, limit int) (IndexResult, error)
- func (e *Engine) IndexObservations(ctx context.Context, user string, limit int) (IndexResult, error)
- func (e *Engine) Maintain(ctx context.Context, user string, at time.Time, limit int) (MaintenanceResult, error)
- func (e *Engine) Memories(ctx context.Context, userID string) ([]Memory, error)
- func (e *Engine) Observe(ctx context.Context, obs []Observation) (int, error)
- func (e *Engine) Profile(ctx context.Context, userID, tier string) (string, error)
- func (e *Engine) Recall(ctx context.Context, userID, query string, limit int) ([]Hit, error)
- func (e *Engine) RecallObservations(ctx context.Context, user, query string, opts RecallOptions) (ObservationRecallResult, error)
- func (e *Engine) RecallWithOptions(ctx context.Context, user, query string, opts RecallOptions) (RecallResult, error)
- func (e *Engine) SetRetention(ctx context.Context, user, id string, r Retention) error
- func (e *Engine) WriteSignal(ctx context.Context, signal Signal) error
- type Feedback
- type ForgetResult
- type Hit
- type IndexResult
- type Kind
- type MaintenanceResult
- type Memory
- type Model
- type Observation
- type ObservationHit
- type ObservationInput
- type ObservationRecallResult
- type Op
- type OpKind
- type Option
- type RecallOptions
- type RecallResult
- type Retention
- type RetentionPolicy
- type Signal
- type Store
- func (s *Store) ApplyMigrations(ctx context.Context, fsys fs.FS) error
- func (s *Store) Close()
- func (s *Store) Memories(ctx context.Context, userID string) ([]Memory, error)
- func (s *Store) RecallByText(ctx context.Context, userID, query string, limit int) ([]Memory, error)
- func (s *Store) WriteObservations(ctx context.Context, obs []Observation) (int, error)
- func (s *Store) WriteSignal(ctx context.Context, sig Signal) error
Constants ¶
const ( DefaultChunkSize = 200 MaxObservationsPerConsolidation = DefaultChunkSize * 100 MaxContextBytes = 1024 * 1024 MaxSummaryCharacters = 512 ConsolidationTimeout = 30 * time.Minute ModelTimeout = 2 * time.Minute )
const MaxRecallMemories = 10000
const MaxRecallObservations = 20000
Variables ¶
var ErrConsolidationBusy = errors.New("consolidation already running for user")
var ErrMemoryNotFound = errors.New("memory not found for user")
var ErrNoObservations = errors.New("no unconsolidated observations")
var ErrObservationCapacity = errors.New("observation set exceeds exact retrieval capacity")
var ErrRecallCapacity = errors.New("active memory set exceeds exact retrieval capacity; archive memories before recalling")
Functions ¶
func Activation ¶ added in v1.0.1
func Activation(m Memory, at time.Time, p RetentionPolicy) float64
Activation is a deterministic relevance multiplier. Reading never changes it.
func Migrations ¶
Migrations is the embedded SQL migration set rooted at "migrations". Pass directly to (*Store).ApplyMigrations.
func ObservationID ¶
Types ¶
type Consolidation ¶
type Consolidation struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Status string `json:"status"`
ObservationIDs []string `json:"observation_ids"`
Model string `json:"model"`
ResolvedModel string `json:"resolved_model,omitempty"`
PromptVersion string `json:"prompt_version"`
StartedAt time.Time `json:"started_at"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
Counts ConsolidationCounts `json:"counts"`
ErrorMessage string `json:"error_message,omitempty"`
}
Consolidation tracks one saved, bounded chunk of work.
type ConsolidationCounts ¶
type ConsolidationOptions ¶
type ConsolidationResult ¶
type ConsolidationResult struct {
Runs []Consolidation `json:"runs"`
Counts ConsolidationCounts `json:"counts"`
ContextLimited bool `json:"context_limited"`
Index *IndexResult `json:"index,omitempty"`
// UnreferencedObservationIDs lists completed observations that supported no
// operation. These may be irrelevant or ambiguous, not necessarily missed facts.
UnreferencedObservationIDs []string `json:"unreferenced_observation_ids,omitempty"`
FormatRepairs int `json:"format_repairs,omitempty"`
}
type Embedder ¶ added in v1.0.1
Embedder is an optional provider-neutral boundary. Model must identify both weights and preprocessing; changing either requires a new model identifier.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) Consolidate ¶
func (e *Engine) Consolidate(ctx context.Context, userID string, opts ConsolidationOptions) (ConsolidationResult, error)
Consolidate processes the pending snapshot sequentially. Successful chunks remain committed if a later chunk fails; retries select only pending work.
func (*Engine) Evidence ¶ added in v1.0.1
Evidence returns source observations for one memory in the same user scope.
func (*Engine) Feedback ¶ added in v1.0.1
Feedback records an explicit application outcome. A shown/unused result or an unknown outcome changes no utility. An identical event ID is a safe retry.
func (*Engine) Forget ¶ added in v1.0.1
Forget removes a memory, connected versions and memories sharing its evidence. Whole source observations are removed, so a multi-fact source can remove more than one memory. One-way import tombstones prevent exact evidence replay.
func (*Engine) ForgetObservation ¶ added in v1.1.0
ForgetObservation removes original evidence even when consolidation retained no memory for it. Derived memories and exact-content copies are removed too. A missing observation is already forgotten and returns an empty result.
func (*Engine) Index ¶ added in v1.0.1
Index refreshes a bounded batch of missing embeddings. Inference occurs outside transactions. Publication rechecks content and current status, so a concurrent correction or forget cannot publish a stale vector.
func (*Engine) IndexObservations ¶ added in v1.1.0
func (e *Engine) IndexObservations(ctx context.Context, user string, limit int) (IndexResult, error)
IndexObservations is opt-in and separate from Index: enabling memory embeddings does not automatically send raw conversations to an embedding provider.
func (*Engine) Maintain ¶ added in v1.0.1
func (e *Engine) Maintain(ctx context.Context, user string, at time.Time, limit int) (MaintenanceResult, error)
Maintain archives at most limit eligible memories. Expiry takes precedence over pinning. No raw evidence is deleted by relevance-based maintenance.
func (*Engine) RecallObservations ¶ added in v1.1.0
func (e *Engine) RecallObservations(ctx context.Context, user, query string, opts RecallOptions) (ObservationRecallResult, error)
RecallObservations searches original evidence without turning it into a fact. It preserves attribution and does not change Recall's memory-only contract. The host must evaluate speaker, timestamp and uncertainty before using a hit.
func (*Engine) RecallWithOptions ¶ added in v1.0.1
func (e *Engine) RecallWithOptions(ctx context.Context, user, query string, opts RecallOptions) (RecallResult, error)
RecallWithOptions fuses lexical and exact cosine ranks. The bounded exact scan avoids a mandatory vector extension or another database. No writes or automatic feedback occur during recall. Embedding failure is an error; an application may explicitly retry with LexicalOnly.
func (*Engine) SetRetention ¶ added in v1.0.1
type ForgetResult ¶ added in v1.0.1
type IndexResult ¶ added in v1.0.1
type MaintenanceResult ¶ added in v1.0.1
type Memory ¶
type Memory struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Kind Kind `json:"kind"`
Summary string `json:"summary"`
Confidence float64 `json:"confidence"`
ReinforcedCount int `json:"reinforced_count"`
BornAt time.Time `json:"born_at"`
LastSeenAt time.Time `json:"last_seen_at"`
ContradictedBy string `json:"contradicted_by,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Sources []string `json:"sources"`
ArchivedAt *time.Time `json:"archived_at,omitempty"`
Pinned bool `json:"pinned"`
Utility float64 `json:"utility"`
OutcomeCount int `json:"outcome_count"`
}
type Model ¶
type Model interface {
Complete(context.Context, []llm.Message) (llm.Response, error)
Model() string
}
Model is the inference boundary; production uses llm.Client.
type Observation ¶
type Observation struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Source string `json:"source"`
Content string `json:"content"`
Refs map[string]any `json:"refs"`
Salience float64 `json:"salience"`
At time.Time `json:"at"`
IdempotencyKey string `json:"idempotency_key"`
ToolName string `json:"tool_name,omitempty"`
IntentID string `json:"intent_id,omitempty"`
OutcomeClass string `json:"outcome_class,omitempty"`
TurnIndex *int `json:"turn_index,omitempty"`
}
func LoadClaudeExport ¶
func LoadClaudeExport(dir, userID string) ([]Observation, int, error)
LoadClaudeExport reads conversations.json + design_chats/*.json from a Claude.ai export directory and returns them flattened into Observations for the given user. Idempotency keys are deterministic so re-imports insert nothing.
type ObservationHit ¶ added in v1.1.0
type ObservationHit struct {
Observation Observation `json:"observation"`
Score float64 `json:"score"`
}
type ObservationInput ¶
type ObservationInput struct {
Sender string `json:"sender"`
Source string `json:"source"`
Content string `json:"content"`
At time.Time `json:"at"`
ConversationUUID string `json:"conversation_uuid"`
ConversationName string `json:"conversation_name"`
Refs map[string]any `json:"refs"`
ToolName string `json:"tool_name,omitempty"`
IntentID string `json:"intent_id,omitempty"`
OutcomeClass string `json:"outcome_class,omitempty"`
TurnIndex *int `json:"turn_index,omitempty"`
}
ObservationInput is the wire shape for POST /v1/observations. Shared between the API and cortex-import; one source of truth keeps the JSON schema in sync across processes.
func (ObservationInput) ToObservation ¶
func (p ObservationInput) ToObservation(userID string) Observation
ToObservation builds the canonical internal Observation, computing the deterministic ID + idempotency key from (sender, content, at, conversation).
type ObservationRecallResult ¶ added in v1.1.0
type ObservationRecallResult struct {
Hits []ObservationHit `json:"hits"`
Mode string `json:"mode"`
Indexed int `json:"indexed"`
Candidates int `json:"candidates"`
Incomplete bool `json:"incomplete"`
}
type Option ¶ added in v1.0.1
type Option func(*Engine)
func WithEmbedder ¶ added in v1.0.1
func WithRetentionPolicy ¶ added in v1.0.1
func WithRetentionPolicy(policy RetentionPolicy) Option
type RecallOptions ¶ added in v1.0.1
type RecallResult ¶ added in v1.0.1
type RetentionPolicy ¶ added in v1.0.1
type RetentionPolicy struct {
HalfLife time.Duration `json:"half_life"`
ArchiveBelow float64 `json:"archive_below"`
MinAge time.Duration `json:"min_age"`
}
RetentionPolicy controls relevance, not the truth of the underlying evidence. A zero HalfLife disables time decay. Maintenance is always an explicit call.
func DefaultRetentionPolicy ¶ added in v1.0.1
func DefaultRetentionPolicy() RetentionPolicy
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) ApplyMigrations ¶
func (*Store) RecallByText ¶
func (*Store) WriteObservations ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
cortex
command
|
|
|
cortex-import
command
|
|
|
cortex-once
command
|
|
|
Package llm provides a small client for an OpenAI-compatible chat endpoint.
|
Package llm provides a small client for an OpenAI-compatible chat endpoint. |
|
Package prompts embeds the human-reviewable memory consolidation prompts.
|
Package prompts embeds the human-reviewable memory consolidation prompts. |