Documentation
¶
Index ¶
- Constants
- Variables
- func Close() error
- func ConceptLine(c Concept) string
- func DefaultDBPath() (string, error)
- func FileBlock(ctx context.Context, cwd, path string) string
- func FormatConcepts(concepts []Concept, heading, note string, bodies int) string
- func IsOpen() bool
- func NormalizeTopic(t string) string
- func Open(opts Options) error
- func RecallBlock(ctx context.Context, cwd, prompt, topic string, exclude map[int64]bool) (string, string)
- func ScopeFor(cwd string) string
- func SerializeVector(vec []float32) []byte
- func SetDefault(s *Service)
- func SystemBlock(ctx context.Context, cwd string) string
- func TitleFromBody(body string) string
- func TopIDs(ctx context.Context, cwd string) map[int64]bool
- func Upsert(ctx context.Context, c Concept) (int64, error)
- func ValidKind(k string) bool
- type Concept
- type Embedder
- type Extractor
- type FakeEmbedder
- type Options
- type RecallQuery
- type RecallResult
- type Service
- func (s *Service) AddSessionToMemory(ctx context.Context, sess session.Session) error
- func (s *Service) Close() error
- func (s *Service) Demote(ctx context.Context, id int64) (bool, error)
- func (s *Service) Forget(ctx context.Context, id int64) error
- func (s *Service) Get(ctx context.Context, id int64) (Concept, error)
- func (s *Service) IsOpen() bool
- func (s *Service) Recall(ctx context.Context, q RecallQuery) (RecallResult, error)
- func (s *Service) Reinforce(ctx context.Context, id int64) (bool, error)
- func (s *Service) SearchMemory(ctx context.Context, req *adkmemory.SearchRequest) (*adkmemory.SearchResponse, error)
- func (s *Service) SetExtractor(e Extractor)
- func (s *Service) Top(ctx context.Context, cwd string, k int) ([]Concept, error)
- func (s *Service) TopicNames(ctx context.Context, cwd string, k int) []string
- func (s *Service) Topics(ctx context.Context, cwd string, k int) ([]Topic, error)
- func (s *Service) TouchTopic(ctx context.Context, cwd, name string) error
- func (s *Service) Upsert(ctx context.Context, c Concept) (int64, error)
- type Topic
- type TurnRecord
Constants ¶
const ( KindUser = "user" KindFeedback = "feedback" KindProject = "project" KindReference = "reference" ScopeGlobal = "global" )
Concept kinds and the global scope.
const ( // DefaultRecallK is how many concepts a per-turn recall returns. DefaultRecallK = 15 // DefaultTopK is how many top-weighted concepts open a session. DefaultTopK = 15 // DefaultBodies is how many of the leading concepts carry their body // inline; the rest are titles the model can expand with load_memory. DefaultBodies = 3 // DefaultTopicK bounds the topic list shown to the model. DefaultTopicK = 20 // DefaultHookTimeout caps how long recall operations can take. DefaultHookTimeout = 8 * time.Second )
const ( WeightInitial = 1.0 WeightCap = 5.0 WeightFloor = 0.05 // ImplicitBump is applied to every concept a recall returns. ImplicitBump = 0.05 // ExplicitBump is the reinforce/demote magnitude; positive bumps are // log-dampened toward WeightCap so repeated calls cannot pin a concept. ExplicitBump = 0.5 // RefractoryPeriod drops a second explicit bump on the same concept // inside the window, so an implicit recall bump followed by an // immediate reinforce is not double-counted. RefractoryPeriod = 60 * time.Second ConceptHalfLife = 100 * 24 * time.Hour TopicHalfLife = 60 * 24 * time.Hour // Reranking: score = sim^RerankSimExp * weight^RerankWeightExp, then // TopicBoost for candidates in the turn's topic. RerankSimExp = 1.0 RerankWeightExp = 0.5 TopicBoost = 1.15 // CandidateOversample is how many raw vector hits are pulled before // reranking; MaxDistance is the cosine-distance relevance floor. CandidateOversample = 50 MaxDistance = 0.4 )
Weight tunables. Weight is the running importance of a concept: it decays exponentially with disuse and is bumped whenever the concept is surfaced (implicit) or judged useful by the model (explicit).
Variables ¶
var Kinds = []string{KindUser, KindFeedback, KindProject, KindReference}
Kinds lists every valid concept kind.
Functions ¶
func ConceptLine ¶
ConceptLine is the one-line index entry for a concept.
func DefaultDBPath ¶
DefaultDBPath returns the standard SQLite vector database file location.
func FileBlock ¶
FileBlock returns titles recalled for a touched file path, without a weight bump: a path match is weak evidence of relevance.
func FormatConcepts ¶
FormatConcepts renders concepts as a titled list: one line per concept as "#id [kind · topic] title", with the first bodies concepts carrying their body indented beneath.
func IsOpen ¶
func IsOpen() bool
IsOpen reports whether the default process-wide memory service is open.
func NormalizeTopic ¶
NormalizeTopic lowercases, collapses whitespace, and caps a topic at three words so the taxonomy stays short.
func RecallBlock ¶
func RecallBlock(ctx context.Context, cwd, prompt, topic string, exclude map[int64]bool) (string, string)
RecallBlock returns the per-turn block for prompt and the topic the hits imply. ids already in the system block are dropped so a turn does not repeat what the session opened with.
func ScopeFor ¶
ScopeFor maps a working directory to its memory scope: the project root, falling back to the cleaned cwd. An empty cwd has no scope.
func SerializeVector ¶
SerializeVector converts a float32 slice to the byte representation expected by sqlite-vec.
func SetDefault ¶
func SetDefault(s *Service)
SetDefault replaces the default global Service instance.
func SystemBlock ¶
SystemBlock returns the session-start block: the top-weighted concepts for cwd's project and global scopes.
func TitleFromBody ¶
TitleFromBody derives a one-line title: the first non-empty line, clipped to 80 runes.
Types ¶
type Concept ¶
type Concept struct {
ID int64 `json:"id"`
Scope string `json:"scope"`
Kind string `json:"kind"`
Topic string `json:"topic,omitempty"`
Title string `json:"title"`
Body string `json:"body"`
Weight float64 `json:"weight"`
AccessCount int64 `json:"access_count"`
CreatedAt time.Time `json:"created_at"`
LastTouched time.Time `json:"last_touched"`
// Distance and Score are set on recall hits only.
Distance float32 `json:"distance,omitempty"`
Score float64 `json:"score,omitempty"`
}
Concept is one long-term memory: a one-line title that goes into prompts cheaply, a body fetched on demand, and a decaying weight.
type Embedder ¶
Embedder represents a model capable of generating vector embeddings for text.
The store never loads a model itself: callers hand one in through Options.Embedder. cmd/ask uses the llama.cpp model in pkg/memory/llamacpp, the one place in the module that links llama.cpp; other consumers bring their own, and tests use NewFakeEmbedder.
type Extractor ¶
type Extractor interface {
Enqueue(TurnRecord) bool
}
Extractor turns finished turns into concepts, asynchronously.
type FakeEmbedder ¶
type FakeEmbedder struct {
// contains filtered or unexported fields
}
FakeEmbedder is the deterministic test embedder: a hashed bag of words, L2-normalised, so texts sharing words land near each other and unrelated texts do not.
func NewFakeEmbedder ¶
func NewFakeEmbedder(dim int) *FakeEmbedder
func (*FakeEmbedder) Close ¶
func (f *FakeEmbedder) Close()
func (*FakeEmbedder) EmbdSize ¶
func (f *FakeEmbedder) EmbdSize() int
type Options ¶
type Options struct {
DBPath string
// Embedder produces the vectors the store indexes; required.
Embedder Embedder
// Now is the clock decay and refractory math read; nil means time.Now.
Now func() time.Time
}
Options configures the initialization of the Memory Service.
type RecallQuery ¶
type RecallQuery struct {
// Cwd selects the project scope; global concepts are always included.
// Empty searches every scope.
Cwd string
// Query is embedded and matched against every concept.
Query string
// Topic is the caller's current topic, used when the hits do not agree
// on one and to boost same-topic candidates.
Topic string
K int
// Silent skips the implicit weight bump on the returned concepts.
Silent bool
}
RecallQuery describes one recall.
type RecallResult ¶
type RecallResult struct {
Concepts []Concept
// Topic is the dominant topic among the candidates, else Query.Topic.
Topic string
}
RecallResult is the ranked hits plus the topic inferred from them.
func Recall ¶
func Recall(ctx context.Context, q RecallQuery) (RecallResult, error)
Recall queries the default service.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages concept persistence, retrieval, and weighting.
func NewService ¶
NewService initializes a SQLite-vec memory service with the specified options.
func (*Service) AddSessionToMemory ¶
AddSessionToMemory hands the session's last exchange to the installed Extractor. ADK calls this with a finished session; ask's own turn boundaries enqueue directly.
func (*Service) Demote ¶
Demote applies a negative explicit bump, clamped at WeightFloor. The concept is never deleted.
func (*Service) Recall ¶
func (s *Service) Recall(ctx context.Context, q RecallQuery) (RecallResult, error)
Recall embeds the query, pulls the nearest candidates in the project and global scopes, reranks them by similarity and decayed weight, infers the turn's topic from them, and bumps what it returns.
func (*Service) Reinforce ¶
Reinforce applies a positive explicit bump. It reports false when the concept was explicitly touched inside RefractoryPeriod.
func (*Service) SearchMemory ¶
func (s *Service) SearchMemory(ctx context.Context, req *adkmemory.SearchRequest) (*adkmemory.SearchResponse, error)
SearchMemory is the ADK-shaped recall: every scope, no topic.
func (*Service) SetExtractor ¶
SetExtractor installs the Extractor AddSessionToMemory hands turns to.
func (*Service) Top ¶
Top returns the highest-weighted concepts in the project and global scopes. No embedding, no bump: this is the session-start block.
func (*Service) TopicNames ¶
TopicNames is Topics reduced to names.
func (*Service) Topics ¶
Topics returns the live topics for cwd's scope plus global, strongest first, deduplicated by name.
func (*Service) TouchTopic ¶
TouchTopic creates or bumps a topic in cwd's scope (global when cwd is empty).
type Topic ¶
type Topic struct {
ID int64 `json:"id"`
Scope string `json:"scope"`
Name string `json:"name"`
Weight float64 `json:"weight"`
LastTouched time.Time `json:"last_touched"`
}
Topic is a short label concepts are grouped under, weighted like a concept so stale topics fall out of the candidate list.
type TurnRecord ¶
TurnRecord is one finished conversational turn handed to an Extractor.
func TurnFromSession ¶
func TurnFromSession(sess session.Session) TurnRecord
TurnFromSession reduces a session to its last exchange: the final user text and every model text after it. Cwd comes from session state when a caller stored one.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package llamacpp is the llama.cpp embedder for the memory store: a GGUF embedding model driven through cgo against the static libraries under build/llama.cpp.
|
Package llamacpp is the llama.cpp embedder for the memory store: a GGUF embedding model driven through cgo against the static libraries under build/llama.cpp. |