{"record":{"id":"010b938f70fbc0c8","repo":"ruvnet/ruflo","slug":"original-and-reconstructed-arrays-must-have-same-l","errorCode":null,"errorMessage":"Original and reconstructed arrays must have same length","messagePattern":"Original and reconstructed arrays must have same length","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/plugins/src/integrations/ruvector/quantization.ts","lineNumber":1799,"sourceCode":"      throw new Error(`Unknown quantization type: ${type}`);\n  }\n}\n\n/**\n * Computes quantization statistics by comparing original and reconstructed vectors.\n *\n * @param original - Original vectors\n * @param reconstructed - Reconstructed vectors after quantization\n * @param quantizer - The quantizer used\n * @returns Quantization statistics\n */\nexport function computeQuantizationStats(\n  original: number[][],\n  reconstructed: number[][],\n  quantizer: IQuantizer\n): QuantizationStats {\n  if (original.length !== reconstructed.length) {\n    throw new Error('Original and reconstructed arrays must have same length');\n  }\n\n  // Compute MSE\n  let mse = 0;\n  for (let i = 0; i < original.length; i++) {\n    mse += squaredEuclideanDistance(original[i], reconstructed[i]);\n  }\n  mse /= original.length;\n\n  // Estimate recall@10 by comparing rankings\n  // (simplified - real evaluation would use a test set)\n  const recallAt10 = estimateRecall(original, reconstructed, 10);\n\n  return {\n    compressionRatio: quantizer.getCompressionRatio(),\n    memoryReduction: quantizer.getMemoryReduction(),\n    recallAt10,\n    searchSpeedup: quantizer.getCompressionRatio() * 0.8, // Approximate","sourceCodeStart":1781,"sourceCodeEnd":1817,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/plugins/src/integrations/ruvector/quantization.ts#L1781-L1817","documentation":"Thrown by computeQuantizationStats() when the original and reconstructed vector arrays have different lengths. The function pairs element-wise original[i] with reconstructed[i] to compute MSE and recall estimates, so mismatched lengths indicate the two datasets no longer correspond.","triggerScenarios":"Filtering or slicing one array but not the other before evaluating; comparing quantized outputs of a subset batch against the full corpus; passing codes.length results from a decode() that dropped failed rows.","commonSituations":"Evaluation harness built incrementally where one pipeline stage adds a filter; retry logic that re-quantizes only failed vectors; off-by-one batching that produces N-1 reconstructions.","solutions":["Ensure both arrays are produced from the same vector set: reconstructed = quantizer.decode(quantizer.quantize(original))","If you must subset, apply the identical filter/indices to both arrays before calling computeQuantizationStats","Log both lengths in the error path so the divergence source is obvious"],"exampleFix":"// before\nconst stats = computeQuantizationStats(allVectors, reconstructedSubset, pq); // throws\n\n// after\nconst subset = allVectors.filter((_, i) => keep[i]);\nconst recSubset = reconstructed.filter((_, i) => keep[i]);\nconst stats = computeQuantizationStats(subset, recSubset, pq);","handlingStrategy":"validation","validationCode":"if (original.length !== reconstructed.length) {\n  throw new Error(\n    `Evaluation sets diverged: original=${original.length}, reconstructed=${reconstructed.length}`\n  );\n}\nconst stats = computeQuantizationStats(original, reconstructed, quantizer);","typeGuard":"const isPairedDataset = (a: number[][], b: number[][]): boolean =>\n  Array.isArray(a) && Array.isArray(b) && a.length === b.length;","tryCatchPattern":"try {\n  stats = computeQuantizationStats(original, reconstructed, quantizer);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('same length')) {\n    const n = Math.min(original.length, reconstructed.length);\n    stats = computeQuantizationStats(original.slice(0, n), reconstructed.slice(0, n), quantizer); // with a warning\n  } else {\n    throw err;\n  }\n}","preventionTips":["Compute reconstructions from the exact array you evaluate: reconstructed = quantizer.decode(quantizer.quantize(original))","Apply any filter/index subset to both arrays through one shared helper","Assert equal lengths in test utilities before calling stats helpers"],"tags":["quantization","evaluation","length-mismatch","validation"],"backgroundTag":"length-mismatch","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}