Add freshness scoring, auto-decay, and USAGE.md

Add lastAccessedAt timestamp to nodes with schema migration and
backfill. Touch timestamp on read, apply exponential freshness decay
(~69-day half-life) to search scoring alongside BM25 and vector
weights. Add auto-decay that marks untouched nodes as stale after a
configurable threshold, with CLI command and server-side daily interval.
Include comprehensive USAGE.md documenting all CLI commands and REST API.
This commit is contained in:
2026-02-02 22:07:06 +01:00
parent d1e3adcb3c
commit f1b59a2d1a
12 changed files with 290 additions and 7 deletions

View File

@@ -16,6 +16,7 @@ function rowToNode(row: any): Node {
embedding: row.embedding ? deserializeEmbedding(row.embedding) : null,
createdAt: row.created_at,
updatedAt: row.updated_at,
lastAccessedAt: row.last_accessed_at ?? row.updated_at,
isStale: !!row.is_stale,
};
}
@@ -36,13 +37,13 @@ export async function addNode(input: AddNodeInput): Promise<Node> {
const embedding = await getEmbedding(`${input.title} ${content}`);
db.prepare(`
INSERT INTO nodes (id, kind, title, content, status, tags, metadata, embedding, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO nodes (id, kind, title, content, status, tags, metadata, embedding, created_at, updated_at, last_accessed_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`).run(
id, input.kind, input.title, content, input.status ?? null,
JSON.stringify(tags), JSON.stringify(metadata),
embedding ? serializeEmbedding(embedding) : null,
now, now
now, now, now
);
// Insert tags
@@ -53,14 +54,16 @@ export async function addNode(input: AddNodeInput): Promise<Node> {
return {
id, kind: input.kind, title: input.title, content, status: input.status,
tags, metadata, embedding, createdAt: now, updatedAt: now, isStale: false,
tags, metadata, embedding, createdAt: now, updatedAt: now, lastAccessedAt: now, isStale: false,
};
}
export function getNode(id: string): Node | null {
const db = getDb();
const row = db.prepare('SELECT * FROM nodes WHERE id = ?').get(id) as any;
return row ? rowToNode(row) : null;
if (!row) return null;
db.prepare('UPDATE nodes SET last_accessed_at = ? WHERE id = ?').run(Date.now(), id);
return rowToNode(row);
}
export function findNodeByPrefix(prefix: string): Node | null {