Documentation
¶
Overview ¶
Package recall is the one recall for memory notes and pages (itd-2610091918433290, itd-39; spc-2610111627213138). The prompt router calls it once per prompt, after rules.Inject, with the items the memory layers yield, and it returns one block headed "## MEMORY" for the hook to append after the rules block.
Matching is the loader's own (rules.TermMatcher), so a note's recall word and a rule domain's recall word hit on exactly the same prompts. The per-session ledger is SessionState.Recalled, keyed on each item's content, cleared by the loader's resets. The budget is what the rules leave of the loader's one per-turn budget (rules.InjectionBudgetBytes), and the relevance ranking (ranking.go, BM25F) decides which candidates fit it.
Notes come from both memory.json layers (step 2) and pages from both page scopes (step 3, pages.go), through one path. Nothing here writes to stdout or knows a transport.
Index ¶
Constants ¶
const ( LayerProject = "project" LayerMachine = "machine" )
The layers an item comes from, as the diagnostic names them: a note's memory.json, or a page's scope (the project's .abcd/memory/ or the machine's ~/.abcd.noindex/memory/).
const ( KindNote = "note" KindPage = "page" )
The kinds of item.
const ( FieldRecall = "recall" FieldTitle = "title" FieldBody = "body" )
The fields an item's words are found in, as the diagnostic names them.
const ( FormFull = "full" FormLine = "one-line" )
The forms an item comes back in (the bracket table's memory columns, rules.BracketRow): in full, its head and its body, or as one line, its head alone.
const PageKeyPrefix = "page:"
PageKeyPrefix begins a page item's key; the rest is its filename.
Variables ¶
This section is empty.
Functions ¶
func ReadItems ¶ added in v0.16.0
ReadItems is every note and page in reach, in id order — notes (mem-…) before pages (page:…) — and every layer, scope or page that could not be read. It is what the prompt router and `rules --prompt` hand the recall.
func ReadLayers ¶
ReadLayers is the one reader of both note layers, for the recall and for the memory verb alike: the machine's under home, the project's under repoRoot, the root the rules loader resolved, each through memnote's layer reader. A layer that cannot be read is a Refusal and yields no notes, never an error: the hook still injects the rules, and the verb still shows what the other layer holds. It asks git nothing.
Types ¶
type Item ¶
type Item struct {
Key string
Kind string
Layer string
Title string
Body string
Recall []string
At time.Time
Tie *string
}
Item is one thing the recall can bring back: a note or a page. Key is its ledger key and the ranking's last tie-break — a note's id (mem-…), and a page's "page:<filename>". At is when it was written, the ranking's recency tie-break: a note's written_at, a page's latest ingested_at, the zero time when it records none. Tie is the root commit a personal note is tied to; nil for a note recalled everywhere, for every item in the project's file, and for every page.
type Layers ¶
Layers is what a read of both note layers gave: the notes as they stand in the machine's file and in the project's.
type Ranked ¶ added in v0.16.0
Ranked is a candidate with its score and the terms behind it.
func Rank ¶ added in v0.16.0
Rank matches items against prompt, judges each tied note's root (matching, which asks root only when a tied item matched), and returns the candidates in ranked order, each with its score and the terms behind it, with the root lookup's error beside them. The score is BM25F: for each query term t found in the item,
idf(t) · tf_w / (tf_w + k1 · (1 − b + b · len / avg_len))
summed over the terms, with idf(t) = ln(1 + (N − n_t + 0.5) / (n_t + 0.5)) over every item in reach (N items, n_t of them holding t), so a word every item shares counts for little and a rare word that matches counts for a lot. Every item read is in reach, a personal note tied to another repository among them: the tie is judged lazily, only for the candidates, so the corpus never depends on whether git was asked. Ties break on the narrower scope (the project's before the machine's), then the more recent At, then the key, so the order is the same on every machine and every run.
type Refusal ¶
type Refusal struct {
File string `json:"file"`
Reason string `json:"reason"`
Kind string `json:"kind"`
}
Refusal names a layer, page scope or page the recall could not read, and why, in words safe to print: the file in tilde or repository-relative form, the reason home-redacted and terminal-safe. Kind is what it would have brought back: KindNote for a memory.json, KindPage for a page scope or page.
type Request ¶
type Request struct {
// Items are every note and page in reach (ReadItems).
Items []Item
// Prompt is the prompt the hook was handed.
Prompt string
// Ledger is the session's recalled ledger (rules.SessionState.Recalled):
// item key to the content signature last sent.
Ledger map[string]string
// Budget is what the rules and the blocks read before them left of the
// loader's per-turn budget, rules.InjectionBudgetBytes.
Budget int
// Disabled is the loader's kill switch: recall is the loader's, so the
// switch silences it too.
Disabled bool
// Root answers the repository's root commit, for the items tied to one;
// asked only once a tied item matched (matching).
Root RootFunc
// Bracket is the context bracket the session is in (rules.BracketFor
// its fill), whose row says how many candidates come back in full and
// how many as one line each. The zero value is rules.BracketUnknown:
// one line each.
Bracket rules.Bracket
}
Request is one prompt's recall.
type Result ¶
type Result struct {
Text string
Recalled []string
Omitted []string
TooLarge []string
Ledger map[string]string
RootErr error
// contains filtered or unexported fields
}
Result is one prompt's recall. Text is empty when nothing new comes back. Recalled names each item Text carries, in order; Omitted each new candidate that did not fit this turn's budget, not recorded and so retried on the next turn; TooLarge each new candidate whose one line alone is larger than the whole per-turn budget (rules.InjectionBudgetBytes), which no turn can carry, so it is set aside without stopping the take and never recorded. Ledger is the updated recalled ledger, a copy. RootErr is the root-commit lookup's error (git did not answer in time) when a tied item matched and was left out for it — unrecorded, so retried on the next turn.
func Recall ¶
Recall matches the items against the prompt, judges each tied note's root (matching), ranks the candidates (Rank), drops every one already sent this session with unchanged content, and takes the rest in ranked order in the forms the context bracket's row gives them (take, rules.BracketRow): in full, then as one line each, within the row's bounds and the budget. The first that does not fit a form ends that form's take, so an item never comes back ahead of, or larger than, one ranked above it that a later turn can still carry. An item larger than the whole per-turn budget is sent as one line, so it cannot hold back every item below it on every turn. The ledger records an item's content whatever its form, so a change of bracket never sends it again. Its only I/O is req.Root, asked when a tied item matched, and it never reflects prompt bytes into the block.
func (Result) Form ¶ added in v0.16.1
Form is the form the recall sent an item in this turn: FormFull or FormLine, and "" for an item it did not send.
type RootFunc ¶
RootFunc answers the repository's root commit, "" where there is none. The recall asks it only once matching has found a tied item, and at most once per call, so a prompt that matches no tied item costs no git call. A caller that hands the same RootFunc to more than one call memoises it (sync.OnceValues). An error is git not answering, in time or at all (gitutil.RootCommitContext): the tied items are then left out.
type TermScore ¶ added in v0.16.0
type TermScore struct {
Term string `json:"term"`
Recall int `json:"recall"`
Title int `json:"title"`
Body int `json:"body"`
Contribution float64 `json:"contribution"`
}
TermScore is one query term's part in an item's score: how many times it was found in each field, and what it contributed.