ruvnet/ruflo · error · Error

embedding failed

Error message

embedding failed

What it means

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.

Solutions

  1. Initialize the embedding store: `npx @claude-flow/cli@latest memory init` (or `ruflo memory init`), then retry the semantic query
  2. Verify the Node version meets the runtime requirement (Node 20+ per doctor) so the ONNX/native chain loads
  3. Fall back to graph mode — call the same pathfinder with mode 'graph' (or k-hop) which does not need embeddings
  4. Check that nodeId is a sensible text identifier, not binary or empty content that the embedder chokes on

Example fix

// before — semantic mode in a fresh environment
await callMCPTool('agentdb_pathfinder', { mode: 'semantic', nodeId: 'auth-service' });
// throws: embedding failed

// after — init once, retry; degrade to graph mode on failure
await exec('npx @claude-flow/cli@latest memory init');
try {
  await callMCPTool('agentdb_pathfinder', { mode: 'semantic', nodeId: 'auth-service' });
} catch {
  await callMCPTool('agentdb_pathfinder', { mode: 'graph', nodeId: 'auth-service' });
}
Defensive patterns

Strategy: fallback

Validate before calling

import { generateEmbedding } from './memory/memory-initializer';

// Probe the embedding backend before offering semantic mode
const probe = await generateEmbedding('healthcheck');
const semanticAvailable = Boolean(probe?.embedding?.length);

Try / catch

try {
  return await callMCPTool('agentdb_pathfinder', { mode: 'semantic', nodeId });
} catch (e) {
  if ((e as Error).message === 'embedding failed') {
    // embeddings unavailable — degrade to graph traversal, still useful
    return await callMCPTool('agentdb_pathfinder', { mode: 'graph', nodeId });
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of ruvnet/ruflo@2602b642d9 (2026-08-18). Data as JSON: /api/errors/9493251dcdad641e. Report an issue: GitHub.

Appendix: source

Thrown at v3/@claude-flow/cli/src/mcp-tools/agentdb-tools.ts:1126

            return {
              success: true, mode, nodeId, depth,
              results: rows.map((r: unknown[]) => ({ nodeId: r[0], depth: r[1] })),
              count: rows.length,
              backend: 'sql-cte',
              elapsedMs: Date.now() - t0,
            };
          }
        } catch { /* db unavailable */ }

        return { success: false, error: 'No graph backend available for k-hop query', mode, nodeId };
      }

      // ── semantic mode ────────────────────────────────────────────────────────
      if (mode === 'semantic') {
        try {
          const { generateEmbedding } = await getMemInit();
          const queryEmb = await generateEmbedding(nodeId);
          if (!queryEmb) throw new Error('embedding failed');

          const { getBridgeDb } = await getGraphEdgeWriter();
          // #2246 fix: lazy-create memory.db on first pathfinder call so
          // fresh environments work without a pre-existing memory init.
          const db = await getBridgeDb(undefined, { createIfMissing: true });
          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 };

          // Load all rows with embedding_ref and score by cosine.
          // better-sqlite3 API — `db.exec(sql, params)` (sql.js) silently
          // throws "datatype mismatch" because exec ignores params, so `?`
          // binds to nothing and SQLite rejects the LIMIT clause.
          const rows = db.prepare(
            `SELECT id, source_id, target_id, relation, weight, embedding_ref FROM graph_edges WHERE embedding_ref IS NOT NULL LIMIT ?`,
          ).raw().all(budget.maxNodesVisited) as unknown[][];
          const { decodeEmbedding } = await getEmbQuant();

          const scored: Array<{ nodeId: string; score: number; relation: string }> = [];
          const qv = new Float32Array(queryEmb.embedding);

View on GitHub (pinned to 2602b642d9)