Skip to main content
NuggetShelf is the recommended entry point when your application works with more than one nugget. It owns the nugget lifecycle (create, load, remove) and fans out recall and search queries across all managed nuggets automatically.

Constructor

new NuggetShelf(opts?: {
  saveDir?: string;
  autoSave?: boolean;
})
opts.saveDir
string
default:"~/.nuggets"
Directory where nugget files and the graph are stored. All nuggets created by this shelf share the same saveDir.
opts.autoSave
boolean
default:"true"
Passed through to every nugget created or loaded by this shelf.
import { NuggetShelf } from "./src/nuggets/index.js";

const shelf = new NuggetShelf({ saveDir: "~/.nuggets" });
shelf.loadAll(); // restore any previously saved nuggets

Properties

saveDir
string
The directory used for all nugget files on this shelf. Read-only.
autoSave
boolean
Whether auto-save is enabled for all nuggets. Read-only.
size
number
The number of nuggets currently held on the shelf.

Nugget lifecycle

create

create(
  name: string,
  opts?: { D?: number; banks?: number; ensembles?: number },
): Nugget
Creates a new Nugget and registers it on the shelf. Throws if a nugget with that name already exists.
name
string
required
Unique name for the nugget.
opts.D
number
default:"16384"
FHRR vector dimensionality.
opts.banks
number
default:"4"
Number of memory banks.
opts.ensembles
number
default:"1"
Number of ensemble copies.
Returns the new Nugget instance.
const prefs = shelf.create("prefs");
prefs.remember("user:theme", "dark");

get

get(name: string): Nugget
Retrieves a registered nugget by name. Throws if the nugget does not exist.
name
string
required
Name of the nugget to retrieve.
const prefs = shelf.get("prefs");
console.log(prefs.facts());

getOrCreate

getOrCreate(name: string): Nugget
Returns the nugget with the given name if it already exists, or creates a new one with default options.
name
string
required
Name of the nugget to retrieve or create.
const locations = shelf.getOrCreate("locations");
locations.remember("shared:auth-handler", "src/auth/middleware.ts:47");

has

has(name: string): boolean
Returns true if a nugget with the given name is registered on the shelf.
if (!shelf.has("debug")) {
  shelf.create("debug");
}

remove

remove(name: string): void
Unregisters a nugget, deletes its .nugget.json file, and removes all of its graph notes. Throws if the nugget does not exist.
remove() permanently deletes the nugget file and all associated notes. This cannot be undone.
name
string
required
Name of the nugget to remove.
shelf.remove("debug");

list

list(): Array<ReturnType<Nugget["status"]>>
Returns the status() object for every registered nugget.
for (const info of shelf.list()) {
  console.log(`${info.name}: ${info.fact_count} facts, ${info.note_count} notes`);
}

loadAll

loadAll(): void
Scans saveDir for *.nugget.json files and loads each one into the shelf. Files that cannot be parsed are silently skipped. Call this once at startup to restore a previous session.
const shelf = new NuggetShelf();
shelf.loadAll();
console.log(shelf.size); // number of nuggets restored

saveAll

saveAll(): void
Calls save() on every registered nugget. Useful when autoSave is disabled and you want a single explicit flush.
const shelf = new NuggetShelf({ autoSave: false });
// ... batch operations ...
shelf.saveAll();

Fact methods

remember

remember(
  nuggetName: string,
  key: string,
  value: string,
  noteMeta?: GraphNoteMetaInput,
): void
Stores or updates a fact in the named nugget, creating the nugget first if it does not exist.
nuggetName
string
required
Target nugget name.
key
string
required
Fact key.
value
string
required
Fact value.
noteMeta
GraphNoteMetaInput
Optional metadata for the mirrored graph note.
shelf.remember("project", "shared:test-cmd", "pnpm test");

recall

recall(
  query: string,
  nuggetName?: string,
  sessionId?: string,
): ReturnType<Nugget["recall"]> & { nugget_name: string | null }
Searches for a fact matching the query. When nuggetName is provided, the search is scoped to that nugget. Otherwise, every nugget is queried and the result with the highest confidence is returned.
query
string
required
Query string passed to each nugget’s recall.
nuggetName
string
Restrict the search to this nugget. Throws if the nugget does not exist.
sessionId
string
default:"\"\""
Session identifier for hit tracking.
Returns the standard recall result plus:
nugget_name
string | null
Name of the nugget that produced the winning result, or null if nothing was found.
// Search all nuggets
const result = shelf.recall("test command");
console.log(result.answer, result.nugget_name);

// Search one nugget
const result2 = shelf.recall("test-cmd", "project");

forget

forget(nuggetName: string, key: string): boolean
Removes a fact from the named nugget. Throws if the nugget does not exist.
nuggetName
string
required
Target nugget name.
key
string
required
Key to remove.
Returns true if the fact was removed, false if not found.
shelf.forget("project", "shared:test-cmd");

Note methods

createNote

createNote(
  nuggetName: string,
  title: string,
  content: string,
  tags?: string[],
  meta?: GraphNoteMetaInput,
): MemoryNote
Creates a note in the named nugget, creating the nugget first if it does not exist.
shelf.createNote("project", "Deploy checklist", "Run pnpm build, then push.", ["deploy"]);

editNote

editNote(
  nuggetName: string,
  noteId: string,
  newContent: string,
  updates?: {
    tags?: string[];
    title?: string;
    hidden?: boolean;
    rewrittenAt?: string;
    noteMeta?: GraphNoteMetaInput;
  },
): MemoryNote | null
Edits a note in the named nugget. Delegates to Nugget.editNote.
shelf.editNote("project", "note-project-a1b2c3d4", "Updated deploy steps.");

addLink(
  nuggetName: string,
  note1: string,
  note2: string,
  reason: string,
): boolean
Adds a bidirectional link between two notes in the named nugget.
shelf.addLink("project", "Deploy checklist", "CORS fix", "both affect production");

searchNotes

searchNotes(
  query: string,
  nuggetName?: string,
  limit?: number,
  opts?: NoteFilterOptions,
): Array<SearchNotesResult & { nugget_name: string }>
Searches notes across all nuggets (or a single named nugget). Results from all nuggets are merged and re-ranked by score before the limit is applied.
query
string
required
Free-text search query.
nuggetName
string
Restrict the search to this nugget.
limit
number
default:"5"
Maximum number of results.
opts
NoteFilterOptions
Optional filters.
Returns an array of SearchNotesResult items each augmented with nugget_name: string.
const results = shelf.searchNotes("CORS");
for (const { note, score, nugget_name } of results) {
  console.log(`[${nugget_name}] ${note.title} (${score.toFixed(3)})`);
}

listNotes

listNotes(
  nuggetName?: string,
  opts?: NoteFilterOptions,
): Array<MemoryNote & { nugget_name: string }>
Lists notes across all nuggets (or a single named nugget). Each item includes a nugget_name field.
// All notes on the shelf
const all = shelf.listNotes();

// Notes from a specific nugget
const projectNotes = shelf.listNotes("project");

reflectAndCleanMemory

reflectAndCleanMemory(
  nuggetName?: string,
  limit?: number,
): ReflectionResult
Runs a synchronous reflection pass on the shelf. Stale notes are rewritten, near-duplicates are merged, tags are improved, and low-value notes are archived. See reflectAndCleanMemory for full details.
nuggetName
string
Restrict the pass to this nugget. Omit to process all nuggets.
limit
number
default:"10"
Maximum number of notes to inspect. Capped at 10.
Returns a ReflectionResult.
const result = shelf.reflectAndCleanMemory();
console.log(`Inspected ${result.inspected}, merged ${result.merged}, tagged ${result.tagged}`);

Build docs developers (and LLMs) love