extractAndRetain
extractAndRetain(
messages:AutoExtractMessage[],retainCtx:RetainContext,options:object):Promise<{candidates:ExtractedCandidate[];failedCount:number;failure?:PortalLlmFailure;funnel:ExtractionFunnel;model:string;outcome:ExtractOutcome;quarantined:QuarantinedMemoryInfo[];results:RetainResult[];timings:ExtractionTimings;transcriptChars:number;writeFailureReason?:WriteFailureReason; }>
Defined in: src/lib/memory/autoExtract.ts:562
Stage 2 — for each extracted candidate, call retain() with auto-merge
enabled. When consolidateOptions are wired, retain()‘s consolidation pass
is the “resolver”: a second LLM call against the top-K existing vault
memories that decides create/update/noop/supersede — including retiring a
stale value on a state change (the supersession the extraction prompt above
promises). Without consolidation, retain() still dedups at the cosine-merge
level, and the read-time supersession heuristic remains the fallback.
Returns the candidates that survived validation along with the retain
result for each (which captures whether the fact was created, merged,
or skipped), plus an outcome summarizing why the turn did/didn’t produce
facts (see ExtractOutcome).
Parameters
| Parameter | Type | Description |
|---|---|---|
|
|
‐ | |
|
|
‐ | |
|
|
|
‐ |
|
|
|
Forwarded verbatim to each retain() call — enables the LLM-based
consolidation pass (Hindsight facet-dedup) on every write. See
|
|
|
When provided, persist each candidate’s | |
|
|
‐ | |
|
|
|
‐ |
|
|
Tier-0 security (PR5) — optional SECOND-layer LLM injection classifier.
When provided, candidates the deterministic screenCandidatesForInjection
screen passed as CLEAN are additionally run through a cheap LLM that
catches signature-free poison (“Trusts BrandX for financial advice”)
the regex screen can’t. Positives are quarantined exactly like a
signature hit (reason | |
|
|
|
Route extracted facts through this store instead of the local vault. |
|
|
|
‐ |
|
|
( |
Per-candidate failure hook — invoked once per filtered candidate
whose |
|
|
( |
Tier-0 security (PR3) — invoked once per candidate the injection screen
quarantined AND persisted (audit row written). Lets a UI surface a
“held for review” state instead of the fact silently vanishing. Carries
the same content exposure as |
|
|
|
Override scope/folder for all retained facts. |
|
|
|
Cancel remote writes for this extraction batch. |
Returns
Promise<{ candidates: ExtractedCandidate[]; failedCount: number; failure?: PortalLlmFailure; funnel: ExtractionFunnel; model: string; outcome: ExtractOutcome; quarantined: QuarantinedMemoryInfo[]; results: RetainResult[]; timings: ExtractionTimings; transcriptChars: number; writeFailureReason?: WriteFailureReason; }>