Documentation
¶
Index ¶
- Constants
- func EstimateTokens(content string) int
- func Excerpt(body string, maxTokens int) string
- type ContextItem
- type ContextPackConfig
- type ContextPackResult
- type ContextPackTarget
- type RecallConfig
- type RecallEdge
- type RecallNode
- type RecallResult
- type ReciteConfig
- type ReciteItem
- type ReciteResult
- type RelatedConfig
- type RelatedItem
- type RelatedResult
- type SummarizeConfig
- type SummarizeResult
- type SummarizeSource
Constants ¶
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 ¶
EstimateTokens estimates the number of LLM tokens for the given content. Uses the heuristic of 4 characters per token with ceiling division.
func Excerpt ¶ added in v0.7.0
Excerpt returns the most decision-relevant part of a note body, within maxTokens.
WHY THIS EXISTS. The packer includes bodies all-or-nothing (`if bodyTokens <= *remaining`), so a note larger than the leftover budget contributes nothing at all and the pack reports "3 items, 0 with bodies" — items present, content absent. Measured on the identity vault, whose median note is ~1,084 tokens against a 900-token hook budget, that is the common case rather than the edge case.
An excerpt always fits, so it turns "no body" into "the part that matters".
It prefers the Principle section because of how arcs are written: the first paragraph is the Trigger — story setup — and the rule an agent could act on is several sections down. Injecting the lead hands over the anecdote and withholds the lesson.
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"`
// BodyExcerpted marks Body as the note's most decision-relevant passage
// rather than its whole text. It is recorded rather than inferred because
// "the agent got the note" and "the agent got the gist" are different facts,
// and a metric that cannot tell them apart reports the second as the first.
BodyExcerpted bool `json:"body_excerpted,omitempty"`
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
// ExcerptTokens caps a per-item excerpt used when a whole body will not fit
// the remaining budget. 0 (default) keeps the released all-or-nothing
// behaviour, where such an item contributes no text at all.
//
// Without this, a pack can honestly report "3 items" while handing the agent
// nothing but titles — which is what a 900-token hook budget does against a
// vault whose median note is larger than the budget.
ExcerptTokens int
}
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"`
// BodyExcerpted marks Body as the note's decision-bearing passage rather
// than its whole text — same meaning as on ContextItem, and needed here for
// the same reason: a renderer that cannot tell the difference will truncate
// an already-bounded excerpt a second time.
BodyExcerpted bool `json:"body_excerpted,omitempty"`
Body string `json:"body,omitempty"`
}
ContextPackTarget holds the fully-loaded target note.
type RecallConfig ¶
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 ReciteConfig ¶ added in v0.8.0
type ReciteConfig struct {
// Type is the note type to enumerate ("arc").
Type string
// Budget is the total token ceiling. 0 means unbounded.
Budget int
// ExcerptTokens caps each note's contribution. 0 means whole bodies.
ExcerptTokens int
}
ReciteConfig selects the layer and bounds it.
type ReciteItem ¶ added in v0.8.0
type ReciteItem struct {
ID string `json:"id"`
Title string `json:"title"`
Excerpt string `json:"excerpt"`
Tokens int `json:"tokens"`
}
ReciteItem is one note rendered for recitation.
type ReciteResult ¶ added in v0.8.0
type ReciteResult struct {
Type string `json:"type"`
Total int `json:"total"`
Items []ReciteItem `json:"items"`
Omitted int `json:"omitted"`
OmittedIDs []string `json:"omitted_ids,omitempty"`
Tokens int `json:"tokens"`
Budget int `json:"budget"`
}
ReciteResult is the whole layer, plus an explicit account of what did not fit.
Omitted and OmittedIDs exist because a bulk loader that silently drops the tail is the same defect this feature fixes, wearing different clothes: the caller cannot tell "you have 27 arcs and here they are" from "you have 27 arcs and here are 9". Whoever reads this must be able to see the difference.
func Recite ¶ added in v0.8.0
func Recite(db *index.DB, cfg ReciteConfig) (*ReciteResult, error)
Recite returns every note of cfg.Type, ordered by id, excerpted and bounded.
Ordering is by id rather than by rank or mtime: an identity layer that arrives in a different order each session is a different thing arriving each session, and nothing downstream could be compared run to run.
func (*ReciteResult) Truncated ¶ added in v0.8.0
func (r *ReciteResult) Truncated() bool
Truncated reports whether the budget forced anything out.
type RelatedConfig ¶
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 ¶
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.