fix(agent): make the recall reranker opt-in and use the word embedder in tests

The reference-set comparison showed the cross-encoder adds nothing to mem0's
ranking and costs about 130 ms per search.
This commit is contained in:
shumeiko.it
2026-10-24 11:57:18 +02:00
parent 10e67f37a5
commit 2d507dc457
2 changed files with 21 additions and 13 deletions

View File

@@ -78,10 +78,12 @@ export interface OrchestratorConfig {
version?: string; version?: string;
skills?: string[]; skills?: string[];
/** /**
* W4.2: optional cross-encoder reranker injected for tests. When absent, * W4.2: optional cross-encoder reranker injected for tests. When absent and
* a lazy in-process reranker (Xenova/ms-marco-MiniLM-L-6-v2, ~22MB ONNX) * WAGGLE_RERANKER=1, a lazy in-process reranker (Xenova/ms-marco-MiniLM-L-6-v2,
* is created on first recall unless WAGGLE_RERANKER=0; creation failure * ~22MB ONNX) is created on first recall; creation failure soft-fails to the
* soft-fails to the store's own ordering. * store's own ordering. Off by default: on the reference set it did not
* improve mem0's ranking and cost about 130 ms per search
* (docs/oss/research/memory-search-quality.md).
*/ */
reranker?: Reranker; reranker?: Reranker;
/** Optional managed cache root for the lazy in-process reranker model. */ /** Optional managed cache root for the lazy in-process reranker model. */
@@ -366,14 +368,14 @@ export class Orchestrator {
} }
/** /**
* W4.2/W4.5: lazy cross-encoder reranker — default on. Kill switch: * W4.2: lazy cross-encoder reranker, opt-in with WAGGLE_RERANKER=1. First use
* WAGGLE_RERANKER=0. First use downloads the ~22MB model (cached at the * downloads the ~22MB model (cached at the configured managed path); creation
* configured managed path); creation failure (offline, OOM) memoizes * failure (offline, OOM) memoizes undefined: recall soft-fails to the store's
* undefined: recall soft-fails to the store's ordering, never throws. * ordering, never throws.
*/ */
private getReranker(): Promise<Reranker | undefined> { private getReranker(): Promise<Reranker | undefined> {
if (this.rerankerPromise) return this.rerankerPromise; if (this.rerankerPromise) return this.rerankerPromise;
if (process.env['WAGGLE_RERANKER'] === '0') { if (process.env['WAGGLE_RERANKER'] !== '1') {
this.rerankerPromise = Promise.resolve(undefined); this.rerankerPromise = Promise.resolve(undefined);
return this.rerankerPromise; return this.rerankerPromise;
} }

View File

@@ -28,14 +28,20 @@ if (!process.env.WAGGLE_PHASE5_CANARY_PCT) {
process.env.WAGGLE_PHASE5_CANARY_PCT = '0'; process.env.WAGGLE_PHASE5_CANARY_PCT = '0';
} }
// W4.5: the cross-encoder reranker is default-ON in production (kill switch // The cross-encoder reranker is opt-in (WAGGLE_RERANKER=1). Tests pin it
// WAGGLE_RERANKER=0). Tests pin it OFF — the real ONNX model is a ~22MB // OFF explicitly; tests that exercise reranking inject a mock Reranker via
// download + per-call CPU inference, both unwanted in unit suites. Tests // OrchestratorConfig.
// that exercise reranking inject a mock Reranker via OrchestratorConfig.
if (!process.env.WAGGLE_RERANKER) { if (!process.env.WAGGLE_RERANKER) {
process.env.WAGGLE_RERANKER = '0'; process.env.WAGGLE_RERANKER = '0';
} }
// Memory (ADR-0007): the sidecar embeds memories with an in-process model
// that is a ~90MB download. Tests use the deterministic word embedder, which
// needs no model and no network.
if (!process.env.WAGGLE_MEMORY_EMBEDDER) {
process.env.WAGGLE_MEMORY_EMBEDDER = 'words';
}
// W4 (2026-06-11): the PromptAssembler is default-ON in production (kill // W4 (2026-06-11): the PromptAssembler is default-ON in production (kill
// switch WAGGLE_PROMPT_ASSEMBLER=0) after the live chat smoke. Tests pin it // switch WAGGLE_PROMPT_ASSEMBLER=0) after the live chat smoke. Tests pin it
// OFF so the broad chat-route suite keeps exercising the stable legacy // OFF so the broad chat-route suite keeps exercising the stable legacy