Skip to main content

Function: sweepRetention()

sweepRetention(options): Promise<{ pages: number; scopes: number; traces: number; }>

Defined in: packages/agentos/src/cognition/memory/io/retentionSweep.ts:62

Deletes for good what expired, one user or session scope at a time: each page compiled from an expired trace, whole, then the scope's traces stored longer ago than its period (soft-deleted rows and the document chunks they were filed from included). The pages go first: while a page is left, the expired traces it was built from are left too, so a sweep that stopped is finished by the next one. With pages: 'rebuild' the next compile builds such a page again from the traces of it that are left. A page whose sources all survive is not touched, and a page's own age is no second clock. A scope left with no trace and no page loses its registry row. The operator's pages and memory from before per-user scope are never swept.

Then the vector index is written again and the store's write-ahead log emptied, for this sweep's deletes and for any an earlier sweep or deletion could not finish (Memory.finishErasure), also when a scope failed. One memory.retention_swept line counts what went, for a sweep in which at least one scope had a period.

Parameters​

options​

RetentionSweepOptions

Returns​

Promise<{ pages: number; scopes: number; traces: number; }>

How many traces and pages it deleted, and how many scopes it removed from the registry.

Throws​

The first error a scope, the index or the log threw, once every scope, the index and the log were tried; what the sweep did in the other scopes stands, and the next sweep finishes the scope that failed.