Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

feat(doctor): fact_admission_floors says when the cosine floors are unmeasured (#6590)

time-attackca6fced9560f
diff --git a/src/commands/doctor/checks/fact-admission-floors.ts b/src/commands/doctor/checks/fact-admission-floors.ts
new file mode 100644
index 0000000000..a4f95a02c1
--- /dev/null
+++ b/src/commands/doctor/checks/fact-admission-floors.ts
@@ -0,0 +1,49 @@
+/**
+ * fact_admission_floors (informational, #6590): whether the brain's embedding
+ * model has a measured cosine floor for fact admission. `recall --question`
+ * and `query`'s facts arm admit a fact on similarity alone at the absolute
+ * floors in `search/fact-relevance.ts` (0.5 for the `reserve` rule, 0.6 for
+ * the facts arm). Those floors depend on the model's cosine scale, and no
+ * model has a measured floor yet, so on a high-baseline embedder an unrelated
+ * question clears them and an empty facts list stops meaning "nothing
+ * matched". Always status ok: it says how far to trust an empty list.
+ */
+import type { Check } from '../../doctor.ts';
+import { connectedEngine, type DoctorContext, type DoctorEntry } from '../context.ts';
+import { embeddingsDisabled } from '../../../core/embedding-disabled.ts';
+import { calibrationKey } from '../../../core/facts/supersession-threshold.ts';
+import { FACTS_ARM_COSINE_MIN, RESERVE_COSINE_MIN } from '../../../core/search/fact-relevance.ts';
+
+/** Embedding models whose admission floors an eval measured, keyed `provider:model@dims`. Add a row only with an eval behind it. */
+export const FACT_ADMISSION_FLOOR_EVIDENCE: Readonly<Record<string, string>> = {};
+
+async function runFactAdmissionFloors(ctx: DoctorContext): Promise<Check[]> {
+ const engine = connectedEngine(ctx);
+ ctx.progress.heartbeat('fact_admission_floors');
+ try {
+ if (await embeddingsDisabled(engine)) {
+ return [{ name: 'fact_admission_floors', status: 'ok', severity: 'info', readiness_state: 'not_applicable',
+ message: 'Embeddings are off on this brain, so facts are admitted by keyword and named entity only; no cosine floor applies.' }];
+ }
+ const { getEmbeddingModel, getEmbeddingDimensions } = await import('../../../core/ai/gateway.ts');
+ const key = calibrationKey(getEmbeddingModel(), getEmbeddingDimensions());
+ const evidence = FACT_ADMISSION_FLOOR_EVIDENCE[key];
+ const details = { key, reserve_cosine_min: RESERVE_COSINE_MIN, facts_arm_cosine_min: FACTS_ARM_COSINE_MIN, measured: evidence !== undefined, evidence: evidence ?? null };
+ if (evidence) {
+ return [{ name: 'fact_admission_floors', status: 'ok', details,
+ message: `Fact admission floors (cosine ${RESERVE_COSINE_MIN} for recall questions, ${FACTS_ARM_COSINE_MIN} for the query facts arm) are measured for ${key} (${evidence}).` }];
+ }
+ return [{ name: 'fact_admission_floors', status: 'ok', severity: 'info', readiness_state: 'degraded', details,
+ message: `Fact admission floors (cosine ${RESERVE_COSINE_MIN} for recall questions, ${FACTS_ARM_COSINE_MIN} for the query facts arm) are not measured for ${key}. `
+ + 'If this model scores unrelated text high, recall --question can return facts for a question nothing answers, so an empty facts list is the reliable signal only on a measured model.' }];
+ } catch (error) {
+ return [{ name: 'fact_admission_floors', status: 'ok', severity: 'info', readiness_state: 'unknown',
+ message: `Could not resolve the embedding model for the fact admission floors: ${error instanceof Error ? error.message : String(error)}.` }];
+ }
+}
+
+export const factAdmissionFloorsEntry: DoctorEntry = {
+ name: 'fact_admission_floors',
+ emits: ['fact_admission_floors'],
+ run: runFactAdmissionFloors,
+};
diff --git a/src/commands/doctor/registry.ts b/src/commands/doctor/registry.ts
index ac05f20cde..bf38459405 100644
--- a/src/commands/doctor/registry.ts
+++ b/src/commands/doctor/registry.ts
@@ -95,6 +95,7 @@ import { factsDrainEntry } from './checks/facts-drain.ts';
import { factTakeVectorsEntry } from './checks/vector-coverage.ts';
import { decideHealthEntry } from './checks/decide.ts';
import { supersessionCalibrationEntry } from './checks/supersession-calibration.ts';
+import { factAdmissionFloorsEntry } from './checks/fact-admission-floors.ts';
import { unlinkedFactsEntry } from './checks/unlinked-facts.ts';
import { edgeValidityEntry } from './checks/edge-validity.ts';
import { coreMemoryEntry } from './checks/core-memory.ts';
@@ -170,6 +171,7 @@ export const DOCTOR_CHECK_REGISTRY: readonly DoctorEntry[] = [
embeddingColumnRegistryEntry,
embeddingEnvOverrideEntry,
supersessionCalibrationEntry,
+ factAdmissionFloorsEntry,
chatFallbackChainEntry,
behaviorChangesEntry,
graphCoverageEntry,
diff --git a/src/core/doctor-categories.ts b/src/core/doctor-categories.ts
index b9c28f123c..7b1eea81c6 100644
--- a/src/core/doctor-categories.ts
+++ b/src/core/doctor-categories.ts
@@ -166,6 +166,8 @@ export const BRAIN_CHECK_NAMES: ReadonlySet<string> = new Set([
'stub_guard_24h',
// Fact supersession threshold calibrated for the active embedding model (facts/supersession-threshold.ts).
'supersession_calibration',
+ // #6590: whether the embedding model has measured fact admission cosine floors (search/fact-relevance.ts).
+ 'fact_admission_floors',
'sync_failures',
// #5984: unfinished managed sync cursors, their remaining entries and indexing ETA.
'managed_sync_backlog',
diff --git a/test/doctor-fact-admission-floors.test.ts b/test/doctor-fact-admission-floors.test.ts
new file mode 100644
index 0000000000..5fec7b232a
--- /dev/null
+++ b/test/doctor-fact-admission-floors.test.ts
@@ -0,0 +1,47 @@
+/**
+ * fact_admission_floors doctor check (#6590): informational, names the
+ * embedding model and the shared floors, never claims a measured floor for a
+ * model without an eval, and is not applicable on a keyless brain. PGLite ($0).
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { configureGateway, resetGateway } from '../src/core/ai/gateway.ts';
+import { factAdmissionFloorsEntry } from '../src/commands/doctor/checks/fact-admission-floors.ts';
+import { FACT_COSINE_MIN } from '../src/core/search/facts-arm.ts';
+import { FACTS_ARM_COSINE_MIN } from '../src/core/search/fact-relevance.ts';
+import { categorizeCheck } from '../src/core/doctor-categories.ts';
+import type { Check } from '../src/commands/doctor.ts';
+
+let engine: PGLiteEngine;
+const run = async () => (await factAdmissionFloorsEntry.run({ engine, progress: { heartbeat() {} } } as never) as Check[])[0];
+
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+}, 60_000);
+
+afterAll(async () => {
+ await engine.disconnect();
+ resetGateway();
+}, 60_000);
+
+describe('fact_admission_floors (#6590)', () => {
+ test('an unmeasured model is informational and names the model and both floors', async () => {
+ configureGateway({ embedding_model: 'llama-server:embeddinggemma-2', embedding_dimensions: 768, env: {} });
+ const check = await run();
+ expect(check).toMatchObject({ name: 'fact_admission_floors', status: 'ok', severity: 'info', readiness_state: 'degraded',
+ details: { key: 'llama-server:embeddinggemma-2@768', reserve_cosine_min: 0.5, facts_arm_cosine_min: 0.6, measured: false } });
+ expect(check.message).toContain('not measured for llama-server:embeddinggemma-2@768');
+ expect(categorizeCheck('fact_admission_floors')).toBe('brain');
+ });
+
+ test('the default model is not claimed as measured without an eval', async () => {
+ configureGateway({ embedding_model: 'voyage:voyage-4', embedding_dimensions: 1024, env: { VOYAGE_API_KEY: 'k' } });
+ expect((await run()).details).toMatchObject({ key: 'voyage:voyage-4@1024', measured: false, evidence: null });
+ });
+
+ test('the query facts arm and the facts_arm admission rule share one floor', () => {
+ expect(FACT_COSINE_MIN).toBe(FACTS_ARM_COSINE_MIN);
+ });
+});