memory

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PriorityExplicitRelation = 0 // frontmatter related_ids, parent_id, source_ids
	PriorityExplicitLink     = 1 // wikilinks, markdown links, embeds
	PriorityMediumConfidence = 2 // inferred edges with medium confidence
	PriorityLowConfidence    = 3 // inferred edges below medium
)

Priority tier constants for edgePriority. Lower value = higher priority (closer to the target in the context-pack ranking).

The numeric values also appear in the distance-weighted ranking formula (distance*10 + priority), so the gaps between tiers encode the relative cost of "one edge further away" vs "one tier weaker confidence". Don't renumber without updating the distance formula.

Variables

This section is empty.

Functions

func EstimateTokens

func EstimateTokens(content string) int

EstimateTokens estimates the number of LLM tokens for the given content. Uses the heuristic of 4 characters per token with ceiling division.

Types

type ContextItem

type ContextItem struct {
	ID           string                 `json:"id"`
	EdgeType     string                 `json:"edge_type"`
	Confidence   string                 `json:"confidence"`
	Frontmatter  map[string]interface{} `json:"frontmatter"`
	BodyIncluded bool                   `json:"body_included"`
	Body         string                 `json:"body,omitempty"`
}

ContextItem holds context metadata for a single related note.

type ContextPackConfig

type ContextPackConfig struct {
	Input            string
	Budget           int                // token budget
	Depth            int                // BFS traversal depth; 0 or 1 = direct neighbors only (default)
	MaxItems         int                // max context items to return; 0 = unlimited (default, backward-compat)
	Slim             bool               // reduce context item frontmatter to {type, title, status} only
	ActivationScores map[string]float64 // optional activation scores keyed by note ID
}

ContextPackConfig holds parameters for a ContextPack operation.

type ContextPackResult

type ContextPackResult struct {
	TargetID        string             `json:"target_id"`
	BudgetTokens    int                `json:"budget_tokens"`
	UsedTokens      int                `json:"used_tokens"`
	BudgetExhausted bool               `json:"budget_exhausted"`
	Truncated       bool               `json:"truncated"`
	Target          *ContextPackTarget `json:"target"`
	Context         []ContextItem      `json:"context"`
}

ContextPackResult is the full output of a ContextPack operation.

func ContextPack

func ContextPack(resolver *graph.Resolver, db *index.DB, cfg ContextPackConfig) (*ContextPackResult, error)

ContextPack resolves the input, loads the target note, and fills a token budget with the target body and related note frontmatter in priority order.

type ContextPackTarget

type ContextPackTarget struct {
	ID          string                 `json:"id"`
	Frontmatter map[string]interface{} `json:"frontmatter"`
	Body        string                 `json:"body,omitempty"`
}

ContextPackTarget holds the fully-loaded target note.

type RecallConfig

type RecallConfig struct {
	Input         string
	Depth         int
	MinConfidence string
	MaxNodes      int
}

RecallConfig holds parameters for a Recall operation.

type RecallEdge

type RecallEdge struct {
	SourceID   string `json:"source_id"`
	TargetID   string `json:"target_id"`
	EdgeType   string `json:"edge_type"`
	Confidence string `json:"confidence"`
}

RecallEdge describes a directed edge between two nodes in the result.

type RecallNode

type RecallNode struct {
	ID             string                 `json:"id"`
	Type           string                 `json:"type"`
	Title          string                 `json:"title"`
	Distance       int                    `json:"distance"`
	EdgeFromParent *graph.TraverseEdge    `json:"edge_from_parent,omitempty"`
	Frontmatter    map[string]interface{} `json:"frontmatter"`
}

RecallNode is an enriched graph node returned by Recall.

type RecallResult

type RecallResult struct {
	TargetID        string       `json:"target_id"`
	Depth           int          `json:"depth"`
	MaxNodes        int          `json:"max_nodes"`
	MaxNodesReached bool         `json:"max_nodes_reached"`
	Nodes           []RecallNode `json:"nodes"`
	Edges           []RecallEdge `json:"edges"`
}

RecallResult is the full output of a Recall operation.

func Recall

func Recall(resolver *graph.Resolver, db *index.DB, cfg RecallConfig) (*RecallResult, error)

Recall resolves the input entity and returns an enriched subgraph neighbourhood. It resolves the input via the resolver, traverses the graph using BFS, and enriches each traversal node with type, title, and frontmatter from the database.

type RelatedConfig

type RelatedConfig struct {
	Input string
	Mode  string // "mixed", "explicit", or "inferred"
}

RelatedConfig holds parameters for a Related operation.

type RelatedItem

type RelatedItem struct {
	ID         string  `json:"id"`
	Type       string  `json:"type"`
	Title      string  `json:"title"`
	EdgeType   string  `json:"edge_type"`
	Confidence string  `json:"confidence"`
	Origin     string  `json:"origin"`
	Score      float64 `json:"score,omitempty"`
}

RelatedItem is a single related note returned by Related.

type RelatedResult

type RelatedResult struct {
	TargetID string        `json:"target_id"`
	Mode     string        `json:"mode"`
	Related  []RelatedItem `json:"related"`
}

RelatedResult is the full output of a Related operation.

func Related(resolver *graph.Resolver, db *index.DB, cfg RelatedConfig) (*RelatedResult, error)

Related resolves the input entity and returns directly connected notes, filtered by the given mode ("mixed", "explicit", or "inferred").

type SummarizeConfig

type SummarizeConfig struct {
	NoteIDs     []string
	IncludeBody bool
	MaxBodyLen  int // max chars per note body (0 = full)
}

SummarizeConfig controls which notes to load and how much body text to include.

type SummarizeResult

type SummarizeResult struct {
	Sources   []SummarizeSource `json:"sources"`
	NoteCount int               `json:"note_count"`
	NotFound  []string          `json:"not_found,omitempty"`
}

SummarizeResult is the assembled output for agent consumption.

func Summarize

func Summarize(db *index.DB, cfg SummarizeConfig) (*SummarizeResult, error)

Summarize loads frontmatter and optional body excerpts from the requested notes. It does not call an LLM — it assembles raw material for agent-driven synthesis.

type SummarizeSource

type SummarizeSource struct {
	ID          string                 `json:"id"`
	Type        string                 `json:"type"`
	Title       string                 `json:"title"`
	Frontmatter map[string]interface{} `json:"frontmatter"`
	BodyExcerpt string                 `json:"body_excerpt,omitempty"`
}

SummarizeSource holds assembled data for a single note.

Jump to

Keyboard shortcuts

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