{"record":{"id":"9493251dcdad641e","repo":"ruvnet/ruflo","slug":"embedding-failed","errorCode":null,"errorMessage":"embedding failed","messagePattern":"embedding failed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/mcp-tools/agentdb-tools.ts","lineNumber":1126,"sourceCode":"            return {\n              success: true, mode, nodeId, depth,\n              results: rows.map((r: unknown[]) => ({ nodeId: r[0], depth: r[1] })),\n              count: rows.length,\n              backend: 'sql-cte',\n              elapsedMs: Date.now() - t0,\n            };\n          }\n        } catch { /* db unavailable */ }\n\n        return { success: false, error: 'No graph backend available for k-hop query', mode, nodeId };\n      }\n\n      // ── semantic mode ────────────────────────────────────────────────────────\n      if (mode === 'semantic') {\n        try {\n          const { generateEmbedding } = await getMemInit();\n          const queryEmb = await generateEmbedding(nodeId);\n          if (!queryEmb) throw new Error('embedding failed');\n\n          const { getBridgeDb } = await getGraphEdgeWriter();\n          // #2246 fix: lazy-create memory.db on first pathfinder call so\n          // fresh environments work without a pre-existing memory init.\n          const db = await getBridgeDb(undefined, { createIfMissing: true });\n          if (!db) return { success: false, error: 'graph_edges DB unavailable (sql.js could not load)', hint: 'Check Node version + try `ruflo memory init` to initialize manually.', mode, nodeId };\n\n          // Load all rows with embedding_ref and score by cosine.\n          // better-sqlite3 API — `db.exec(sql, params)` (sql.js) silently\n          // throws \"datatype mismatch\" because exec ignores params, so `?`\n          // binds to nothing and SQLite rejects the LIMIT clause.\n          const rows = db.prepare(\n            `SELECT id, source_id, target_id, relation, weight, embedding_ref FROM graph_edges WHERE embedding_ref IS NOT NULL LIMIT ?`,\n          ).raw().all(budget.maxNodesVisited) as unknown[][];\n          const { decodeEmbedding } = await getEmbQuant();\n\n          const scored: Array<{ nodeId: string; score: number; relation: string }> = [];\n          const qv = new Float32Array(queryEmb.embedding);","sourceCodeStart":1108,"sourceCodeEnd":1144,"githubUrl":"https://github.com/ruvnet/ruflo/blob/2602b642d92234c710ffbe96bfb33007d481ceab/v3/@claude-flow/cli/src/mcp-tools/agentdb-tools.ts#L1108-L1144","documentation":"In the agentdb pathfinder tool's semantic mode, the query node id is embedded via generateEmbedding() (memory-initializer.ts:2395); if the call returns a falsy vector the tool throws 'embedding failed'. generateEmbedding first tries the AgentDB v3 bridge, then the local ONNX chain — a falsy result means both backend paths failed to produce a vector, so semantic scoring cannot proceed.","triggerScenarios":"Running pathfinder with mode:'semantic' in a fresh environment where memory was never initialized (`ruflo memory init` not run, memory.db absent); the ONNX runtime failing to load on an unsupported Node version; the AgentDB bridge present but its embedder returning nothing (degraded/stubbed); huge or binary-garbage nodeId input breaking the embedder.","commonSituations":"First semantic query after clone/CI boot with no memory init; Node runtime mismatches breaking native ONNX bindings (the neighboring code hints 'Check Node version + try ruflo memory init'); environments where AgentDB is installed but its model assets are missing.","solutions":["Initialize the embedding store: `npx @claude-flow/cli@latest memory init` (or `ruflo memory init`), then retry the semantic query","Verify the Node version meets the runtime requirement (Node 20+ per doctor) so the ONNX/native chain loads","Fall back to graph mode — call the same pathfinder with mode 'graph' (or k-hop) which does not need embeddings","Check that nodeId is a sensible text identifier, not binary or empty content that the embedder chokes on"],"exampleFix":"// before — semantic mode in a fresh environment\nawait callMCPTool('agentdb_pathfinder', { mode: 'semantic', nodeId: 'auth-service' });\n// throws: embedding failed\n\n// after — init once, retry; degrade to graph mode on failure\nawait exec('npx @claude-flow/cli@latest memory init');\ntry {\n  await callMCPTool('agentdb_pathfinder', { mode: 'semantic', nodeId: 'auth-service' });\n} catch {\n  await callMCPTool('agentdb_pathfinder', { mode: 'graph', nodeId: 'auth-service' });\n}","handlingStrategy":"fallback","validationCode":"import { generateEmbedding } from './memory/memory-initializer';\n\n// Probe the embedding backend before offering semantic mode\nconst probe = await generateEmbedding('healthcheck');\nconst semanticAvailable = Boolean(probe?.embedding?.length);","typeGuard":null,"tryCatchPattern":"try {\n  return await callMCPTool('agentdb_pathfinder', { mode: 'semantic', nodeId });\n} catch (e) {\n  if ((e as Error).message === 'embedding failed') {\n    // embeddings unavailable — degrade to graph traversal, still useful\n    return await callMCPTool('agentdb_pathfinder', { mode: 'graph', nodeId });\n  }\n  throw e;\n}","preventionTips":["Run `memory init` during environment provisioning, not on first query","Smoke-test generateEmbedding at startup and disable semantic features when it returns nothing","Keep a graph-mode fallback path wherever semantic search is optional","Verify Node version (20+) so the ONNX/native chain loads"],"tags":["agentdb","embeddings","semantic-search","pathfinder","onnx","memory-init"],"backgroundTag":"embedding-generation-failed","analyzedSha":"2602b642d92234c710ffbe96bfb33007d481ceab","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}