Skip to documentation
Docs navigation
Docs/graftByRelevance()
MemoGrafter

graftByRelevance()

Select session topics by semantic relevance.

What it does

Select session topics by semantic relevance.

When to use it

Use when the application has a session and natural-language intent but not explicit topic IDs.

Signature

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

Parameters

sessionId (string) — The application-owned session whose memory should be read or changed.
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, applies configured graph expansion, and assembles an InjectionResult.

Side effects and completion

Read-only.

Example

example.ts
const graft = await memo.graftByRelevance("session-1", "travel plans");