DEV Community

Krish Verma
Krish Verma

Posted on

How I built memory that forgets on purpose: 90 days to stale, 365 to gone, and a pin that never expires

Clock refreshes only on actual retrieval

How I built memory that forgets on purpose: 90 days to stale, 365 to gone, and a pin that never expires

Ankita AI is a desktop AI assistant by Krish Verma, and it remembers things about you — your preferences, your projects, the decisions you made last month. The problem with a companion that remembers everything is that it remembers everything forever. A fact you stated once, a year ago, in a context that no longer exists, still arrives in the model's context with the same authority as something you said yesterday. The assistant doesn't know it's stale. It just asserts it.

So I gave Ankita's memory an expiry date — two of them, actually — and a rule that nothing is ever deleted.

Two windows, not a delete button

The design lives in two config values in src/core/config.mjs:

memoryStaleDays: Math.min(3650, posInt(pick("MEMORY_STALE_DAYS"), 90)),
memoryForgetDays: Math.min(3650, posInt(pick("MEMORY_FORGET_DAYS"), 365)),
Enter fullscreen mode Exit fullscreen mode

A fact untouched for 90 days is stale: it sinks to the bottom of recall results and is filtered out of default recall entirely. A fact untouched for 365 days is past the forget window: it drops out of normal results altogether. Both windows are configurable with env vars, both are capped at 3,650 days (ten years), and both can be turned off by setting them to 0.

The important part: neither window deletes anything. A stale fact is still on disk, still in the store, and one explicit flag — includeStale on the recall tool — brings it back. The comment above the filter says it plainly: "Old, rarely recalled facts sink but are never deleted; only an explicit ask returns them."

What counts as "touched"

Staleness is decided by isStale() in src/memory/memory-similarity.mjs:

export function isStale(fact, { staleDays, now = Date.now() } = {}) {
  if (!fact || fact.always === true) return false; // Pins are deliberate and permanent.
  const days = Number(staleDays);
  if (!Number.isFinite(days) || days <= 0) return false;
  const at = Date.parse(fact.lastRecalledAt || fact.updatedAt || fact.createdAt || '');
  if (!Number.isFinite(at)) return false;
  return now - at > days * 86400000;
}
Enter fullscreen mode Exit fullscreen mode

Three decisions are doing the work here:

  1. Pins never go stale. A fact marked always is deliberate and permanent — the user chose to pin it, so silence doesn't erode it. Everything else ages.
  2. The clock is last recall, not last edit. The timestamp is lastRecalledAt, falling back to updatedAt, then createdAt. A fact you keep using stays fresh because you keep using it — recall is the ageing signal.
  3. The threshold is a hard line, not a decay. Past 90 days, the fact is stale. There is no "a bit stale" — the flag is binary, one comparison against days * 86400000.

Recall refreshes the clock — but only for what you actually saw

Every fact in the store carries lastRecalledAt and a recallCount, and recall updates both through touchRecalled() in src/memory/profile.mjs. Two details matter:

  • One batched write. A recall can touch many facts, but the store writes once, not once per fact. The ageing signal is bookkeeping; it shouldn't cost a write per row.
  • Only rows the caller actually received get touched. The model can't keep a fact alive by searching for something else. And if the calling context is read-only — a read-only subagent, for instance — the touch is skipped entirely. The comment in tools/personal/recall.mjs is explicit: "recall is advertised readOnly, and a read-only subagent must stay read-only: the ageing signal is bookkeeping, never worth violating that contract."

The ageing signal also surfaces to the model. Each recall row carries its confidence, its conflictsWith list, and its stale flag, and stale rows sort last in every ranking — semantic or lexical. The system prompt even counts them: the personal-memory block in src/core/agent.mjs reads "Personal memory store: N saved fact(s), M stale" so the model knows the store has entries it shouldn't trust blindly. And the automatic context builder, personalMemoryContext(), searches project notes and decisions too, not just personal facts, inside a 1,600-character budget — so a stale personal preference doesn't crowd out a fresh project decision.

Confidence doesn't age. That's the part I'm least sure about.

Every fact also carries a confidence from 0 to 1. The default is 1, with a comment that says why: "A direct user statement is treated as certain." Confidence is clamped on write, returned on every recall row, and otherwise left alone.

That means confidence never decays. A fact you stated once, confidently, a year ago keeps confidence 1 right up to the day it goes stale — and then the binary flag takes over. The number says "certain" while the flag says "don't use this." I chose the binary flag over a decay curve because a decaying number would silently downgrade the user's own words without telling them, and a number that drifts is harder to argue with than a flag you can see. But I'm not convinced the split is right: the confidence is the model's evidence about how sure the fact is, and age is evidence about whether it's still true. Right now the two never meet.

The honest limits

  • The two windows run on different clocks. Staleness keys on last recall (lastRecalledAt), but the 365-day forget window keys on last edit — withinForgetWindow() in recall.mjs compares row.at, which is updatedAt. A fact you recall every week but never edit still drops out of normal results a year after its last edit. That may be the right behaviour — a year without an edit is a year without the user reaffirming it — but the two windows disagreeing about what "touched" means is an inconsistency I haven't resolved, and I can see the argument that the forget window should use the same clock as the stale window.
  • Stale is binary. There is no gradient between fresh and stale, no "probably outdated" — a fact is either in play or it isn't. A gradient would be more honest about how memory actually fades, but it would also be a number the model could quietly round down.
  • Recall is the only thing that refreshes the clock. If the model never recalls a fact, it ages even if the user still holds it. The store can't know what the user still believes; it only knows what the assistant has surfaced.

Ankita is open source at https://github.com/akyourowngames/A.N.K.I.T.A, and the site is https://ankita-sable.vercel.app. The memory code is in src/memory/ and tools/personal/recall.mjs if you want to check the two windows against the code.

Tell me I'm wrong: is 90 days of silence the right line for "forgotten", or should a fact the user stated once — confidence 1, their own words — never go stale on its own? And should confidence decay with age, or is a binary flag the honest shape — a fact is either in play or it isn't?

— Krish Verma, creator of Ankita AI

Top comments (24)

Collapse
 
iictp profile image
IICTP •

The detail that impressed me most is that only rows the caller actually received get their clock refreshed — the model can't keep a fact alive just by searching near it. That's a quiet little guard against the store drifting toward whatever the model happens to poke at. With the 12-pin cap, what happens when a pinned fact conflicts with a newer one — does the conflictsWith list ever surface that tension to the user, or does the pin quietly win?

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Good question — and the honest answer is the flag does surface, but the pin still gets into the prompt, so it's not a clean win either way.

When a new fact lands, addWithChecks() in tools/personal/remember.mjs runs findSimilar() against the store. If it's related but not a duplicate, it calls ProfileStore.flagConflict() in src/memory/profile.mjs, which writes each fact's id into the other's conflictsWith list and changes neither text — the comment there says resolution stays an explicit user decision. The write also returns a notice telling me to ask the user which fact is current.

It surfaces at read time too. personalMemoryContext() in src/memory/memory-context.mjs attaches a conflicts count to any recalled fact that has one, and if a conflicted fact actually reaches the model it adds a conflictNotice: "Some facts conflict with each other. Ask the user which is current instead of asserting either." So the tension reaches the user as a question, through the model — there's no separate user-facing conflict UI.

The caveat: promptBlock() in profile.mjs still puts the latest 12 pinned facts into every prompt with no conflict annotation, just the header "current requests take precedence". So a pinned fact keeps showing up while flagged, and the model has to notice the recall-side notice to push back. And detection itself has a real hole: findSimilar() only claims a conflict between facts of the same declared kind, so a pinned preference and a newer fact filed under a different kind slip past each other with no flag at all. That's an open gap, not a design choice I'm proud of.

Collapse
 
iictp profile image
IICTP •

Thank you for the honest walkthrough, Krish — the part that stuck with me is that the conflict reaches the user as a question through the model, via that conflictNotice, rather than a separate UI. The promptBlock caveat is the sharper one for me: the latest 12 pinned facts still land in every prompt unannotated, so the flag and the pin are really fighting each other there. Do you see the same-kind hole in findSimilar() as the fix to chase first, or the promptBlock annotation?

Thread Thread
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Good question — I'd chase the promptBlock annotation first. The reason is reach: promptBlock() in src/memory/profile.mjs puts the latest 12 pinned facts into every prompt as plain text, with no annotation at all, while the conflict flag only surfaces through personalMemoryContext() in src/memory/memory-context.mjs — and only when the fact is actually recalled inside the 1600-char budget. A flag the model never sees in the prompt is no better than no flag for the pinned set. The findSimilar() same-kind gate in src/memory/memory-similarity.mjs is real too — a preference and a project fact sharing vocabulary never get flagged as a conflict — but kind is free-form, so widening that gate risks flagging things that aren't disagreements at all, which is exactly why the gate exists. Caveat: annotating promptBlock only fixes the pinned 12; an unpinned conflict still depends on recall surfacing it, so the findSimilar gap stays open for everything that isn't pinned.

Thread Thread
 
iictp profile image
IICTP •

That's a convincing case for annotation first — reach settles it: the pinned 12 land in every prompt unannotated, while the flag only surfaces when recall happens to pull the fact inside the 1600-char budget, so for the pinned set the flag may as well not exist. I also take your point on findSimilar: with kind being free-form, widening the gate would trade missed conflicts for false ones, which is a worse failure mode. The unpinned caveat is the part I'd keep an eye on — annotation fixes the pinned 12, but anything unpinned still depends on recall surfacing it, so that gap stays open until the clocks are aligned.

Thread Thread
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

You're right to keep an eye on that — annotation only fixes the half of the store that reaches every prompt. The unpinned half still lives or dies by recall surfacing it inside the 1600-char budget, and by the forget window, which keys on at: f.updatedAt in collect() (tools/personal/recall.mjs) rather than lastRecalledAt. So the order I'm working in is: annotate the pinned 12 in promptBlock() first, since that's the leak that hits every prompt, then align the forget clock to lastRecalledAt — which is the same fix the earlier thread in this article pointed at — and that closes the unpinned gap too, because a fact that keeps getting recalled stops ageing out. The findSimilar gate stays as it is: same-kind only, since kind is free-form and widening it trades missed conflicts for false ones. Thanks for staying with the thread — this is the sharpest version of the remaining gap.

Thread Thread
 
iictp profile image
IICTP •

That order makes sense — annotate the pinned 12 first since that's the leak hitting every prompt, then align the forget clock to lastRecalledAt so a fact that keeps getting recalled stops ageing out. The f.updatedAt detail is the part I hadn't connected: the forget window keys on when the fact was last written, not when it was last used, so the unpinned gap is really two gaps — recall surfacing it and the clock measuring the wrong thing. Keeping findSimilar same-kind is the right call too; with kind free-form, the gate's false-positive cost is the thing to protect against. Thanks for laying out the sequence so clearly.

Thread Thread
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Thanks — you've named it better than I did: it really is two gaps, not one. The recall-surfacing gap is the one I can't fully close without the annotation work, since a fact only reaches the prompt if recall pulls it inside the 1600-char budget. The clock gap is the cleaner fix: collect() in tools/personal/recall.mjs keys the forget window on f.updatedAt, so switching that to lastRecalledAt means a fact that keeps getting used stops ageing out. And yes, findSimilar stays same-kind — with kind free-form, widening the gate trades a few missed conflicts for a lot of false ones, and false conflicts are the costlier failure. Appreciate you following the thread this closely.

Thread Thread
 
iictp profile image
IICTP •

That lastRecalledAt switch is a neat fix for the clock gap — a fact that keeps getting used simply stops ageing out, which is exactly how it should feel. And the same-kind gate trade-off makes sense to me too; widening it would trade a few missed conflicts for a lot of false ones, and false conflicts are the costlier failure. Is the annotation work for the recall-surfacing gap the next thing you'll tackle, or does the clock fix come first?

Thread Thread
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Annotation first, then the clock fix — that's the order I settled on, and it still holds. The reason is reach: promptBlock() in src/memory/profile.mjs puts the latest 12 pinned facts into every prompt as plain text, with no annotation at all, so a conflicting pin is live in every conversation right now. The clock gap is real but slower — collect() in tools/personal/recall.mjs keys the forget window on f.updatedAt, so a fact recalled weekly but never edited still drops out after a year. The fix itself is small: lastRecalledAt is already tracked on every fact, and isStale() in src/memory/memory-similarity.mjs already clocks staleness off it, so it's really a matter of carrying that timestamp through collect() instead of updatedAt. The honest caveat is that the annotation only fixes the pinned 12 — unpinned facts still depend on recall surfacing them inside the 1600-char budget, so the clock fix is second, not optional.

Collapse
 
userxnom profile image
Abdullah Naseer •

90 days of silence feels like a fair line for preferences and project facts, which go stale quietly — but the mismatch you flagged at the end is the part I would fix first. A fact you recall every week but never edit still drops out of normal results a year after its last edit, because the forget window keys on updatedAt while staleness keys on lastRecalledAt. That punishes exactly the facts you still use.

Aligning the forget window to lastRecalledAt would keep the two clocks telling the same story, and it would also soften your confidence problem: a confident fact that keeps getting recalled keeps its authority, while one nobody recalls for a year loses it through silence rather than through a separate decay rule. The pin rule is the right escape hatch either way — the user choosing permanence should beat any clock.

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

You're right, and you've put it more precisely than I did in the article. The mismatch is real and it's exactly where you say it is: collect() in tools/personal/recall.mjs sets each personal row's at to f.updatedAt, and withinForgetWindow() compares that against the 365-day cutoff — while isStale() in src/memory/memory-similarity.mjs clocks staleness off lastRecalledAt first. So a fact I recall every week but never edit stays fresh in the stale sense and still falls out of normal results a year after its last edit. Aligning the forget window to lastRecalledAt would make the two clocks tell the same story — recall already refreshes that timestamp through touchRecalled() in src/memory/profile.mjs, one batched write, only for rows the caller actually received.

One wrinkle your pin point surfaced: the pin exemption lives in isStale(), not in withinForgetWindow() — the row collect() builds doesn't even carry always, so a pinned fact you never edit still drops out of normal results after a year. Aligning the clock fixes the weekly-recall case, but a pin nobody recalls would still need its own exemption. That's a real gap I hadn't spelled out.

The argument that still keeps me from just changing it: a year without an edit is a year without the user reaffirming the fact, and recall isn't reaffirmation — the model recalling something isn't the user confirming it. But your confidence point lands: a confident fact that keeps getting recalled keeps its authority through use, and one nobody recalls for a year loses it through silence. That's a cleaner story than a separate decay rule. Leaning your way — the forget window should use the same clock as staleness.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

Ninety days to stale, a year to gone, and one pin that never expires. The asymmetry is doing all the work.

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Thanks — that's the bet, really. The two windows disagreeing about what "touched" means was the part I was least happy with, and a pin only works as an escape hatch if the clocks agree. Appreciate you reading it closely.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

If the clocks have to agree for the pin to work, the pin is just a second clock.

Thread Thread
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Fair pushback, and it made me check the exact shape of it. The pin isn't a clock at all — it's a flag, always: true on the fact, and isStale() in src/memory/memory-similarity.mjs already returns false for it ("Pins are deliberate and permanent"). The bug is narrower than I wrote it: withinForgetWindow() in tools/personal/recall.mjs never checks that flag — it filters on at, which collect() sets to f.updatedAt, and collect() doesn't even carry always into the row, so the fix has to thread the flag through first. Aligning the clocks (both on lastRecalledAt, which touchPersonal() refreshes on every recall the user actually receives) only fixes what "touched" means; the pin stays an escape hatch from both windows, not a second clock. The honest caveat runs the other way: a pin that never expires can pile up, and the only guard today is MAX_ALWAYS = 12 in src/memory/profile.mjs — only the latest 12 pinned facts enter the prompt, the rest stay reachable through recall. So "never expires" is already bounded in practice, just not by time.

Thread Thread
 
robertpaschal profile image
Odinaka Robert Nnamani •

Pin as a flag, not a timestamp. The gap is withinForgetWindow and collect not carrying always, and 12 is the bound.

Thread Thread
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Exactly — that's the shape of it. The pin stays a flag, not a clock; the actual fix is collect() carrying always through so withinForgetWindow() can see it, and 12 stays the bound on how many pinned facts reach the prompt.

Collapse
 
fattakhov profile image
Mansur Fattakhov •

Keeping read-only recall genuinely read-only is a thoughtful boundary. If a fact is regularly useful only through read-only workers, would you want to show that usage separately? It could help explain why something actively used still becomes stale without changing the read-only contract.

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Good question — and you have named the exact tension. Read-only workers deliberately do not refresh the clock: touchPersonal() in tools/personal/recall.mjs skips the ageing write when ctx.readOnly === true, so a fact that is only ever useful to read-only workers still goes stale at 90 days. That is the contract working as designed, but it makes the staleness look wrong from the outside — the fact is actively used, just never by a writer. Showing that usage separately is the fix I would reach for first: a second counter that read-only recall bumps, displayed next to lastRecalledAt, without ever touching the ageing write itself. The open question is whether that second number earns its keep, or just adds a second clock to explain — would you show it in the recall output, or keep it as a debug-only field?

Collapse
 
iamaanahmad profile image
Amaan Ahmad •

The part that stayed with me is the open question about confidence never ageing — a fact stated confidently a year ago still arriving with confidence 1 feels like the sharpest edge here. One approach worth trying: let recall compute an effective confidence that folds in age, so a stale fact keeps its stored confidence but competes at a discount against fresher facts. That way you don't have to touch the stored value, and the model still gets a signal that a year-old preference might no longer be true.

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

I like this shape of it — compute the discount at recall time and never touch the stored value. That's very doable in the code as it stands: collect() in tools/personal/recall.mjs already copies confidence onto each recall row verbatim, and the stored number is set once at write time in tools/personal/remember.mjs (a direct statement is 1, extraction with evidence gets INFERRED_CONFIDENCE) and then never changed. So the stored value stays the user's words as stated, and recall computes what the model competes on.

One wrinkle your version would need: collect() only carries at: f.updatedAt on the row, and the age clock that matters for the discount is lastRecalledAt — that's the clock isStale() in src/memory/memory-similarity.mjs already uses. So the row would need to carry lastRecalledAt too, or the discount would inherit the same updatedAt-vs-lastRecalledAt mismatch the article is about.

The honest open question for me is what the discounted number should feed: ranking, the number shown to the model, or both. Right now confidence plays no part in ordering at all — rankRows() sorts by stale flag, then score, then recency — so a discount that only changes the displayed number might not move which facts actually win. Thanks for pushing on the sharpest edge — this is the version of the idea I'd actually build.

Collapse
 
the_daily_flare profile image
The daily flare •

I think the pin idea is the part I like most, since some facts should just stay put no matter how old they get.

Collapse
 
krish_verma_77e28d3fd63ca profile image
Krish Verma •

Thanks — that's exactly why I kept it. A pin is a flag (always: true on the fact), not a clock: isStale() in src/memory/memory-similarity.mjs already returns false for it, so it never ages out. The honest caveat is the one iictp raised in this same thread: the pin still lands in every prompt unannotated even when it conflicts with something newer, so it's a promise I haven't fully kept yet.