Documentation
¶
Overview ¶
Package memory implements the persistent memory storage layer for golder.
It is backed by a pure-Go SQLite database (modernc.org/sqlite, no CGO) with an FTS5 full-text index over Markdown memory files. This file provides the Store type together with database opening and idempotent schema migration. The package also holds path resolution, reconcile (lazy indexing/pruning) and BM25 search.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Locator ¶
Locator is the parsed identity of a memory file on disk: which scope it belongs to, the scope id (project-id / session-id / slug; "" for global), the semantic type, and the absolute path of the file itself.
type Result ¶
Result reports what a Reconcile pass changed: Indexed counts rows inserted or updated (new or changed files), Pruned counts rows deleted because their file no longer exists on disk.
type SearchOptions ¶
type SearchOptions struct {
// Scope, ScopeID and Type, when non-empty, restrict results to rows whose
// corresponding memory_index column matches exactly.
Scope string
ScopeID string
Type string
// Limit caps the number of returned results; <=0 means the default of 10.
Limit int
// ReconcileFirst runs a lazy Store.Reconcile before searching so that
// off-tool writes are picked up. Its counts are ignored; hard errors
// propagate.
ReconcileFirst bool
// ScoreFloor is the relative floor ratio: trailing rows scoring below
// topScore*ScoreFloor are dropped. <=0 keeps all matches when 0, but the
// default of 0.15 is used when the field is left at its zero value; pass a
// negative value to explicitly disable the floor.
ScoreFloor float64
}
SearchOptions tunes a Store.Search call. All fields are optional; the zero value performs an unfiltered search with default limit and score floor.
type SearchResult ¶
type SearchResult struct {
Path string
Snippet string
Score float64
Scope Scope
ScopeID string
Type Type
}
SearchResult is a single ranked hit from Store.Search. Score is normalized so that higher = better (the raw FTS5 bm25 value, where lower is better, is negated).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the handle to the memory database. Fields are unexported; later nodes access the underlying *sql.DB via DB() and the configured roots via the package-internal fields.
func Open ¶
Open opens (creating if necessary) the SQLite database at dbPath and runs the idempotent schema migration. The parent directory of dbPath is created with os.MkdirAll before opening. root is the memory root directory and ccBase is the optional Claude Code base directory; both are retained for use by later nodes and are not required to exist here.
Calling Open twice on the same file is safe: the migration uses CREATE ... IF NOT EXISTS throughout.
func (*Store) CountByScope ¶
CountByScope returns the number of indexed memory entries grouped by scope. Scopes with no entries are omitted from the map. It reflects the current contents of memory_index; callers that want fresh counts should Reconcile first. A nil store or nil db yields an empty map.
func (*Store) DB ¶
DB returns the underlying *sql.DB for use by later nodes and tests. It may be nil if the store was not successfully opened.
func (*Store) Reconcile ¶
Reconcile performs a lazy sync between the memory files on disk and the memory_index table. It walks both the mimo root and (when configured) the cc base, prunes rows whose file no longer exists, and indexes new or changed files. Unchanged files are skipped via a size-mtime fingerprint. The FTS index is kept consistent by the memory_ai/ad/au triggers, so only memory_index is touched here.
func (*Store) Root ¶
Root returns the memory root directory the store was opened with (the magic layout root holding global/projects/sessions). It is the canonical source for the memory root used by checkpoint persistence and context rebuild (<root>/sessions/<id>/checkpoint.md); callers must resolve the memory root through this accessor rather than re-deriving it from another store's dir. It is "" for a nil store.
func (*Store) Search ¶
func (s *Store) Search(query string, opts SearchOptions) ([]SearchResult, error)
Search runs a BM25 full-text query over the indexed memory bodies.
The free-form query is tokenized and OR-joined by buildFtsQuery; an empty token set returns (nil, nil) without touching SQL. Results are ranked by BM25 (converted to higher = better), over-fetched 3x (capped at 50) so a relative score floor can trim common-word-only noise, then sliced to the requested limit. Optional scope/scope_id/type filters restrict the corpus.