Skip to documentation
Docs navigation
Docs/graftByRelevance()
MemoGrafterAgent

graftByRelevance()

Select topics semantically and assemble a graft prompt.

What it does

Select topics semantically and assemble a graft prompt.

When to use it

Use when broader topic context is needed but the caller does not know topic IDs.

Signature

TypeScript
graftByRelevance(query: string, options?: GraftByRelevanceOptions): Promise<InjectionResult>

Parameters

query (string) — Natural-language intent used to rank relevant memory.
options? (GraftByRelevanceOptions) — A typed options object. The applicable fields and defaults are documented below.

GraftByRelevanceOptions fields

topK? (number) — Maximum number of semantic seed topics.
minSimilarity? (number) — Minimum semantic similarity for a seed.
hopDepth? (number) — Number of graph-neighbour expansion hops.
expansionStrategy? ("none" | "graph", default "graph") — Keep only seeds or expand through topic edges.
sessionIds? (string[]) — Restrict eligible source sessions where the calling API supports cross-session selection.

InjectionResult fields

systemPrompt is the assembled context; this operation does not itself call the chat model.
nodes are selected topics and memories contains their active structured facts when included.
tokenCount is the assembled size; tokenBudget is present when a budget governed assembly.

Result

The selected memory context and prompt text ready to pass to an LLM.

Behavior

Selects semantic seed topics, optionally expands through graph neighbours, loads active memories, and trims the assembled prompt to the configured budget.

Side effects and completion

Read-only; use ingestGraftedNodes() or absorption APIs to copy selected memory.

Example

example.ts
const graft = await agent.graftByRelevance("travel plans", { topK: 3 });