{"record":{"id":"43e182666297a5ca","repo":"ruvnet/ruflo","slug":"invalid-embedding-value-at-index-i-expected-fi","errorCode":null,"errorMessage":"Invalid embedding value at index ${i}: expected finite number, got ${typeof embedding[i]}","messagePattern":"Invalid embedding value at index (.+?): expected finite number, got (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/commands/ruvector/import.ts","lineNumber":52,"sourceCode":" */\ninterface ImportStats {\n  total: number;\n  imported: number;\n  skipped: number;\n  errors: number;\n  withEmbeddings: number;\n  byNamespace: Record<string, number>;\n}\n\n/**\n * Format a ruvector embedding array for PostgreSQL\n * Validates each element is a finite number to prevent SQL injection via crafted arrays.\n */\nfunction formatEmbedding(embedding: number[], dimensions: number = 384): string {\n  // Validate every element is a finite number (prevents SQL injection via crafted JSON)\n  for (let i = 0; i < embedding.length; i++) {\n    if (typeof embedding[i] !== 'number' || !Number.isFinite(embedding[i])) {\n      throw new Error(`Invalid embedding value at index ${i}: expected finite number, got ${typeof embedding[i]}`);\n    }\n  }\n\n  // Ensure correct dimensions by padding or truncating\n  const padded = [...embedding];\n  while (padded.length < dimensions) {\n    padded.push(0);\n  }\n  if (padded.length > dimensions) {\n    padded.length = dimensions;\n  }\n  return `'[${padded.join(',')}]'::ruvector(${dimensions})`;\n}\n\n/**\n * Escape string for PostgreSQL\n */\nfunction escapeString(str: string): string {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/commands/ruvector/import.ts#L34-L70","documentation":"Thrown by formatEmbedding() when any element of the embedding array is not a finite number (NaN, Infinity, a string, null, undefined). This guard exists primarily to prevent SQL injection and data corruption via crafted embedding JSON passed into the ruvector() PostgreSQL cast — every value is interpolated into the literal vector string, so non-numeric content would break out of the numeric context.","triggerScenarios":"Importing an embedding payload that contains NaN/Infinity (e.g. from JSON that legitimately cannot carry those but which was produced by a buggy model client emitting strings), nulls where numbers belong, or a partially-decoded buffer.","commonSituations":"Model client emitting 'NaN'/'Infinity' as strings, a downstream pipeline leaving null placeholders for failed inferences, mixed-type arrays from a sloppy export, or unit tests feeding [1,'2',3].","solutions":["Sanitize the array before import: replace non-finite values or drop the row entirely.","Inspect the offending index reported in the message to find which record is malformed.","Validate at the producer: ensure the embedding pipeline only emits finite numbers."],"exampleFix":"// before\nconst emb = [0.1, NaN, 0.3];\nformatEmbedding(emb);\n// after\nconst emb = [0.1, NaN, 0.3];\nif (!emb.every(v => typeof v === 'number' && Number.isFinite(v))) {\n  throw new Error('embedding has non-finite values');\n}\nformatEmbedding(emb);","handlingStrategy":"type-guard","validationCode":"function isFiniteNumberArray(v: unknown): v is number[] {\n  return Array.isArray(v) && v.every(x => typeof x === 'number' && Number.isFinite(x));\n}\n// before importing:\nif (!isFiniteNumberArray(record.embedding)) {\n  throw new Error(`record ${record.id} has non-finite embedding values`);\n}","typeGuard":"const isFiniteNumber = (v: unknown): v is number =>\n  typeof v === 'number' && Number.isFinite(v);\nconst isFiniteNumberArray = (v: unknown): v is number[] =>\n  Array.isArray(v) && v.every(isFiniteNumber);","tryCatchPattern":"try {\n  formatEmbedding(emb, dims);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e);\n  if (msg.startsWith('Invalid embedding value')) {\n    // drop the row or sanitize, then continue\n    return null;\n  }\n  throw e;\n}","preventionTips":["Validate embeddings at the producer; only emit finite numbers.","Reject or replace NaN/Infinity/null before import.","Unit-test the import path with adversarial arrays."],"tags":["validation","security","ruvector","embeddings","sql-injection"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}