replaceMemoryEntitiesGuardedOp
replaceMemoryEntitiesGuardedOp(
ctx:EntityOperationsContext,memoryId:string,entityInputs: readonlyEntityInput[]):Promise<StoredEntity[] |null>
Defined in: src/lib/db/entities/operations.ts:423
REPLACE a memory’s entity links with an auto-derived set — the topic worker’s write primitive. Unlike setMemoryEntitiesOp it does NOT mark the memory user-managed (the pass is automatic), and unlike linkMemoryEntitiesOp it removes stale links, so re-extracting an edited memory drops entities its previous content mentioned (“works at Acme” → “works at Globex” must unlink Acme). Insert-missing and destroy-stale are batched in ONE writer, after the same in-write guard as the link op (user-managed / deleted / absent / read-fault ⇒ skip).
That batch also prunes entity rows left with no links at all (see
findOrphanedEntities) — otherwise a topic the extractor has disowned
keeps rendering as a chip that matches no memory.
Returns the linked entities ([] for an answered-empty set), or null when
the guard skipped — callers must treat null as “not persisted” (e.g. don’t
stamp topics_extracted_at).
Parameters
| Parameter | Type |
|---|---|
|
| |
|
|
|
|
|
readonly |
Returns
Promise<StoredEntity[] | null>