@memhtml/eval: the fixture corpus generator, and the refusable retrieval discrimination gate. The corpus is never committed; each run regenerates it from a seed.
The gate asks one question: can the retrieval stack rank a memory above its own high-similarity WRONG twin? controls turns a true claim into a plausible impostor along three divergence families (negation, numeric, variant), validates each control against its own family’s predicate from @memhtml/domain, and discards a control that failed to diverge. corpus is a pure function of (seed, now): it yields the same memory specs and probes on any machine, with every timestamp anchored as an offset behind the run so that salience decay cannot move the ranks from one calendar day to the next. fixture is the one module that writes, rendering a spec into a real git repository under a temp directory. harness builds the stack the gate measures (that fixture, a real database with the shipped migrations, the real indexer and the real four-arm retrieval) and substitutes only the embedder: a deterministic one whose cosine relations are a pure function of the text, so the numbers reproduce without credentials. discriminate runs the probes and reports two numbers, of which the strict one is the gate: mrr against a floor of 0.85, and a per-probe inversion count where one inversion fails the run regardless of MRR. run picks the mode and shapes the outcome so that a skipped gate never looks like a passing one: fake mode runs everywhere, and live mode without credentials reports skipped: true and passed: false.
This package sits above @memhtml/contracts, @memhtml/domain, @memhtml/html, @memhtml/index, @memhtml/llm and @memhtml/store, and apps/cli depends on it: memhtml eval discriminate is runDiscrimination.
Modules
Section titled “Modules”The package publishes one import path, @memhtml/eval, which re-exports the six modules below, so the reference on this page is the whole exported surface. gen-fixture.ts is the body of pnpm gen:fixture and is not exported.
| Module | What it holds |
|---|---|
controls.ts |
DIVERGENCE_FAMILIES, the three flips (negationFlip, numericFlip, variantFlip), familyPredicate and deriveControl. |
corpus.ts |
MemorySpec, Probe, CorpusSpec, the defaults (DEFAULT_SEED, DEFAULT_CORPUS_SIZE, DEFAULT_PROBE_COUNT), quantizeNow, articleFor, queryFor and buildCorpus. |
discriminate.ts |
MRR_FLOOR, PROBE_LIMIT, runProbes, summarize, discriminate, runFloor, describeFailure and the report shapes. |
fixture.ts |
FixtureCorpus, FixtureOptions, memoryFileFor, writeCorpus and makeFixtureCorpus. |
harness.ts |
EvalStack, StackOptions, the embedders (fakeEmbedder, failingEmbedder, liveEmbedder, fakeVector, FAKE_DIM), buildStack and withStack. |
run.ts |
EvalOptions, EvalOutcome, BEDROCK_TOKEN_VAR, hasBedrockCredentials, runDiscrimination, DiscriminationFailed and discriminationGate. |
Classes
Section titled “Classes”DiscriminationFailed
Section titled “DiscriminationFailed”A failed gate, as a tagged error.
Tagged so it is a failure like every other in the system rather than a bare value. The CLI’s
codeFor switches on _tag, and ERR_DISCRIMINATION_FAILED, the error code design §8 named for
exactly this refusal, would otherwise have no producer at all and degrade to ERR_UNKNOWN.
The whole outcome rides along, because a refusal an operator cannot reproduce is a refusal they will
override. seed regenerates the corpus that failed, and inversions says which probes.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new DiscriminationFailed(outcome): DiscriminationFailed;Parameters
Section titled “Parameters”outcome
Section titled “outcome”Returns
Section titled “Returns”Properties
Section titled “Properties”readonly _tag: "DiscriminationFailed" = "DiscriminationFailed";outcome
Section titled “outcome”readonly outcome: EvalOutcome;Accessors
Section titled “Accessors”reason
Section titled “reason”Get Signature
Section titled “Get Signature”get reason(): string;The one-line summary, used as the envelope’s human message.
Returns
Section titled “Returns”string
Interfaces
Section titled “Interfaces”ClaimText
Section titled “ClaimText”The text of a memory as the flips see it, meaning the claim then each body paragraph.
Extended by
Section titled “Extended by”Properties
Section titled “Properties”readonly body: readonly string[];readonly claim: string;CorpusSpec
Section titled “CorpusSpec”The whole fixture: the memories to write, their access history, and the probes.
Properties
Section titled “Properties”access
Section titled “access”readonly access: readonly AccessSpec[];state.access rows the harness seeds before running the probes.
memories
Section titled “memories”readonly memories: readonly MemorySpec[];readonly now: number;The quantized run instant every stamp is anchored behind, UTC millis. See quantizeNow.
probes
Section titled “probes”readonly probes: readonly Probe[];readonly seed: number;DerivedControl
Section titled “DerivedControl”A derived control, holding the flipped text plus the family that produced it.
Extends
Section titled “Extends”Properties
Section titled “Properties”readonly body: readonly string[];Inherited from
Section titled “Inherited from”readonly claim: string;Inherited from
Section titled “Inherited from”family
Section titled “family”readonly family: DivergenceFamily;readonly note: string;What changed, for the probe’s own record.
DiscriminationReport
Section titled “DiscriminationReport”The whole run’s outcome. This is the eval.discrimination envelope payload.
Extended by
Section titled “Extended by”Properties
Section titled “Properties”corpusMrr
Section titled “corpusMrr”readonly corpusMrr: number;Mean reciprocal rank over the WHOLE hit list, unitless in [0, 1], four decimals.
Reported rather than gated, because corpus size dominates it more than ranking quality does.
DEFAULT_ARM_LIMIT is 40, which is 13% of a 300-file fixture and under 1% of a real corpus, so
the two query-blind arms cover a far larger share of a fixture than of production. The value is
seed- and parameter-dependent — it moves with the corpus size, the probe count, and the seed —
but it rises with corpus size on this generator while the inversion count stays flat, which is
exactly why a gate on this number would be a gate on how big the fixture is.
degradedProbes
Section titled “degradedProbes”readonly degradedProbes: number;Probes ranked by a degraded (vector-arm-free) search.
discriminated
Section titled “discriminated”readonly discriminated: number;Probes whose target strictly outranked all of its controls.
inversions
Section titled “inversions”readonly inversions: readonly ProbeResult[];Probes with at least one inversion. The gate fails when this is non-zero.
readonly mode: EvalMode;readonly mrr: number;Mean reciprocal rank over {target} ∪ controls, unitless in [0, 1], four decimals.
This is the gated number, and its coordinate space is the discrimination set, not the corpus.
Design §5 states the floor in the same clause as rank(target) < min(rank(control)), so the space
the sentence is about is the target against its own impostors. 1.0 means every target beat every
control outright. See corpusMrr for the other reading, which is reported and not gated.
mrrFloor
Section titled “mrrFloor”readonly mrrFloor: number;The floor mrr was measured against.
passed
Section titled “passed”readonly passed: boolean;True when there are zero inversions AND mrr >= mrrFloor.
probes
Section titled “probes”readonly probes: number;results
Section titled “results”readonly results: readonly ProbeResult[];EvalEmbedder
Section titled “EvalEmbedder”Both embed ports plus a call counter.
Extends
Section titled “Extends”EmbedPortQueryEmbedPort
Properties
Section titled “Properties”readonly calls: () => number;Returns
Section titled “Returns”number
readonly embed: (texts) => Effect<readonly Float32Array<ArrayBufferLike>[], ModelUnavailable>;Parameters
Section titled “Parameters”readonly string[]
Returns
Section titled “Returns”Effect<readonly Float32Array<ArrayBufferLike>[], ModelUnavailable>
Inherited from
Section titled “Inherited from”EmbedPort.embed
embedQuery
Section titled “embedQuery”readonly embedQuery: (text) => Effect<Float32Array<ArrayBufferLike>, ModelUnavailable>;Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Effect<Float32Array<ArrayBufferLike>, ModelUnavailable>
Inherited from
Section titled “Inherited from”QueryEmbedPort.embedQuery
EvalOptions
Section titled “EvalOptions”What runDiscrimination takes.
Properties
Section titled “Properties”readonly env?: Readonly<Record<string, string | undefined>>;Injected for tests, so the credential branch is drivable without touching the environment.
readonly mode?: EvalMode;fake by default, the mode that works in CI and whose numbers are reproducible.
mrrFloor?
Section titled “mrrFloor?”readonly mrrFloor?: number;readonly now?: number;The run instant to anchor the corpus’s stamps behind, UTC millis. The clock when absent.
probes?
Section titled “probes?”readonly probes?: number;readonly seed?: number;readonly size?: number;EvalOutcome
Section titled “EvalOutcome”What memhtml eval discriminate emits, the report plus which mode was asked for.
Extends
Section titled “Extends”Properties
Section titled “Properties”corpusMrr
Section titled “corpusMrr”readonly corpusMrr: number;Mean reciprocal rank over the WHOLE hit list, unitless in [0, 1], four decimals.
Reported rather than gated, because corpus size dominates it more than ranking quality does.
DEFAULT_ARM_LIMIT is 40, which is 13% of a 300-file fixture and under 1% of a real corpus, so
the two query-blind arms cover a far larger share of a fixture than of production. The value is
seed- and parameter-dependent — it moves with the corpus size, the probe count, and the seed —
but it rises with corpus size on this generator while the inversion count stays flat, which is
exactly why a gate on this number would be a gate on how big the fixture is.
Inherited from
Section titled “Inherited from”DiscriminationReport.corpusMrr
corpusSize
Section titled “corpusSize”readonly corpusSize: number;degradedProbes
Section titled “degradedProbes”readonly degradedProbes: number;Probes ranked by a degraded (vector-arm-free) search.
Inherited from
Section titled “Inherited from”DiscriminationReport.degradedProbes
discriminated
Section titled “discriminated”readonly discriminated: number;Probes whose target strictly outranked all of its controls.
Inherited from
Section titled “Inherited from”DiscriminationReport.discriminated
inversions
Section titled “inversions”readonly inversions: readonly ProbeResult[];Probes with at least one inversion. The gate fails when this is non-zero.
Inherited from
Section titled “Inherited from”DiscriminationReport.inversions
readonly mode: EvalMode;Inherited from
Section titled “Inherited from”readonly mrr: number;Mean reciprocal rank over {target} ∪ controls, unitless in [0, 1], four decimals.
This is the gated number, and its coordinate space is the discrimination set, not the corpus.
Design §5 states the floor in the same clause as rank(target) < min(rank(control)), so the space
the sentence is about is the target against its own impostors. 1.0 means every target beat every
control outright. See corpusMrr for the other reading, which is reported and not gated.
Inherited from
Section titled “Inherited from”mrrFloor
Section titled “mrrFloor”readonly mrrFloor: number;The floor mrr was measured against.
Inherited from
Section titled “Inherited from”readonly now: number;The quantized run instant the corpus’s stamps were anchored behind, UTC millis. The other half
of reproducing a failing run, since the corpus is a function of (seed, now). 0 on a skipped
run, where no corpus was generated.
passed
Section titled “passed”readonly passed: boolean;True when there are zero inversions AND mrr >= mrrFloor.
Inherited from
Section titled “Inherited from”probes
Section titled “probes”readonly probes: number;Inherited from
Section titled “Inherited from”requested
Section titled “requested”readonly requested: EvalMode;The mode the caller asked for, which differs from mode only on a refused live run.
results
Section titled “results”readonly results: readonly ProbeResult[];Inherited from
Section titled “Inherited from”readonly seed: number;The seed the corpus was generated at, so a failing run is reproducible.
skipped
Section titled “skipped”readonly skipped: boolean;True when live mode was requested with no credentials present. A skipped run is passed: false
and carries zero probes, so it is a refusal rather than a result.
skipReason?
Section titled “skipReason?”readonly skipReason?: string;Why it was skipped, absent otherwise.
EvalStack
Section titled “EvalStack”A built stack, holding the fixture, the database, and retrieval over both.
Properties
Section titled “Properties”readonly db: DatabaseShape;embedCalls
Section titled “embedCalls”readonly embedCalls: () => number;Returns
Section titled “Returns”number
fixture
Section titled “fixture”readonly fixture: FixtureCorpus;indexed
Section titled “indexed”readonly indexed: number;How many files the indexer projected, so a caller can assert the corpus really landed.
retrieval
Section titled “retrieval”readonly retrieval: RetrievalShape;FixtureCorpus
Section titled “FixtureCorpus”A generated fixture repo, with the root, the git service over it, and the spec behind it.
Properties
Section titled “Properties”cleanup
Section titled “cleanup”readonly cleanup: () => Promise<void>;Returns
Section titled “Returns”Promise<void>
readonly git: GitShape;readonly root: string;readonly spec: CorpusSpec;written
Section titled “written”readonly written: number;How many files were written, generated artifacts excluded.
FixtureOptions
Section titled “FixtureOptions”What makeFixtureCorpus takes. Every field has a default, so a caller can pass nothing.
Extended by
Section titled “Extended by”Properties
Section titled “Properties”readonly now?: number;The run instant the corpus’s stamps are anchored behind, UTC millis. Effect’s Clock when
absent, which is the one place the fixture pipeline consults time at all — buildCorpus
requires it, so a test pinning this value pins every stamp in the tree.
probes?
Section titled “probes?”readonly probes?: number;readonly root?: string;Where to generate. A fresh temp directory when absent.
readonly seed?: number;readonly size?: number;FloorReport
Section titled “FloorReport”The lexical-floor scenario runs the same suite with no vector arm.
Design §5 requires two things of it: no error, and the lexical arm still beating the controls on the probes that carry lexical signal. Only the SECOND half is a subset claim, and it has to be. A numeric-family control differs from its target by one token, which the FTS arm cannot order, so demanding the full gate without vectors would be demanding the vector arm be unnecessary.
lexicallyDiscriminated is therefore the number reported and asserted, not passed.
Properties
Section titled “Properties”allDegraded
Section titled “allDegraded”readonly allDegraded: boolean;True when every probe was ranked degraded, which asserts that the arm really is absent.
lexicallyDiscriminated
Section titled “lexicallyDiscriminated”readonly lexicallyDiscriminated: number;Probes the lexical floor still discriminated.
probes
Section titled “probes”readonly probes: number;results
Section titled “results”readonly results: readonly ProbeResult[];Every result, so a caller can see which families survive without vectors.
MemorySpec
Section titled “MemorySpec”One memory to write, before it becomes HTML.
Properties
Section titled “Properties”archivedAt?
Section titled “archivedAt?”readonly archivedAt?: string;Set on the archived members, which carry memhtml-status: archived and a memhtml-archived stamp.
readonly body: readonly string[];readonly claim: string;The sentence the memory turns on. It becomes the <mark> span and therefore files.gist.
confidence
Section titled “confidence”readonly confidence: number;createdAt
Section titled “createdAt”readonly createdAt: string;entities
Section titled “entities”readonly entities: readonly string[];extras
Section titled “extras”readonly extras: readonly string[];Extra article markup after the claim paragraph, the element kit this memory exercises.
importance
Section titled “importance”readonly importance: number;readonly links: readonly object[];memoryType
Section titled “memoryType”readonly memoryType: string;readonly path: string;sessionId?
Section titled “sessionId?”readonly sessionId?: string;readonly tags: readonly string[];readonly title: string;updatedAt
Section titled “updatedAt”readonly updatedAt: string;validUntil?
Section titled “validUntil?”readonly validUntil?: string;One discrimination probe: a query, the memory that answers it, and the near-twins that do not.
controlPaths are ordered by family so a failure names the axis. Each control is validated
against its OWN family’s divergence predicate at generation time. See controls.ts.
Properties
Section titled “Properties”controlPaths
Section titled “controlPaths”readonly controlPaths: readonly string[];families
Section titled “families”readonly families: readonly DivergenceFamily[];readonly query: string;targetPath
Section titled “targetPath”readonly targetPath: string;ProbeResult
Section titled “ProbeResult”One probe’s outcome.
Properties
Section titled “Properties”controlRanks
Section titled “controlRanks”readonly controlRanks: readonly object[];Each control’s 1-based rank in the whole hit list, null when absent from the hits.
corpusReciprocalRank
Section titled “corpusReciprocalRank”readonly corpusReciprocalRank: number;1 / targetRank, or 0 when the target was absent. The term of corpusMrr.
degraded
Section titled “degraded”readonly degraded: boolean;True when the vector arm did not fire for this probe.
discriminated
Section titled “discriminated”readonly discriminated: boolean;True when the target strictly outranks EVERY control. A control the search never returned counts as outranked, since being absent is worse than being last.
discriminationRank
Section titled “discriminationRank”readonly discriminationRank: number;1-based rank of the target within {target} ∪ controls ALONE, the space the gate is stated in.
1 means the target beat every one of its own impostors. Never null, because the target is
always a member of this set, so an absent target ranks last rather than nowhere.
readonly query: string;reciprocalRank
Section titled “reciprocalRank”readonly reciprocalRank: number;1 / discriminationRank. The term of DiscriminationReport.mrr.
targetPath
Section titled “targetPath”readonly targetPath: string;targetRank
Section titled “targetRank”readonly targetRank: number | null;1-based rank of the target within the WHOLE returned hit list, or null when it was not returned.
The scope is every active memory in the corpus. Compare against discriminationRank, which
measures the same position in a different space.
StackOptions
Section titled “StackOptions”What buildStack takes beyond the fixture options.
Extends
Section titled “Extends”Properties
Section titled “Properties”embedder?
Section titled “embedder?”readonly embedder?: EvalEmbedder;The embedder to measure through. fakeEmbedder() when absent.
readonly now?: number;The run instant the corpus’s stamps are anchored behind, UTC millis. Effect’s Clock when
absent, which is the one place the fixture pipeline consults time at all — buildCorpus
requires it, so a test pinning this value pins every stamp in the tree.
Inherited from
Section titled “Inherited from”probes?
Section titled “probes?”readonly probes?: number;Inherited from
Section titled “Inherited from”readonly root?: string;Where to generate. A fresh temp directory when absent.
Inherited from
Section titled “Inherited from”readonly seed?: number;Inherited from
Section titled “Inherited from”readonly size?: number;Inherited from
Section titled “Inherited from”VariantOptions
Section titled “VariantOptions”What a variant-family derivation needs beyond the target’s own text.
Properties
Section titled “Properties”anchor
Section titled “anchor”readonly anchor: string;The token the qualifier is inserted after, a product or host name in the claim.
qualifier
Section titled “qualifier”readonly qualifier: string;A VARIANT_QUALIFIERS member, such as pro, beta, or legacy.
Type Aliases
Section titled “Type Aliases”DivergenceFamily
Section titled “DivergenceFamily”type DivergenceFamily = "negation" | "numeric" | "variant";Which divergence a control embodies. Named on the probe, so a failure says which axis broke.
EvalMode
Section titled “EvalMode”type EvalMode = "live" | "fake";Which embedder produced the numbers. Recorded on the report so a pass is never ambiguous.
Variables
Section titled “Variables”BEDROCK_TOKEN_VAR
Section titled “BEDROCK_TOKEN_VAR”const BEDROCK_TOKEN_VAR: "AWS_BEARER_TOKEN_BEDROCK" = "AWS_BEARER_TOKEN_BEDROCK";The variable whose presence decides whether live mode can run.
DEFAULT_CORPUS_SIZE
Section titled “DEFAULT_CORPUS_SIZE”const DEFAULT_CORPUS_SIZE: 200 = 200;How many base memories a default corpus carries, before controls and the archive tier.
DEFAULT_PROBE_COUNT
Section titled “DEFAULT_PROBE_COUNT”const DEFAULT_PROBE_COUNT: 36 = 36;How many probes a default corpus carries. Design §5 requires at least 30.
DEFAULT_SEED
Section titled “DEFAULT_SEED”const DEFAULT_SEED: 20260802 = 20_260_802;The default seed. Named so a caller changing it is making a visible choice.
DIVERGENCE_FAMILIES
Section titled “DIVERGENCE_FAMILIES”const DIVERGENCE_FAMILIES: ReadonlyArray<DivergenceFamily>;FAKE_DIM
Section titled “FAKE_DIM”const FAKE_DIM: 1024 = EMBED_DIM;The vector width the fake produces. It is the real one, so a width check cannot pass by luck.
MRR_FLOOR
Section titled “MRR_FLOOR”const MRR_FLOOR: 0.85 = 0.85;The MRR floor, from design §5. A gate below this admits a target that loses to one of its own negation-flipped twins on one probe in seven. An agent cannot trust that retrieval layer to answer with the right fact.
PROBE_LIMIT
Section titled “PROBE_LIMIT”const PROBE_LIMIT: 40 = 40;How many hits each probe requests.
Wide enough that a control’s rank is observable rather than truncated into null. A window of 10
would report an inversion and a merely-narrow miss identically, and the two need different fixes.
The gate itself compares ranks, so widening the window can only make it stricter.
Functions
Section titled “Functions”articleFor()
Section titled “articleFor()”function articleFor(spec): string;The article markup for a spec: the claim paragraph, the first body paragraph joined onto it, then the remaining paragraphs and the element kit.
Written here rather than left to renderTemplate’s claim/body path because the kits carry real
markup, and renderTemplate escapes its body strings as text. That is correct for a tool
parameter and wrong for a <dl>.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”string
buildCorpus()
Section titled “buildCorpus()”function buildCorpus(options): CorpusSpec;The whole fixture specification.
The order is fixed as people, base, archive tier, then controls, so the generated tree is written
in a stable order and two runs at one (seed, now) produce byte-identical files. now is
REQUIRED rather than defaulted from a clock, because this module’s contract is purity: every
caller threads its own run instant (the harness reads Effect’s Clock once), it is quantized to
the UTC day, and it is recorded on the spec, so a failing run is reproducible by passing the
reported now back in.
Parameters
Section titled “Parameters”options
Section titled “options”number
The run instant to anchor stamps behind, UTC millis.
probes?
Section titled “probes?”number
number
number
Returns
Section titled “Returns”buildStack()
Section titled “buildStack()”function buildStack(options?): Effect<EvalStack, never, Scope>;Build the whole stack inside a scope: generate the corpus, index it, and return retrieval over it.
Effect.acquireRelease owns the database, so the caller’s Effect.scoped closes the connection,
and the fixture’s own cleanup removes the temp tree. Both matter in a CLI, because a command
that leaked a database handle would keep a WAL file alive under /tmp for the life of the process.
Parameters
Section titled “Parameters”options?
Section titled “options?”StackOptions = {}
Returns
Section titled “Returns”Effect<EvalStack, never, Scope>
deriveControl()
Section titled “deriveControl()”function deriveControl( target, family, options?): DerivedControl | undefined;Derive one control from a target, or refuse.
Refusal, returned as undefined, is the behavior callers depend on. It has two causes, and each
one would otherwise produce a control that LOOKS adversarial and is not:
- The family does not apply (no number to flip).
- The pair fails the family’s own predicate. For
negationthat means the target body already carried a marker, so the flip is invisible to the guard that defines the family.
A caller that ignores the refusal and ships the pair anyway gets a probe whose control is a paraphrase, and a gate built on paraphrases passes no matter how badly retrieval discriminates.
Parameters
Section titled “Parameters”target
Section titled “target”family
Section titled “family”options?
Section titled “options?”Returns
Section titled “Returns”DerivedControl | undefined
describeFailure()
Section titled “describeFailure()”function describeFailure(report): string;A one-line summary of a failure, for stderr and for a merge’s refusal log.
Names the first inversion rather than every one, because an operator needs a probe to reproduce and a thirty-line dump of a failing gate is a thirty-line dump nobody reads. The full list is on the report.
Parameters
Section titled “Parameters”report
Section titled “report”Returns
Section titled “Returns”string
discriminate()
Section titled “discriminate()”function discriminate( retrieval, probes, options): Effect<DiscriminationReport, StorageFailure>;Run the suite and summarize it in one call.
Parameters
Section titled “Parameters”retrieval
Section titled “retrieval”RetrievalShape
probes
Section titled “probes”readonly Probe[]
options
Section titled “options”limit?
Section titled “limit?”number
mrrFloor?
Section titled “mrrFloor?”number
Returns
Section titled “Returns”Effect<DiscriminationReport, StorageFailure>
discriminationGate()
Section titled “discriminationGate()”function discriminationGate(options?): Effect<EvalOutcome, DiscriminationFailed, never>;The gate, for a merge that must refuse on a regression.
A failing gate FAILS this effect, which is what a merge reads to refuse. It wraps
the gate in Effect.result and turns a failure into refusal: "gate-failed" with main never
moving. The shape matters, because a version returning a boolean would let a caller forget to check
it, and a refusable gate must not be optional at its call site.
Parameters
Section titled “Parameters”options?
Section titled “options?”EvalOptions = {}
Returns
Section titled “Returns”Effect<EvalOutcome, DiscriminationFailed, never>
failingEmbedder()
Section titled “failingEmbedder()”function failingEmbedder(): EvalEmbedder;An embedder that always fails, for the lexical-floor scenario.
The failure travels through the ERROR channel as a typed ModelUnavailable rather than a throw.
The floor only holds if retrieval can catch it, and a defect would kill the fiber instead of
narrowing the search.
Returns
Section titled “Returns”fakeEmbedder()
Section titled “fakeEmbedder()”function fakeEmbedder(): EvalEmbedder;Returns
Section titled “Returns”fakeVector()
Section titled “fakeVector()”function fakeVector(text): Float32Array;The deterministic embedder, built as a hash-seeded bag of words, L2-normalized.
The same construction @memhtml/index and tests-integration use in their own harnesses. Two texts sharing
vocabulary have a genuinely high cosine and two disjoint texts a low one, which makes a
negation-flipped control a real adversary here instead of a random vector the arm trivially
separates. A random fake would make the gate meaningless in the easy direction and a constant fake
in the hard one.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Float32Array
familyPredicate()
Section titled “familyPredicate()”function familyPredicate(family): (textA, textB) => boolean;The predicate a family’s control must satisfy against its target.
Parameters
Section titled “Parameters”family
Section titled “family”Returns
Section titled “Returns”(textA, textB) => boolean
hasBedrockCredentials()
Section titled “hasBedrockCredentials()”function hasBedrockCredentials(env?): boolean;True when a Bedrock bearer token is present in the environment.
Parameters
Section titled “Parameters”Readonly<Record<string, string | undefined>> = process.env
Returns
Section titled “Returns”boolean
liveEmbedder()
Section titled “liveEmbedder()”function liveEmbedder(): Effect<EvalEmbedder>;The real Bedrock embedder, for live mode. Built only when a caller asks for it.
Returns
Section titled “Returns”Effect<EvalEmbedder>
makeFixtureCorpus()
Section titled “makeFixtureCorpus()”function makeFixtureCorpus(options?): Effect<FixtureCorpus>;A scaffolded memory repo carrying a generated corpus.
initRepo is the real one, so the fixture carries the real .gitignore, the real
.gitattributes, and the real merge.ours.driver config. That config is per-clone, and the
merge=ours attribute does nothing without it.
Parameters
Section titled “Parameters”options?
Section titled “options?”FixtureOptions = {}
Returns
Section titled “Returns”Effect<FixtureCorpus>
memoryFileFor()
Section titled “memoryFileFor()”function memoryFileFor(spec): string;One spec as a memory file’s bytes.
Hand-assembled rather than routed through @memhtml/html’s renderTemplate, because of the
element kits. renderTemplate escapes each body string as TEXT, which is right for an agent’s
tool parameter and wrong for a <dl> the fixture means as markup. The head is written in
META_ORDER so a generated file is byte-identical to what the serializer would emit for the same
metadata. The rest of the system then treats the fixture as an ordinary document.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”string
negationFlip()
Section titled “negationFlip()”function negationFlip(claim): string;The affirmative claim as its negation.
Total. When no verb anchor is present the whole sentence is wrapped rather than left unchanged. A transform that returned its input would produce a “control” identical to its target, and an identical control is a duplicate the content-hash index refuses at index time, one layer too late to explain itself.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
numericFlip()
Section titled “numericFlip()”function numericFlip(claim): string | undefined;The claim with its first numeric token replaced by a different one.
undefined when the claim carries no number, because the family does not apply. Inventing a
number to flip would produce a control that differs from its target by an ADDED fact rather than
by a contradicted one. The probe builder reads the undefined and skips the family instead of
emitting a weaker control under the same name.
The replacement is value + 10 for a small integer and value * 2 otherwise, so the wrong
number stays in the plausible range for whatever the sentence counts. A retry budget of 13 is a
believable misremembering of 3, and 3000 is not.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string | undefined
quantizeNow()
Section titled “quantizeNow()”function quantizeNow(nowMillis): number;Quantize a run instant to its UTC day.
The anchor is the day rather than the millisecond so that every run on one calendar date builds a byte-identical corpus at a given seed. The gate’s determinism checks compare two full runs, and a millisecond-precision anchor would make “same seed, same numbers” true only for runs started in the same millisecond.
Math.floor rather than a % remainder, because JS % keeps the DIVIDEND’s sign: at
nowMillis = -1, nowMillis % DAY_MILLIS is -1 and subtracting it lands on 0 — an anchor AHEAD
of the instant asked for, which is the one thing the anchoring exists to rule out.
A non-finite instant is refused here rather than carried: NaN passes every arithmetic step and
surfaces hundreds of lines later as RangeError: Invalid time value out of a stamp formatter, which
names neither the input nor the caller that supplied it.
Parameters
Section titled “Parameters”nowMillis
Section titled “nowMillis”number
Returns
Section titled “Returns”number
queryFor()
Section titled “queryFor()”function queryFor(spec, limit?): string;A probe query holds the target’s own content words, in order, capped.
Content words rather than the claim verbatim, and the query design decides what the probe can measure. A NUMERIC-family control differs from its target in exactly one numeric token, so a query that dropped the number would have identical overlap with both and the vector arm could not order them at all. The probe would measure a tie-break instead. Keeping the digits is what makes the numeric family a probe rather than a coin toss. The same reasoning keeps a variant qualifier’s ANCHOR in the query while the qualifier itself, which only the control carries, stays out.
Stopwords go so that not cannot hide behind them. A query carrying the target’s function words
would raise the negation control’s lexical overlap for a reason unrelated to the fact either
states.
Parameters
Section titled “Parameters”limit?
Section titled “limit?”number = 12
Returns
Section titled “Returns”string
runDiscrimination()
Section titled “runDiscrimination()”function runDiscrimination(options?): Effect<EvalOutcome, never, never>;Run the gate.
Never fails, because the report IS the answer and a caller maps passed to an exit code. An eval
whose error channel could fire would hand a caller a run that both happened and errored, with no
way to say whether the corpus, the index, or the ranking was at fault.
Parameters
Section titled “Parameters”options?
Section titled “options?”EvalOptions = {}
Returns
Section titled “Returns”Effect<EvalOutcome, never, never>
runFloor()
Section titled “runFloor()”function runFloor( retrieval, probes, options?): Effect<FloorReport, StorageFailure>;Parameters
Section titled “Parameters”retrieval
Section titled “retrieval”RetrievalShape
probes
Section titled “probes”readonly Probe[]
options?
Section titled “options?”limit?
Section titled “limit?”number
Returns
Section titled “Returns”Effect<FloorReport, StorageFailure>
runProbes()
Section titled “runProbes()”function runProbes( retrieval, probes, options?): Effect<readonly ProbeResult[], StorageFailure>;Run every probe through the real retrieval service.
includeArchived stays false. The corpus carries an archived tier and an archived memory must not
be a candidate, so a probe that ranked one would be reporting a scope leak rather than a ranking
failure. The controls are ACTIVE files, which is what makes them adversaries.
Parameters
Section titled “Parameters”retrieval
Section titled “retrieval”RetrievalShape
probes
Section titled “probes”readonly Probe[]
options?
Section titled “options?”limit?
Section titled “limit?”number
Returns
Section titled “Returns”Effect<readonly ProbeResult[], StorageFailure>
summarize()
Section titled “summarize()”function summarize( mode, results, mrrFloor?): DiscriminationReport;Aggregate probe results into the report the gate reads.
An empty suite is a FAILURE, not a vacuous pass. Zero probes yields mrr: 0, which is below any
floor, so a corpus whose probe generation produced nothing refuses instead of reporting a green gate
over no measurement. A skipped quality gate must not look like a passing one, and “no probes ran” is
the purest form of skipped.
Parameters
Section titled “Parameters”results
Section titled “results”readonly ProbeResult[]
mrrFloor?
Section titled “mrrFloor?”number = MRR_FLOOR
Returns
Section titled “Returns”variantFlip()
Section titled “variantFlip()”function variantFlip( claim, anchor, qualifier): string;The claim with a variant qualifier inserted after anchor.
qualifier must be a token @memhtml/domain’s VARIANT_QUALIFIERS knows, or the pair is not
variant-divergent and deriveControl refuses it. Total, so an absent anchor appends a
scope sentence naming the qualifier. That states a different fact about a different variant
instead of a paraphrase.
Parameters
Section titled “Parameters”string
anchor
Section titled “anchor”string
qualifier
Section titled “qualifier”string
Returns
Section titled “Returns”string
wholeText()
Section titled “wholeText()”function wholeText(text): string;The whole text one memory contributes, claim first. What the veto predicates compare.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”string
withStack()
Section titled “withStack()”function withStack<A, E, R>(body, options?): Effect<A, E, R>;Build the stack, run body, then tear both down.
A scoped helper rather than a fixture the caller assembles, so the temp tree is removed on the
failure path too. An eval that exits 1 on an inversion must not leave a 200-file corpus under
/tmp every time the gate refuses.
Type Parameters
Section titled “Type Parameters”A
E
R
Parameters
Section titled “Parameters”(stack) => Effect<A, E, R>
options?
Section titled “options?”StackOptions = {}
Returns
Section titled “Returns”Effect<A, E, R>
writeCorpus()
Section titled “writeCorpus()”function writeCorpus( root, git, spec): Effect<number>;Generate the corpus into root, committing it.
ONE commit for the whole corpus. A commit per memory would make the fixture’s git history the
dominant cost of every eval run. The gate is about ranking, and git log over a generated corpus
tells a reader nothing.
Parameters
Section titled “Parameters”string
GitShape
Returns
Section titled “Returns”Effect<number>