From 04f47445068d688c244bc76777ab7c656e87f906 Mon Sep 17 00:00:00 2001 From: ruv Date: Wed, 17 Jun 2026 19:36:50 -0400 Subject: [PATCH] =?UTF-8?q?fix(memory):=20reject=20128-dim=20bridge=20resu?= =?UTF-8?q?lts=20=E2=80=94=20MCP=20no=20longer=20emits=20mock=20embeddings?= =?UTF-8?q?=20(#2395)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #2395 — MCP `memory_store` emitted persistent 128-dim mock (hash-fallback) embeddings instead of the real 384-dim ONNX embeddings, while the standalone CLI worked correctly. The CLI vs MCP divergence wasted any benefit of vector memory and silently corrupted similarity recall. ROOT CAUSE `bridgeGenerateEmbedding` (v3/@claude-flow/cli/src/memory/memory-bridge.ts) called `embedder.embed(text)` and unconditionally returned the result labeled `model: 'Xenova/all-MiniLM-L6-v2', backend: 'onnx'`. The model name promises 384-dim, but AgentDB's vectorBackend controller may initialize as `enabled: false` (e.g., when ruvector isn't yet wired into its neural substrate) and silently substitute a 128-dim hash stub. The stub doesn't expose `isMock=true`, so the existing `isMock` check let it through with a wrong `'onnx'` label. Downstream `generateEmbedding` saw the non-null bridge result and returned it immediately, skipping the local ONNX chain (transformers.js / ruvector) which DOES produce 384-dim correctly. FIX Add a dimensional sanity check: if `emb.length !== 384`, the bridge result is definitively a stub (the model name we hardcode always produces 384). Return null instead. Caller falls through to `generateLocalEmbedding` which routes via the local ONNX chain. This is conservative: the only behavior change is that a previously- misclassified 128-dim "onnx" path now becomes a 384-dim real-ONNX path (when the local chain has transformers.js or ruvector) OR a clearly-labeled 128-dim hash fallback (when local ONNX also fails). Either way the backend label now matches the actual semantics. Co-Authored-By: RuFlo --- v3/@claude-flow/cli/src/memory/memory-bridge.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/v3/@claude-flow/cli/src/memory/memory-bridge.ts b/v3/@claude-flow/cli/src/memory/memory-bridge.ts index 3fce82ba11..694cee674d 100644 --- a/v3/@claude-flow/cli/src/memory/memory-bridge.ts +++ b/v3/@claude-flow/cli/src/memory/memory-bridge.ts @@ -1191,6 +1191,19 @@ export async function bridgeGenerateEmbedding( const isMock = (embedder as { isMock?: boolean; backend?: string }).isMock === true || (embedder as { backend?: string }).backend === 'mock'; + // #2395 — AgentDB's vectorBackend controller may initialize as + // `enabled: false` (e.g., ruvector isn't wired into its neural substrate + // yet) and silently fall back to a 128-dim hash stub. The embedder doesn't + // expose isMock=true in that path, so the wrapper above was reporting + // backend='onnx' on what's actually 128-dim hash garbage. The model name + // we hardcode ('Xenova/all-MiniLM-L6-v2') always produces 384-dim, so a + // dimensions mismatch is a definitive stub signal: return null and let + // the caller fall through to generateLocalEmbedding which routes to + // transformers.js / ruvector ONNX directly. + if (emb.length !== 384) { + return null; + } + return { embedding: Array.from(emb), dimensions: emb.length,