{"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":"Error","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/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/ruvector/semantic-router.ts#L38-L74","documentation":"addIntentWithEmbeddings requires a truthy name and an Array instance for embeddings. The check `!name || !Array.isArray(embeddings)` throws before any embedding is validated or stored, so partial normalization never happens. An empty-string name and a null/undefined embeddings list both trip it.","triggerScenarios":"Calling addIntentWithEmbeddings('', [...]) with an empty intent name; passing embeddings as a Float32Array instead of an Array (Array.isArray(Float32Array) === false); calling with embeddings=undefined when the caller forgot to compute them.","commonSituations":"Looping over an object of intents where one key is empty; treating a typed array as an array; refactoring that changed the embeddings parameter type without updating the call site.","solutions":["Ensure name is a non-empty string (validate before the call).","Pass embeddings as a plain Array (wrap typed arrays with Array.from(...) if needed).","Skip or log intents with missing embeddings rather than forwarding them."],"exampleFix":"// before\nrouter.addIntentWithEmbeddings(intent.name, intent.embs); // throws if name ''\n\n// after\nif (!intent.name || !Array.isArray(intent.embs) || intent.embs.length === 0) {\n  continue; // or throw a clearer caller-side error\n}\nrouter.addIntentWithEmbeddings(intent.name, intent.embs, intent.meta);","handlingStrategy":"validation","validationCode":"function addIntentSafe(router, name, embeddings, metadata = {}) {\n  if (typeof name !== 'string' || name.length === 0) throw new Error('intent name required');\n  if (!Array.isArray(embeddings) || embeddings.length === 0) throw new Error('non-empty embeddings array required');\n  router.addIntentWithEmbeddings(name, embeddings, metadata);\n}","typeGuard":"function isIntentInput(n: unknown, e: unknown): n is string {\n  return typeof n === 'string' && n.length > 0 && Array.isArray(e) && e.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Validate name and embeddings shape at the producer side before batching.","Wrap typed arrays with Array.from if your pipeline stores Float32Array.","Skip or log empty intents rather than forwarding them to the router."],"tags":["validation","semantic-router","api-contract"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}