{"record":{"id":"989141eb4b25b56d","repo":"ruvnet/ruflo","slug":"must-provide-name-and-embeddings-array","errorCode":null,"errorMessage":"Must provide name and embeddings array","messagePattern":"Must provide name and embeddings array","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/ruvector/semantic-router.ts","lineNumber":56,"sourceCode":"\n  constructor(config: RouterConfig) {\n    if (!config || typeof config.dimension !== 'number') {\n      throw new Error('SemanticRouter requires a dimension in config');\n    }\n    this.dimension = config.dimension;\n    this.metric = config.metric ?? 'cosine';\n  }\n\n  /**\n   * Add an intent with pre-computed embeddings\n   */\n  addIntentWithEmbeddings(\n    name: string,\n    embeddings: Float32Array[],\n    metadata: Record<string, unknown> = {}\n  ): void {\n    if (!name || !Array.isArray(embeddings)) {\n      throw new Error('Must provide name and embeddings array');\n    }\n\n    // Validate embeddings\n    for (const emb of embeddings) {\n      if (!(emb instanceof Float32Array) || emb.length !== this.dimension) {\n        throw new Error(`Embedding must be Float32Array of length ${this.dimension}`);\n      }\n    }\n\n    // Normalize embeddings for cosine similarity\n    const normalizedEmbeddings = embeddings.map(emb => this.normalize(emb));\n\n    this.intents.set(name, {\n      name,\n      embeddings: normalizedEmbeddings,\n      metadata,\n    });\n    this.totalVectors += embeddings.length;","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/ruvector/semantic-router.ts#L38-L74","documentation":"addIntentWithEmbeddings() validates its inputs before storing: name must be a non-empty string and embeddings must be an Array. This is the first and loosest check — the next loop additionally requires every element to be a Float32Array of exactly config.dimension. This error fires when either the name or the array shape is wrong at the top level.","triggerScenarios":"Calling with a name that is undefined/'' (often a destructured or interpolated variable that was never set); passing embeddings as a plain number[][] instead of Float32Array[] (caught here only if not an Array at all — plain arrays pass this check and fail the next one); passing null embeddings.","commonSituations":"Building intents from data files where a key is misspelled (name vs label); coercing JSON-loaded embeddings that arrive as nested arrays; optional-chained lookups (intent?.name) yielding undefined for a malformed record.","solutions":["Supply a non-empty literal name and an actual Array of Float32Array embeddings","Convert JSON-loaded vectors: embeddings.map(v => Float32Array.from(v)) before the call","Validate intent records at load time: name is a non-empty string, embeddings is a non-empty array of arrays, then coerce","Double-check that every embedding's length equals the dimension you constructed the router with"],"exampleFix":"// before\nrouter.addIntentWithEmbeddings(intent.label, intent.vectors); // label undefined → throws\n// after\nconst name = intent.name;\nconst embeddings = (intent.vectors ?? []).map((v: number[]) => Float32Array.from(v));\nif (!name || !Array.isArray(embeddings) || embeddings.length === 0) {\n  throw new Error(`invalid intent record: ${JSON.stringify(intent).slice(0, 80)}`);\n}\nrouter.addIntentWithEmbeddings(name, embeddings);","handlingStrategy":"validation","validationCode":"function toIntent(record: { name?: unknown; vectors?: unknown }) {\n  const name = typeof record.name === 'string' ? record.name.trim() : '';\n  const embeddings = Array.isArray(record.vectors)\n    ? record.vectors.map((v: number[]) => Float32Array.from(v))\n    : [];\n  if (!name || embeddings.length === 0) return null; // filter bad records before the call\n  return { name, embeddings };\n}","typeGuard":"type IntentInput = { name: string; embeddings: Float32Array[] };\nfunction isIntentInput(x: unknown): x is IntentInput {\n  return !!x && typeof (x as any).name === 'string' && (x as any).name.length > 0\n    && Array.isArray((x as any).embeddings);\n}","tryCatchPattern":"try {\n  router.addIntentWithEmbeddings(name, embeddings);\n} catch (e) {\n  if (e instanceof Error && (e.message.startsWith('Must provide name and embeddings') || e.message.startsWith('Embedding must be Float32Array'))) {\n    console.warn(`skipping malformed intent ${JSON.stringify(name)}`); // bad record, not fatal\n  } else throw e;\n}","preventionTips":["Coerce JSON-loaded vectors with Float32Array.from() — JSON has no typed arrays","Validate intent records at load time (non-empty name, array of correct-length vectors)","Dimension mismatches throw on the NEXT line — validate length === router dimension in the same pass"],"tags":["semantic-router","embeddings","argument-validation","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}