Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

feat(feedback): off by default (opt-in, explicit ratings only) per the held-out verdict; post-upgrade notice

garrytan1cb0e15ccc36
diff --git a/docs/guides/retrieval-feedback.md b/docs/guides/retrieval-feedback.md
index af89a9811c..d6d2ad3bf9 100644
--- a/docs/guides/retrieval-feedback.md
+++ b/docs/guides/retrieval-feedback.md
@@ -6,6 +6,15 @@ and the revision of each page it read. When your agent rates an answer, the
weights of those pages move a little, and later searches rank them up or down.
It costs no LLM calls: a rating is a small database update.
+Retrieval feedback is **off by default**. Turn it on with
+`gbrain config set feedback.enabled true`; ratings are then explicit only, and
+`gbrain config set feedback.implicit true` also learns from `think` citations.
+Held-out tests with consistent ratings showed a gain on entity-centric brains
+(people, companies, deals: +2.0 NDCG@10, CI [+1.0, +3.3]) and no gain on
+chat-history brains (−0.1, CI [−1.0, +0.6]); results:
+[`docs/eval/decisions/p3-retrieval-feedback/VERDICTS.md`](../eval/decisions/p3-retrieval-feedback/VERDICTS.md).
+
+**Say to your agent:** *"Turn on retrieval feedback for this brain."*
**Say to your agent:** *"That last answer used the wrong page; rate it down."*
**Say to your agent:** *"The second page was the one that helped. Tell the brain."*
**Say to your agent:** *"Show me which pages the brain has learned to distrust."*
@@ -25,7 +34,7 @@ It costs no LLM calls: a rating is a small database update.
the fused score. A brain with no ratings ranks exactly as before.
- When `think` or `synthesize` produces a real answer for the brain owner
(CLI or stdio MCP), each cited page counts as a rating of 4 at half the
- learning rate (`feedback.implicit`). Uncited pages are left alone.
+ learning rate (`feedback.implicit`, off by default). Uncited pages are left alone.
- A rating applies only to the revision the answer read. If the page changed
since, that page is skipped (`stale_revision`): a corrected page is never
penalized for its old text. A page edited after it was rated reads at half
@@ -71,16 +80,17 @@ an answer: fix the page itself when it is wrong.
gbrain feedback status # counts, weight spread, lowest-weighted pages with a next step
gbrain feedback reset --page notes/old-renewal-plan
gbrain feedback reset --source default
+gbrain config set feedback.enabled true # on (default off): recording, ratings and the ranking effect
gbrain config set feedback.enabled false # off: no recording, no ratings, no ranking effect
gbrain config set feedback.learn false # keep learned weights, stop learning
```
| Key | Default | Meaning |
|---|---|---|
-| `feedback.enabled` | true | Recording, ratings, `answer_id` and the ranking effect. |
+| `feedback.enabled` | false | Recording, ratings, `answer_id` and the ranking effect. |
| `feedback.learn` | true | Write new learning. Off keeps applying learned weights. |
| `feedback.influence` | 0.1 | λ: the ranking multiplier stays within `[1 - λ, 1 + λ]` (max 0.5). |
-| `feedback.implicit` | true | Learn from `think`/`synthesize` citations for the brain owner. |
+| `feedback.implicit` | false | Learn from `think`/`synthesize` citations for the brain owner. |
| `feedback.alpha` | 0.1 | Learning rate; the citation signal uses half. |
| `feedback.max_ratings_per_hour` | 120 | Rating calls per client per hour. |
| `feedback.event_retention_days` | 30 | How long answers stay rateable. |
diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.ts
index 225fa5026b..68bfae03f4 100644
--- a/src/commands/upgrade.ts
+++ b/src/commands/upgrade.ts
@@ -699,6 +699,7 @@ export async function runPostUpgrade(args: string[] = []): Promise<void> {
// #5876: auto_chronicle now defaults on; one-shot [AGENT] cost + opt-out notice, best-effort.
await (await import('../core/chronicle/upgrade-notice.ts')).printAutoChronicleUpgradeNotice(engine);
+ await (await import('../core/feedback/upgrade-notice.ts')).printRetrievalFeedbackUpgradeNotice(engine);
// Ambient-writeback consent ask (WP8): one-shot for EXISTING installs
// upgrading into the feature. Personal brains only; double-gated on
diff --git a/src/core/config.ts b/src/core/config.ts
index 638f952097..64ba3247d2 100644
--- a/src/core/config.ts
+++ b/src/core/config.ts
@@ -1316,7 +1316,7 @@ export const KNOWN_CONFIG_KEYS: readonly string[] = [
'search.track_retrieval',
// Retrieval feedback (feedback/settings.ts).
'feedback.enabled', 'feedback.learn', 'feedback.influence', 'feedback.implicit', 'feedback.alpha',
- 'feedback.max_ratings_per_hour', 'feedback.event_retention_days', 'feedback.rating_prompt',
+ 'feedback.max_ratings_per_hour', 'feedback.event_retention_days', 'feedback.rating_prompt', 'feedback.notice_shown',
// #4415: per-brain query-intent pattern extensions (JSON bank→regex[]),
// merged over the shipped banks in src/core/search/query-intent.ts.
'search.intent_patterns',
diff --git a/src/core/feedback/settings.ts b/src/core/feedback/settings.ts
index 75e84c3f99..3c0b6aaece 100644
--- a/src/core/feedback/settings.ts
+++ b/src/core/feedback/settings.ts
@@ -22,10 +22,10 @@ export interface FeedbackSettings {
}
export const FEEDBACK_DEFAULTS: FeedbackSettings = Object.freeze({
- enabled: true,
+ enabled: false,
learn: true,
influence: 0.1,
- implicit: true,
+ implicit: false,
alpha: 0.1,
maxRatingsPerHour: 120,
eventRetentionDays: 30,
diff --git a/src/core/feedback/upgrade-notice.ts b/src/core/feedback/upgrade-notice.ts
new file mode 100644
index 0000000000..f7a4ccfc1e
--- /dev/null
+++ b/src/core/feedback/upgrade-notice.ts
@@ -0,0 +1,51 @@
+// One-shot post-upgrade notice for retrieval feedback. The feature ships off; the notice says what it does,
+// how to turn it on, and what held-out results showed. Printed by `gbrain post-upgrade` once, and not at all when
+// the operator already set `feedback.enabled`.
+import type { BrainEngine } from '../engine.ts';
+import { agentBlock } from '../agent-markers.ts';
+
+export const FEEDBACK_NOTICE_SHOWN_KEY = 'feedback.notice_shown';
+export const FEEDBACK_ENABLE_ARGV = ['gbrain', 'config', 'set', 'feedback.enabled', 'true'] as const;
+
+export async function retrievalFeedbackUpgradeNotice(engine: BrainEngine): Promise<string[] | null> {
+ const shown = await engine.getConfig(FEEDBACK_NOTICE_SHOWN_KEY);
+ if (shown != null && shown.trim() !== '') return null;
+ if ((await engine.getConfig('feedback.enabled')) != null) return null;
+ return [
+ '',
+ '═══════════════════════════════════════════════════════════════',
+ '[gbrain] Retrieval feedback is available and OFF. When on, an agent can rate',
+ '[gbrain] an answer (rate_answer / gbrain rate) and the pages it used rank a',
+ '[gbrain] little higher or lower next time. No model call, local only.',
+ '═══════════════════════════════════════════════════════════════',
+ ...agentBlock({
+ ask: 'Turn on retrieval feedback for this brain?',
+ why: 'When on, every answer carries an answer_id; rating it 1-5 nudges the ranking of the pages and links that answer used (a capped ' +
+ 'multiplier, 0.9x to 1.1x by default; `search --explain` shows it). Held-out tests with consistent ratings showed a gain on entity-centric brains ' +
+ '(people, companies, deals: +2.0 NDCG@10) and no gain on chat-history brains, so it ships off. Nothing leaves the machine.',
+ consent: 'none',
+ actor: 'user',
+ next: 'ask_user',
+ if_yes: `Run ${FEEDBACK_ENABLE_ARGV.join(' ')}. Guide: docs/guides/retrieval-feedback.md`,
+ if_no: 'Nothing to run; it stays off.',
+ verify: 'gbrain feedback status --json',
+ }, {
+ showUser: 'GBrain can learn which pages actually helped when you or your agent rate answers. It is off by default: it helped on ' +
+ 'brains about people and companies but not on chat-history brains. Turn it on?',
+ }).trimEnd().split('\n'),
+ '',
+ ];
+}
+
+/** Prints the notice once and stamps it. Best-effort: never blocks the upgrade. */
+export async function printRetrievalFeedbackUpgradeNotice(engine: BrainEngine, log: (line: string) => void = console.log): Promise<boolean> {
+ try {
+ const lines = await retrievalFeedbackUpgradeNotice(engine);
+ if (!lines) return false;
+ for (const line of lines) log(line);
+ await engine.setConfig(FEEDBACK_NOTICE_SHOWN_KEY, new Date().toISOString());
+ return true;
+ } catch {
+ return false;
+ }
+}
diff --git a/test/e2e/feedback-parity.test.ts b/test/e2e/feedback-parity.test.ts
index d9dd121c0e..f7bf40a129 100644
--- a/test/e2e/feedback-parity.test.ts
+++ b/test/e2e/feedback-parity.test.ts
@@ -35,6 +35,7 @@ for (const kind of ['pglite', 'postgres'] as const) {
'SELECT content_hash FROM pages WHERE slug = $1 AND source_id = $2', [slug, SOURCE]);
hashes.set(slug, row!.content_hash);
}
+ await engine.setConfig('feedback.enabled', 'true');
_resetFeedbackSettingsCacheForTests();
}, 60_000);
diff --git a/test/feedback-boost.test.ts b/test/feedback-boost.test.ts
index 6a102182ba..1811a0294e 100644
--- a/test/feedback-boost.test.ts
+++ b/test/feedback-boost.test.ts
@@ -51,6 +51,7 @@ afterAll(async () => {
beforeEach(async () => {
await engine.executeRaw('DELETE FROM retrieval_weights');
await engine.executeRaw('DELETE FROM config WHERE key LIKE $1', ['feedback.%']);
+ await engine.setConfig('feedback.enabled', 'true');
_resetFeedbackSettingsCacheForTests();
});
diff --git a/test/feedback-cli-loop.serial.test.ts b/test/feedback-cli-loop.serial.test.ts
index 1cca77d95c..3bd57d99f1 100644
--- a/test/feedback-cli-loop.serial.test.ts
+++ b/test/feedback-cli-loop.serial.test.ts
@@ -1,6 +1,6 @@
/**
- * Retrieval feedback through the real CLI on a keyless PGLite brain:
- * search prints an answer id, `gbrain rate` records the rating, and the next
+ * Retrieval feedback through the real CLI on a keyless PGLite brain: off by
+ * default (no answer id); once enabled, search prints an answer id, `gbrain rate` records the rating, and the next
* `search --explain` shows the feedback multiplier on the rated pages.
*
* Serial: spawns the CLI against a temporary GBRAIN_HOME.
@@ -33,6 +33,11 @@ afterAll(() => {
});
test('search → rate → search --explain shows the learned boost', async () => {
+ const off = await cli(['search', 'widget', '--json']);
+ expect(off.exitCode).toBe(0);
+ expect(off.stdout).not.toContain('answer_id');
+ expect((await cli(['config', 'set', 'feedback.enabled', 'true'])).exitCode).toBe(0);
+
const before = await cli(['search', 'widget', '--explain']);
expect(before.exitCode).toBe(0);
expect(before.stdout).not.toContain('feedback ×');
diff --git a/test/feedback-store.test.ts b/test/feedback-store.test.ts
index 9ebb48a70b..7e498cdc74 100644
--- a/test/feedback-store.test.ts
+++ b/test/feedback-store.test.ts
@@ -14,6 +14,7 @@ import {
} from '../src/core/feedback/record.ts';
import { __listDrainerNamesForTest } from '../src/core/background-work.ts';
import { _resetFeedbackSettingsCacheForTests } from '../src/core/feedback/settings.ts';
+import { retrievalFeedbackUpgradeNotice } from '../src/core/feedback/upgrade-notice.ts';
let engine: PGLiteEngine;
@@ -55,10 +56,24 @@ beforeEach(async () => {
await engine.executeRaw('DELETE FROM retrieval_weights');
await engine.executeRaw('DELETE FROM retrieval_events');
await engine.executeRaw('DELETE FROM config WHERE key LIKE $1', ['feedback.%']);
+ await engine.setConfig('feedback.enabled', 'true');
+ await engine.setConfig('feedback.implicit', 'true');
_resetFeedbackSettingsCacheForTests();
_resetFeedbackRecordingForTests();
});
+describe('defaults', () => {
+ test('a brain that never set feedback.enabled records nothing and returns no answer id', async () => {
+ await engine.executeRaw('DELETE FROM config WHERE key LIKE $1', ['feedback.%']);
+ _resetFeedbackSettingsCacheForTests();
+ expect(await recordAnswer(localCtx(), { op: 'query', pages: [{ slug: 'people/alice-example' }] })).toBeNull();
+ const notice = await retrievalFeedbackUpgradeNotice(engine);
+ expect(notice?.join('\n')).toContain('gbrain config set feedback.enabled true');
+ await engine.setConfig('feedback.enabled', 'false');
+ expect(await retrievalFeedbackUpgradeNotice(engine)).toBeNull();
+ });
+});
+
describe('answer ids', () => {
test('mint and decode the timestamp', () => {
const now = 1_790_000_000_000;