linkMemoryEntitiesOp()
linkMemoryEntitiesOp(
ctx:EntityOperationsContext,memoryId:string,entityInputs: readonlyEntityInput[],options?:object):Promise<StoredEntity[]>
Defined in: src/lib/db/entities/operations.ts:312
Link a memory to one or more entities. Accepts bare names (back-compat)
or { name, kind } objects. Names are normalized; missing entities are
auto-created (with their kind), and an existing entity’s null kind is
back-filled — see upsertEntitiesInWrite. Idempotent — duplicate
(memory_id, entity_id) pairs are skipped.
options.unlessTopicsUserManaged re-checks the memory’s vault row INSIDE
the serialized writer and skips link creation when the row is user-managed
(topics_user_managed), soft-deleted, or absent. Auto paths (extraction,
topic worker) need this: a pre-call check races the LLM round-trip —
setMemoryEntitiesOp sets the flag in its own writer and a delete can land
mid-call (orphaning links the cascade already swept) — so only an in-write
check guarantees a user’s manual edit or delete can’t be grafted over. The
row read fails CLOSED (skip links) so a transient fault never attaches
topics to a memory we couldn’t verify. Entity upserts and link creation
run in ONE writer to prevent orphan-prune races; returns [] when links
were skipped.
options.topicsSource (default auto) is the provenance recorded in
memory_vault.topics, which this rewrites from the memory’s FULL resulting
link set — see prepareTopicsUpdate. Add semantics mean that set is
old ∪ new, so already-linked entities are resolved for their names too.
Parameters
| Parameter | Type |
|---|---|
|
| |
|
|
|
|
|
readonly |
|
|
|
|
| |
|
|
|
Returns
Promise<StoredEntity[]>
Deprecated
App code: use MemoryStore.addTopics (createLocalMemoryStore).