Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

recall: read both switches through named key constants so the config-reader guard resolves them

garrytan582e96e3a8a8
diff --git a/src/core/facts/question-recall.ts b/src/core/facts/question-recall.ts
index 5aad142751..e3dba0445f 100644
--- a/src/core/facts/question-recall.ts
+++ b/src/core/facts/question-recall.ts
@@ -27,7 +27,7 @@ import {
type FactPoolFilters, type FactPoolScope, type QuestionAdmissionRule,
} from '../search/fact-relevance.ts';
import { confidenceFactor, recallConfidence } from './decay.ts';
-import { CONFIDENCE_WEIGHTING_KEY, GROUP_BY_ENTITY_KEY, recallSwitchOn } from './recall-config.ts';
+import { readRecallSwitches } from './recall-config.ts';
export const QUESTION_MAX_CHARS = 2000;
/** Candidates per arm, separate from the output `limit`. */
@@ -214,16 +214,17 @@ export async function rankFactsByQuestion(ctx: OperationContext, input: Question
const { embedding, reason } = await questionEmbedding(ctx, question);
if (!embedding && queryTerms(question).length === 0) return empty({ reason: 'no_query_terms' });
try {
- const [pool, uncomparable, rule, weighted, grouped] = await Promise.all([
+ const [pool, uncomparable, rule, switches] = await Promise.all([
collectFactCandidates(ctx.engine, question, scope, embedding, {
depth: { keyword: QUESTION_POOL_DEPTH, cosine: QUESTION_POOL_DEPTH, entity: QUESTION_POOL_DEPTH }, filters, cosineForAll: true,
hnswIterativeScan: resolveHnswIterativeScan(ctx.config),
}),
embedding ? countUncomparableFacts(ctx.engine, scope, filters, embedding.length) : [],
admissionRule(ctx.engine),
- recallSwitchOn(ctx.engine, CONFIDENCE_WEIGHTING_KEY),
- input.entity ? false : recallSwitchOn(ctx.engine, GROUP_BY_ENTITY_KEY),
+ readRecallSwitches(ctx.engine),
]);
+ const weighted = switches.weighting;
+ const grouped = switches.grouping && !input.entity;
const ranked = scoreFactCandidates(question, pool.candidates).filter(s => admitted(s, rule));
const unembedded = uncomparable.reduce((n, r) => n + r.n, 0);
const why = reason ?? (embedding && !pool.column ? 'facts_embedding_column_missing' : undefined);
diff --git a/src/core/facts/recall-config.ts b/src/core/facts/recall-config.ts
index a68bd2039e..66fdf20862 100644
--- a/src/core/facts/recall-config.ts
+++ b/src/core/facts/recall-config.ts
@@ -15,10 +15,16 @@ const SWITCH_KEYS: readonly string[] = [CONFIDENCE_WEIGHTING_KEY, GROUP_BY_ENTIT
const ON = ['on', 'true', '1', 'yes'];
const OFF = ['off', 'false', '0', 'no'];
-/** Whether a stored switch value is on; unset, unreadable and unknown values are off. */
-export async function recallSwitchOn(engine: BrainEngine, key: string): Promise<boolean> {
- const raw = (await engine.getConfig(key).catch(() => null))?.trim().toLowerCase();
- return ON.includes(raw ?? '');
+/** Whether a stored switch value is on; unset and unknown values are off. */
+export const recallSwitchOn = (raw: string | null | undefined): boolean => ON.includes(raw?.trim().toLowerCase() ?? '');
+
+/** The two switches, read once per call; an unreadable config reads as off. */
+export async function readRecallSwitches(engine: BrainEngine): Promise<{ weighting: boolean; grouping: boolean }> {
+ const [weighting, grouping] = await Promise.all([
+ engine.getConfig(CONFIDENCE_WEIGHTING_KEY).catch(() => null),
+ engine.getConfig(GROUP_BY_ENTITY_KEY).catch(() => null),
+ ]);
+ return { weighting: recallSwitchOn(weighting), grouping: recallSwitchOn(grouping) };
}
/** Why `value` is not a valid value for a recall key, or null when it is (or the key is not one of these). */