Skip to content

Graphorin API reference v0.7.0


Graphorin API reference / @graphorin/memory / / SemanticMemory

Class: SemanticMemory

Defined in: packages/memory/src/tiers/semantic-memory.ts:429

SemanticMemory - long-term factual store. Hybrid (vector + FTS5) search merges the two ranked lists through the configured ReRanker (default RRFReranker with k = 60).

Phase 10a wrote facts straight through with MD5 deduplication; Phase 10b routes every remember(...) call through the multi-stage conflict resolution pipeline (DEC-117 / ADR-018 ext / RB-02). The pipeline can be disabled per-call (pipeline: 'off') or per-Memory instance (createMemory({ conflictPipeline: { mode: 'off' } })).

Stable

Constructors

Constructor

ts
new SemanticMemory(args): SemanticMemory;

Defined in: packages/memory/src/tiers/semantic-memory.ts:445

Parameters

ParameterTypeDescription
args{ conflictPipeline?: ConflictPipeline; contextualRetrieval?: "off" | "late-chunk"; embedder: | EmbedderProvider | null; embedderIdProvider: () => string | null; entityResolver?: EntityResolver; grader?: RetrievalGrader; iterativeDifficultyThreshold?: number; iterativeMaxIterations?: number; queryTransformer?: QueryTransformer; reranker: ReRanker; searchDefaults?: SemanticSearchDefaults; store: MemoryStoreAdapter; tracer: Tracer; trustWeights?: SalienceWeights; }-
args.conflictPipeline?ConflictPipeline-
args.contextualRetrieval?"off" | "late-chunk"Contextual-retrieval mode for the write path (P1-3). 'late-chunk' (default) prepends a deterministic situating context to the text that is embedded + FTS-indexed, leaving the canonical text untouched; 'off' indexes the bare text. The hot write path never makes an LLM call - the 'llm' enrichment is confined to the background consolidator, which supplies a precomputed indexText.
args.embedder| EmbedderProvider | null-
args.embedderIdProvider() => string | null-
args.entityResolver?EntityResolverEntity resolver for the relation graph (P2-1). When supplied, remember(...) resolves a fact's subject / object to canonical entities and links them, enabling search(..., { expandHops: 1 }). Omitted (the default) ⇒ writes carry s/p/o but form no entity links, and the write path stays offline + unchanged.
args.grader?RetrievalGraderRetrieval grader for the gated iterative loop (P2-4). When supplied, searchIterative(...) can grade a retrieved set and reformulate on hard queries; omitted (the default) ⇒ searchIterative runs a single, difficulty-gated pass and makes no provider call.
args.iterativeDifficultyThreshold?numberDefault difficulty-gate threshold for searchIterative (W-088). Omitted ⇒ the gate's built-in 0.5. Per-call difficultyThreshold overrides it.
args.iterativeMaxIterations?numberDefault total-pass cap for searchIterative. Default 3.
args.queryTransformer?QueryTransformerQuery transformer for multi-query / HyDE retrieval (P2-3). When supplied, search(..., { multiQuery }) / { hyde } opt into one cheap LLM call to rewrite / hypothesize the query; omitted (the default) ⇒ those options are silent no-ops and search stays offline + single-shot.
args.rerankerReRanker-
args.searchDefaults?SemanticSearchDefaultsConstruction-time retrieval defaults (W-086) merged under every search(...) call - see SemanticSearchDefaults. Because the merge happens inside search(), the model-facing surfaces (fact_search, auto-recall, deep_recall) inherit them without any per-surface wiring; per-call options override key-by-key (so e.g. deep_recall's widen-pass expandHops still wins).
args.storeMemoryStoreAdapter-
args.tracerTracer-
args.trustWeights?SalienceWeightsWeights for the rank-time trust discount (C5). Reuses the eviction-path SalienceWeights semantics; defaults to DEFAULT_SALIENCE_WEIGHTS.

Returns

SemanticMemory

Methods

forget()

ts
forget(
   scope, 
   factId, 
reason?): Promise<void>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:1310

Soft-delete a fact (kept for replay; never hard-deleted).

Parameters

ParameterType
scopeSessionScope
factIdstring
reason?string

Returns

Promise&lt;void&gt;


fuse()

ts
fuse(
   query, 
   lists, 
options?): Promise<readonly MemoryHit<Fact>[]>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:1348

Fuse multiple ranked lists outside of a search() call.

Parameters

ParameterType
querystring
listsreadonly readonly MemoryHit&lt;Fact&gt;[][]
options{ signal?: AbortSignal; topK?: number; }
options.signal?AbortSignal
options.topK?number

Returns

Promise<readonly MemoryHit&lt;Fact&gt;[]>


get()

ts
get(scope, factId): Promise<Fact | null>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:1126

Lookup a single fact by id. Returns null for soft-deleted / missing.

Parameters

ParameterType
scopeSessionScope
factIdstring

Returns

Promise&lt;Fact | null&gt;


history()

ts
history(scope, factId): Promise<readonly Fact[]>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:1156

Return the full bi-temporal supersede chain that factId belongs to, oldest → newest, including superseded / soft-deleted rows so callers can answer "how did this fact change over time". Requires a storage adapter that implements SemanticMemoryStoreExt.historyOf(...) - the default @graphorin/store-sqlite adapter wires this through. P0-2.

Parameters

ParameterType
scopeSessionScope
factIdstring

Returns

Promise&lt;readonly Fact[]&gt;

Stable


neighbors()

ts
neighbors(
   scope, 
   text, 
opts?): Promise<readonly MemoryHit<Fact>[]>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:1117

Raw vector KNN neighbours for the consolidator's reconcile pre-filter (P0-3). Unlike search this skips FTS, reranking, and decay so the cosine scores survive intact (the conflict-pipeline zone thresholds are calibrated against them), and it includes quarantined facts so prior synthesized memories are visible to reconciliation. Returns [] when no embedder / vector adapter is configured - the consolidator then treats every candidate as a fresh add, degrading gracefully to the pre-reconcile behaviour.

Parameters

ParameterType
scopeSessionScope
textstring
opts{ topK?: number; }
opts.topK?number

Returns

Promise<readonly MemoryHit&lt;Fact&gt;[]>

Stable


purge()

ts
purge(
   scope, 
   factId, 
reason?): Promise<void>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:1329

Hard-delete a fact (GDPR path). Distinct from forget: the record is removed from storage entirely instead of soft-archived. Requires a storage adapter that implements SemanticMemoryStoreExt.purge(...) - the default @graphorin/store-sqlite adapter wires this through.

Parameters

ParameterType
scopeSessionScope
factIdstring
reason?string

Returns

Promise&lt;void&gt;


remember()

ts
remember(
   scope, 
   input, 
options?): Promise<Fact>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:544

Persist a fact. Returns the stored record. Phase 10b routes every call through the multi-stage conflict resolution pipeline; the legacy straight-through path is reachable per-call via { pipeline: 'off' } (operators may disable the pipeline globally via createMemory({ conflictPipeline: { mode: 'off' } })).

Parameters

ParameterType
scopeSessionScope
inputFactInput
optionsFactRememberOptions

Returns

Promise&lt;Fact&gt;


rememberWithDecision()

ts
rememberWithDecision(
   scope, 
   input, 
options?): Promise<RememberOutcome>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:560

Like remember but returns the pipeline decision alongside the stored fact. Useful for callers that need to distinguish silent dedups (decision.kind === 'dedup') from fresh inserts.

Parameters

ParameterType
scopeSessionScope
inputFactInput
optionsFactRememberOptions

Returns

Promise&lt;RememberOutcome&gt;

Stable


reranker()

ts
reranker(): ReRanker;

Defined in: packages/memory/src/tiers/semantic-memory.ts:533

Currently active reranker.

Returns

ReRanker


ts
search(
   scope, 
   query, 
callOpts?): Promise<readonly MemoryHit<Fact>[]>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:773

Hybrid (vector + FTS5) search merged through the configured reranker.

Parameters

ParameterType
scopeSessionScope
querystring
callOptsFactSearchOptions

Returns

Promise<readonly MemoryHit&lt;Fact&gt;[]>


searchIterative()

ts
searchIterative(
   scope, 
   query, 
opts?): Promise<IterativeRecallResult>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:1041

Gated, iterative ("deep") recall for hard queries (P2-4). A cheap local heuristic (assessQueryDifficulty) decides whether the query is even a loop candidate; simple lookups take exactly one search pass and make no provider call. For a query judged hard and with a grader configured (createMemory({ iterativeRetrieval })), the retrieved set is graded for sufficiency and, when weak, the query is reformulated and retrieved again - widening to one-hop graph expansion (expandHops: 1) on each reformulation pass - up to maxIterations (hard-capped at 5). When still insufficient it returns abstained: true so the caller can decline to answer instead of confabulating.

Without a grader (the offline default) this degrades to a single, difficulty-gated search and never calls a provider.

Parameters

ParameterType
scopeSessionScope
querystring
optsIterativeSearchOptions

Returns

Promise&lt;IterativeRecallResult&gt;

Stable


setReranker()

ts
setReranker(reranker): ReRanker;

Defined in: packages/memory/src/tiers/semantic-memory.ts:526

Replace the active reranker. Returns the previous instance.

Parameters

ParameterType
rerankerReRanker

Returns

ReRanker


supersede()

ts
supersede(
   scope, 
   oldId, 
   newInput, 
   reason?, 
   options?): Promise<{
  new: Fact;
  old: string;
}>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:1270

Mark oldId superseded by a new fact. Returns the new record.

W-019 (security-first, knowledge-preserving): when the successor lands QUARANTINED (the default for extraction/synthesized provenance), the old ACTIVE fact's validity interval is NOT closed

  • default recall keeps returning the old knowledge until the successor passes validate, which completes the closure. The link is recorded on the successor's supersedes field. With autoPromoteSynthesized (threaded from the consolidator's autoPromoteExtraction escape hatch) an injection-clean successor is active immediately and the interval closes right away - the pre-W-019 behaviour. Inverting the default (auto-activating the successor) would hand a MINJA attacker instant active memory via any text the reconciler classifies as an 'update'.

Parameters

ParameterType
scopeSessionScope
oldIdstring
newInputFactInput
reason?string
options?{ autoPromoteSynthesized?: boolean; }
options.autoPromoteSynthesized?boolean

Returns

Promise<{ new: Fact; old: string; }>


validate()

ts
validate(
   scope, 
   factId, 
   reason?, 
options?): Promise<void>;

Defined in: packages/memory/src/tiers/semantic-memory.ts:1196

Promote a quarantined fact to active (P1-4). The validation path that admits a synthesized memory into action-driving recall once a human (or trusted non-agent caller) has reviewed it. Writes a memory_history audit row. Requires a storage adapter that implements SemanticMemoryStoreExt.setStatus(...) - the default @graphorin/store-sqlite adapter wires this through.

MRET-3 / MST-1: promotion of a fact whose text still trips the offline injection heuristics is refused with QuarantinePromotionRefusedError - the model-facing fact_validate tool calls this with no force, so a poisoned memory can never be promoted by the agent itself (the one-turn fact_remember(poison)fact_validate(id) chain is closed). An operator can override after review by passing { force: true } from a trusted (non-agent) context. Synthesized-but-clean writes (consolidator / reflection) promote normally.

Parameters

ParameterType
scopeSessionScope
factIdstring
reason?string
options?{ force?: boolean; }
options.force?boolean

Returns

Promise&lt;void&gt;

Stable


fuseRrf()

ts
static fuseRrf<TRecord>(lists, k?): readonly MemoryHit<TRecord>[];

Defined in: packages/memory/src/tiers/semantic-memory.ts:1357

Pure-fusion helper - exposed for callers that already collected results.

Type Parameters

Type Parameter
TRecord extends Fact

Parameters

ParameterTypeDefault value
listsreadonly readonly MemoryHit&lt;TRecord&gt;[][]undefined
knumber60

Returns

readonly MemoryHit&lt;TRecord&gt;[]


fuseWeighted()

ts
static fuseWeighted<TRecord>(
   lists, 
   weights, 
   k?): readonly MemoryHit<TRecord>[];

Defined in: packages/memory/src/tiers/semantic-memory.ts:1370

Pure weighted-fusion helper (X-2) - like SemanticMemory.fuseRrf but scales each list i's reciprocal-rank contribution by weights[i]. A missing / invalid entry defaults to 1, so equal or absent weights reproduce RRF.

Type Parameters

Type Parameter
TRecord extends Fact

Parameters

ParameterTypeDefault value
listsreadonly readonly MemoryHit&lt;TRecord&gt;[][]undefined
weightsreadonly number[] | undefinedundefined
knumber60

Returns

readonly MemoryHit&lt;TRecord&gt;[]