ruvnet/ruflo · error
Original and reconstructed arrays must have same length
Error message
Original and reconstructed arrays must have same length
What it means
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.
Source
Thrown at v3/@claude-flow/plugins/src/integrations/ruvector/quantization.ts:1799
throw new Error(`Unknown quantization type: ${type}`);
}
}
/**
* Computes quantization statistics by comparing original and reconstructed vectors.
*
* @param original - Original vectors
* @param reconstructed - Reconstructed vectors after quantization
* @param quantizer - The quantizer used
* @returns Quantization statistics
*/
export function computeQuantizationStats(
original: number[][],
reconstructed: number[][],
quantizer: IQuantizer
): QuantizationStats {
if (original.length !== reconstructed.length) {
throw new Error('Original and reconstructed arrays must have same length');
}
// Compute MSE
let mse = 0;
for (let i = 0; i < original.length; i++) {
mse += squaredEuclideanDistance(original[i], reconstructed[i]);
}
mse /= original.length;
// Estimate recall@10 by comparing rankings
// (simplified - real evaluation would use a test set)
const recallAt10 = estimateRecall(original, reconstructed, 10);
return {
compressionRatio: quantizer.getCompressionRatio(),
memoryReduction: quantizer.getMemoryReduction(),
recallAt10,
searchSpeedup: quantizer.getCompressionRatio() * 0.8, // ApproximateView on GitHub (pinned to fa13ee4ad6)
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
Example fix
// before const stats = computeQuantizationStats(allVectors, reconstructedSubset, pq); // throws // after const subset = allVectors.filter((_, i) => keep[i]); const recSubset = reconstructed.filter((_, i) => keep[i]); const stats = computeQuantizationStats(subset, recSubset, pq);
Defensive patterns
Strategy: validation
Validate before calling
if (original.length !== reconstructed.length) {
throw new Error(
`Evaluation sets diverged: original=${original.length}, reconstructed=${reconstructed.length}`
);
}
const stats = computeQuantizationStats(original, reconstructed, quantizer); Type guard
const isPairedDataset = (a: number[][], b: number[][]): boolean => Array.isArray(a) && Array.isArray(b) && a.length === b.length;
Try / catch
try {
stats = computeQuantizationStats(original, reconstructed, quantizer);
} catch (err) {
if (err instanceof Error && err.message.includes('same length')) {
const n = Math.min(original.length, reconstructed.length);
stats = computeQuantizationStats(original.slice(0, n), reconstructed.slice(0, n), quantizer); // with a warning
} else {
throw err;
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot calibrate with empty samples
- Expected ${this.numSubvectors} codebooks, got ${codebooks.le
- localCompute: no adapter for graphId=${input.graphId}
- Invalid completion type
- Router multimodal is enabled but LLM_ROUTER_MULTIMODAL_MODEL
AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18).
Data as JSON: /api/errors/010b938f70fbc0c8.
Report an issue: GitHub.