Documentation
¶
Index ¶
- Constants
- Variables
- func Migrations() fs.FS
- func ObservationID(sender, text, createdAt, conversationUUID string) string
- type API
- type Consolidation
- type ConsolidationCounts
- type ConsolidationOptions
- type ConsolidationResult
- type Engine
- func (e *Engine) Consolidate(ctx context.Context, userID string, opts ConsolidationOptions) (ConsolidationResult, 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) WriteSignal(ctx context.Context, signal Signal) error
- type Hit
- type Kind
- type Memory
- type Model
- type Observation
- type ObservationInput
- type Op
- type OpKind
- 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 ConsolidationTimeout = 30 * time.Minute ModelTimeout = 2 * time.Minute )
Variables ¶
var ErrConsolidationBusy = errors.New("consolidation already running for user")
var ErrNoObservations = errors.New("no unconsolidated observations")
Functions ¶
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"`
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"`
}
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.
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"`
}
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 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 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. |