Skip to content

Commit ebf07e5

Browse files
fix(memory): apply temporal decay to dated files in memory subdirectories (#121103)
* fix(memory): apply temporal decay to dated files in memory subdirectories DATED_MEMORY_PATH_RE only matched memory/YYYY-MM-DD.md at the root, so dated files in subdirectories (e.g. dreaming phase reports at memory/dreaming/light/2026-05-14.md) were classified as evergreen and kept full ranking weight forever even with temporalDecay enabled. Accept a date-only Markdown basename at any depth below memory/, matching the nested-path shape short-term promotion already recognizes. MEMORY.md, USER.md, and undated files remain evergreen; non-memory sources keep the mtime fallback. Fixes #121046 * refactor(memory): trim issue-specific commentary from dated-path matcher * fix(memory): decay nested and slugged dated memory files Co-authored-by: wangmiao0668000666 <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 0528f44 commit ebf07e5

3 files changed

Lines changed: 85 additions & 3 deletions

File tree

‎docs/concepts/memory-search.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ Two deterministic ranking passes are enabled by default for hybrid search.
145145

146146
Old notes gradually lose ranking weight so recent information surfaces first.
147147
With the default 30-day half-life, a note from last month scores at 50% of its
148-
original weight. `MEMORY.md` and other non-dated files under `memory/` are
149-
evergreen and never decayed; only dated `memory/YYYY-MM-DD.md` files decay.
148+
original weight. `MEMORY.md`, `USER.md`, and undated files under `memory/`
149+
remain evergreen. Dated `YYYY-MM-DD.md` and `YYYY-MM-DD-<slug>.md` files decay
150+
at any depth, including session-memory notes and nested dreaming reports.
150151

151152
### MMR (diversity)
152153

‎extensions/memory-core/src/memory/temporal-decay.test.ts‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,87 @@ describe("temporal decay", () => {
9494
expect(merged[0]?.score ?? 0).toBeGreaterThan(merged[1]?.score ?? 0);
9595
});
9696

97+
it("decays dated and slugged memory files at any depth by their embedded date", async () => {
98+
const merged = await mergeVectorResultsWithTemporalDecay([
99+
createVectorMemoryEntry({
100+
id: "nested-old",
101+
path: "memory/dreaming/light/2025-01-01.md",
102+
snippet: "stale dreaming report",
103+
vectorScore: 0.95,
104+
}),
105+
createVectorMemoryEntry({
106+
id: "root-old",
107+
path: "memory/2025-01-01.md",
108+
snippet: "stale daily note",
109+
vectorScore: 0.95,
110+
}),
111+
createVectorMemoryEntry({
112+
id: "root-timestamp",
113+
path: "memory/2025-01-01-1430.md",
114+
snippet: "stale session memory",
115+
vectorScore: 0.95,
116+
}),
117+
createVectorMemoryEntry({
118+
id: "root-collision",
119+
path: "memory/2025-01-01-1430-2.md",
120+
snippet: "stale colliding session memory",
121+
vectorScore: 0.95,
122+
}),
123+
createVectorMemoryEntry({
124+
id: "nested-slug",
125+
path: "memory/dreaming/light/2025-01-01-vendor-pitch.md",
126+
snippet: "stale named dreaming report",
127+
vectorScore: 0.95,
128+
}),
129+
createVectorMemoryEntry({
130+
id: "nested-undated",
131+
path: "memory/dreaming/light/report.md",
132+
snippet: "undated evergreen",
133+
vectorScore: 0.7,
134+
}),
135+
]);
136+
137+
const byPath = new Map(merged.map((entry) => [entry.path, entry]));
138+
const nestedOld = byPath.get("memory/dreaming/light/2025-01-01.md");
139+
const rootOld = byPath.get("memory/2025-01-01.md");
140+
expect(nestedOld?.score).toBeCloseTo(rootOld?.score ?? 0);
141+
expect(nestedOld?.score ?? 1).toBeLessThan(0.5);
142+
expect(byPath.get("memory/2025-01-01-1430.md")?.score).toBeCloseTo(rootOld?.score ?? 0);
143+
expect(byPath.get("memory/2025-01-01-1430-2.md")?.score).toBeCloseTo(rootOld?.score ?? 0);
144+
expect(byPath.get("memory/dreaming/light/2025-01-01-vendor-pitch.md")?.score).toBeCloseTo(
145+
rootOld?.score ?? 0,
146+
);
147+
expect(byPath.get("memory/dreaming/light/report.md")?.score).toBeCloseTo(0.7);
148+
});
149+
150+
it("decays nested dated and slugged memory files with Windows-style separators", async () => {
151+
const merged = await mergeVectorResultsWithTemporalDecay([
152+
createVectorMemoryEntry({
153+
id: "win-nested-old",
154+
path: "memory\\dreaming\\light\\2025-01-01.md",
155+
snippet: "stale dreaming report",
156+
vectorScore: 0.95,
157+
}),
158+
createVectorMemoryEntry({
159+
id: "win-nested-slug",
160+
path: "memory\\dreaming\\light\\2025-01-01-1430.md",
161+
snippet: "stale session memory",
162+
vectorScore: 0.95,
163+
}),
164+
createVectorMemoryEntry({
165+
id: "win-nested-undated",
166+
path: "memory\\dreaming\\light\\report.md",
167+
snippet: "undated evergreen",
168+
vectorScore: 0.7,
169+
}),
170+
]);
171+
172+
const byPath = new Map(merged.map((entry) => [entry.path, entry]));
173+
expect(byPath.get("memory\\dreaming\\light\\2025-01-01.md")?.score ?? 1).toBeLessThan(0.5);
174+
expect(byPath.get("memory\\dreaming\\light\\2025-01-01-1430.md")?.score ?? 1).toBeLessThan(0.5);
175+
expect(byPath.get("memory\\dreaming\\light\\report.md")?.score).toBeCloseTo(0.7);
176+
});
177+
97178
it("handles future dates, zero age, and very old memories", async () => {
98179
const merged = await mergeVectorResultsWithTemporalDecay([
99180
createVectorMemoryEntry({

‎extensions/memory-core/src/memory/temporal-decay.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const DEFAULT_TEMPORAL_DECAY_CONFIG: TemporalDecayConfig = {
1313
};
1414

1515
const DAY_MS = 24 * 60 * 60 * 1000;
16-
const DATED_MEMORY_PATH_RE = /(?:^|\/)memory\/(\d{4})-(\d{2})-(\d{2})\.md$/;
16+
const DATED_MEMORY_PATH_RE = /(?:^|\/)memory\/(?:[^/]+\/)*(\d{4})-(\d{2})-(\d{2})(?:-[^/]+)?\.md$/;
1717

1818
function toDecayLambda(halfLifeDays: number): number {
1919
if (!Number.isFinite(halfLifeDays) || halfLifeDays <= 0) {

0 commit comments

Comments
 (0)