WOLBΛRG

linkMemories()

Create a directed relation between two memories in the optional graph layer.

Signature

linkMemories(
  fromId: string,
  toId: string,
  relation: string,
  metadata?: Record<string, unknown>,
): Promise<void>

Requires a configured graph provider. Without it: ProviderNotConfiguredError.

What it does

Creates (or ensures) a directed edge fromId --[relation]→ toId in the graph. Missing memory nodes are created as stubs; content is re-hydrated from storage on getRelated / recall({ includeGraph }).

Works the same on SQLite and Neo4j — see Portability.

Example

const preference = await ctx.remember({
  agent: "support",
  content: { text: "User prefers dark mode." },
});
const policy = await ctx.remember({
  agent: "support",
  content: { text: "UI theme is user-configurable." },
});

await ctx.linkMemories(
  preference.id,
  policy.id,
  "supported_by",
  { source: "onboarding" },
);

Relation names

Use stable, lowercase snake_case strings (related_to, depends_on, cites). Filter later with getRelated({ relation }).