ruvnet/ruflo · error

Unknown quantization type: ${type}

Error message

Unknown quantization type: ${type}

What it means

Thrown by the SQL DDL generator (QuantizationSQL CREATE TABLE path) when the quantization `type` argument is not one of the supported literals 'scalar' | 'binary' | 'pq' | 'opq'. The switch has no other branches, so any other string (typo, casing, or an unvalidated config value) hits the default case.

Source

Thrown at v3/@claude-flow/plugins/src/integrations/ruvector/quantization.ts:1344

      case 'scalar':
        vectorColumn = `quantized_vector BYTEA NOT NULL`;
        comment = `Scalar quantized vectors (int8, ${dimensions} dims, 4x compression)`;
        break;

      case 'binary':
        const binaryBytes = Math.ceil(dimensions / 8);
        vectorColumn = `binary_vector BIT(${dimensions})`;
        comment = `Binary quantized vectors (${dimensions} dims, ${binaryBytes} bytes, 32x compression)`;
        break;

      case 'pq':
      case 'opq':
        vectorColumn = `pq_codes BYTEA NOT NULL`;
        comment = `${type === 'opq' ? 'Optimized ' : ''}Product quantized vectors (M=${numSubvectors}, K=256)`;
        break;

      default:
        throw new Error(`Unknown quantization type: ${type}`);
    }

    const extraCols = additionalColumns ? `\n  ${additionalColumns},` : '';

    return `
-- Table for ${comment}
CREATE TABLE IF NOT EXISTS ${tableName} (
  id ${idType} PRIMARY KEY,${extraCols}
  original_vector vector(${dimensions}),  -- Optional: keep original for reranking
  ${vectorColumn},
  metadata JSONB,
  created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

-- Index for quantized search
CREATE INDEX IF NOT EXISTS idx_${tableName}_quantized ON ${tableName} (quantized_vector);

COMMENT ON TABLE ${tableName} IS '${comment}';

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Use exactly one of: 'scalar', 'binary', 'pq', 'opq' (lowercase)
  2. Normalize/validate the type at the config boundary: lowercase it and assert membership in the allowed set before generating DDL
  3. Type the parameter as the library's union type so TypeScript rejects invalid literals at compile time

Example fix

// before
const ddl = sqlGen.generateCreateTableSQL('vectors', 'embedding', 128, 'int8'); // throws

// after
const ddl = sqlGen.generateCreateTableSQL('vectors', 'embedding', 128, 'scalar');
Defensive patterns

Strategy: type-guard

Validate before calling

const QUANTIZATION_TYPES = ['scalar', 'binary', 'pq', 'opq'] as const;
const type = String(rawType).trim().toLowerCase() as (typeof QUANTIZATION_TYPES)[number];
if (!QUANTIZATION_TYPES.includes(type)) {
  throw new Error(`type must be one of ${QUANTIZATION_TYPES.join(', ')}`);
}
const ddl = sqlGen.generateCreateTableSQL(table, column, dims, type);

Type guard

const isQuantizationType = (t: string): t is 'scalar' | 'binary' | 'pq' | 'opq' =>
  ['scalar', 'binary', 'pq', 'opq'].includes(t);

Try / catch

try {
  ddl = generateCreateTableSQL(table, column, dims, type);
} catch (err) {
  if (err instanceof Error && err.message.startsWith('Unknown quantization type')) {
    throw new ConfigurationError(`quantization.type '${type}' unsupported; use scalar|binary|pq|opq`);
  }
  throw err;
}

Prevention

When it happens

Trigger: Passing 'int8' or 'sq' instead of 'scalar', 'PQ'/'OPQ' in uppercase, or forwarding a raw string from user config/env into the SQL generator without normalizing it.

Common situations: Config files copied from a different tool that names scalar quantization 'int8'; new team members guessing the enum; REST endpoint accepting a free-form type field that reaches this function unchecked.

Related errors


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/3b6e0a27e942a52b. Report an issue: GitHub.