engine

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDecayConfig = DecayConfig{
	HalfLifeDays:  30,
	MinConfidence: 0.1,
	BoostOnAccess: 0.2,
}

Functions

func BoostNode

func BoostNode(store *storage.Store, id string, boost float64) error

BoostNode increases confidence of a node on access (capped at 1.0).

func FormatContext

func FormatContext(nodes []*storage.Node) string

FormatContext formats nodes as a markdown context block for injection.

func GarbageCollect

func GarbageCollect(store *storage.Store, cfg DecayConfig) (int, error)

GarbageCollect removes nodes below min_confidence (except anchors: file/entity).

func RunDecay

func RunDecay(store *storage.Store, cfg DecayConfig) error

RunDecay applies half-life decay to all nodes in the store. Orphan nodes (0 edges) and superseded nodes decay 2× faster.

func TrimToTokenBudget

func TrimToTokenBudget(nodes []*storage.Node, budget int) []*storage.Node

TrimToTokenBudget trims a node list to fit within a token budget. Approximation: 1 token ≈ 4 characters.

Types

type DecayConfig

type DecayConfig struct {
	HalfLifeDays  float64 // default 30
	MinConfidence float64 // default 0.1 — below this, eligible for GC
	BoostOnAccess float64 // default 0.2
}

DecayConfig controls decay behaviour.

type EdgeInput

type EdgeInput struct {
	ToID string
	Type string
}

EdgeInput describes an edge to create alongside a node.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is the core memory engine wrapping graph + storage.

func New

func New(store *storage.Store) *Engine

New creates a memory engine.

func (*Engine) Compact

func (e *Engine) Compact(project string) (int, error)

Compact merges low-confidence memories to keep the graph lean.

func (*Engine) CompressSession

func (e *Engine) CompressSession(sessionID, project string) (*storage.Node, error)

CompressSession creates a session summary node linking all memories from the session.

func (*Engine) Context

func (e *Engine) Context(project string) (*RecallResult, error)

Context returns the hot-tier subgraph for session start injection.

func (*Engine) Feedback

func (e *Engine) Feedback(id string, action FeedbackAction, newContent string) error

Feedback applies user feedback to a memory node.

func (*Engine) Forget

func (e *Engine) Forget(id string) error

Forget archives a node by setting confidence to 0.

func (*Engine) Graph

func (e *Engine) Graph() *graph.Graph

Graph returns the underlying graph engine.

func (*Engine) MentalModel

func (e *Engine) MentalModel(project string) (*mental.Model, error)

MentalModel generates an auto-evolving project summary.

func (*Engine) PendingNodes

func (e *Engine) PendingNodes(project string, threshold float64) ([]*storage.Node, error)

PendingNodes returns low-confidence nodes that may need review.

func (*Engine) Profile

func (e *Engine) Profile(project string) (*profile.Profile, error)

Profile returns an auto-maintained user/project profile (static facts + dynamic context).

func (*Engine) Recall

func (e *Engine) Recall(opts RecallOpts) (*RecallResult, error)

Recall performs graph-aware hybrid search: BM25 seed → graph expand → rank.

func (*Engine) Remember

func (e *Engine) Remember(in RememberInput) (*storage.Node, error)

Remember creates a memory node with privacy filtering, dedup, and entity extraction.

func (*Engine) Rollback

func (e *Engine) Rollback(id string, version int) error

Rollback restores a node to a previous version.

func (*Engine) StartSession

func (e *Engine) StartSession(project, agent string) (string, error)

StartSession creates a new session record and returns its ID.

func (*Engine) Status

func (e *Engine) Status(project string) (*Status, error)

func (*Engine) Store

func (e *Engine) Store() *storage.Store

Store returns the underlying store.

type Entity

type Entity struct {
	Name string
	Type string // "file" or "entity"
}

Entity represents an auto-extracted entity from content.

func ExtractEntities

func ExtractEntities(content string) []Entity

ExtractEntities pulls file paths, packages, functions, and classes from content.

type FeedbackAction

type FeedbackAction string

FeedbackAction represents what to do with a pending memory.

const (
	FeedbackApprove FeedbackAction = "approve"
	FeedbackEdit    FeedbackAction = "edit"
	FeedbackDiscard FeedbackAction = "discard"
)

type HybridSearch

type HybridSearch struct {
	// contains filtered or unexported fields
}

HybridSearch performs 3-stage retrieval: BM25 → vector → graph expansion → RRF fusion.

func NewHybridSearch

func NewHybridSearch(store *storage.Store, g *graph.Graph, provider embeddings.Provider) *HybridSearch

NewHybridSearch creates a hybrid search engine.

func (*HybridSearch) Search

func (h *HybridSearch) Search(ctx context.Context, query string, opts RecallOpts) ([]*ScoredNode, error)

Search runs hybrid search and returns ranked nodes. 4-path retrieval: BM25 + vector + graph (intent-aware) + temporal recency Based on Hindsight's multi-strategy approach.

type LLMExtractor

type LLMExtractor struct {
	// contains filtered or unexported fields
}

LLMExtractor uses an LLM to extract entities from content. Falls back to regex extraction if LLM is unavailable.

func NewLLMExtractor

func NewLLMExtractor(apiKey, baseURL, model string) *LLMExtractor

NewLLMExtractor creates an LLM-based entity extractor. baseURL: "https://api.openai.com" or any OpenAI-compatible endpoint.

func (*LLMExtractor) Extract

func (e *LLMExtractor) Extract(ctx context.Context, content string) []Entity

Extract returns entities from content using the LLM. Returns regex-extracted entities if LLM call fails.

type ProactiveContext

type ProactiveContext struct {
	// contains filtered or unexported fields
}

ProactiveContext predicts what context the agent will likely need next by analyzing recent access patterns and graph connectivity.

func NewProactiveContext

func NewProactiveContext(eng *Engine, search *HybridSearch) *ProactiveContext

NewProactiveContext creates a proactive context predictor.

func (*ProactiveContext) Predict

func (p *ProactiveContext) Predict(ctx context.Context, project string, budget int) ([]*storage.Node, error)

Predict returns nodes likely needed in the next session based on: 1. Recently accessed nodes and their neighbors 2. Active tasks and their dependencies 3. High-centrality nodes in the project subgraph

type RecallOpts

type RecallOpts struct {
	Query   string
	Depth   int
	Limit   int
	Type    string
	Tier    int
	Project string
}

RecallOpts configures a recall search.

type RecallResult

type RecallResult struct {
	Nodes []*storage.Node
	Edges []*storage.Edge
}

RecallResult holds search results.

type RememberInput

type RememberInput struct {
	Type    string // convention|decision|bug|spec|task|preference
	Content string
	Summary string
	Scope   string // global|project
	Project string
	Tier    int
	Tags    string
	Session string
	Agent   string
	// Optional: explicit edges to create
	Edges []EdgeInput
}

RememberInput is the input for creating a memory node.

type ScoredNode

type ScoredNode struct {
	Node  *storage.Node
	Score float64
}

ScoredNode is a node with a combined relevance score.

func Rerank

func Rerank(nodes []*ScoredNode, store *storage.Store) []*ScoredNode

Rerank re-scores nodes combining RRF score, graph centrality, recency, and confidence.

type Status

type Status struct {
	Nodes    int
	Edges    int
	Sessions int
}

Status returns basic stats.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL