risingwavelabs/risingwave · error

invalid pgvector dimension in type `{type_name}`

Error message

invalid pgvector dimension in type `{type_name}`

What it means

For pgvector types of the form `vector(n)`, the dimension text must parse as a `usize`. `parse_pgvector_dimension` throws 'invalid pgvector dimension in type `{type_name}`' when the content inside parentheses is not a valid unsigned integer.

Source

Thrown at src/connector/src/connector_common/postgres.rs:757

    Ok(dtype)
}

fn parse_pgvector_dimension(type_name: &str) -> ConnectorResult<Option<usize>> {
    let normalized = type_name.trim().to_ascii_lowercase();
    if normalized == "vector" {
        bail!("pgvector type `vector` is missing dimension, expected `vector(n)`")
    }
    if !normalized.starts_with("vector(") || !normalized.ends_with(')') {
        return Ok(None);
    }

    let dim_text = normalized
        .trim_start_matches("vector(")
        .trim_end_matches(')')
        .trim();
    let dim = dim_text
        .parse::<usize>()
        .map_err(|_| anyhow!("invalid pgvector dimension in type `{type_name}`"))?;

    if !(1..=DataType::VEC_MAX_SIZE).contains(&dim) {
        bail!(
            "pgvector dimension out of range in type `{}`: expect 1..={}",
            type_name,
            DataType::VEC_MAX_SIZE
        );
    }

    Ok(Some(dim))
}

// Used for sink connector
// We use `sea-schema` for table schema discovery.
// So we have to map `sea-schema` pg types
// to `tokio-postgres` pg types (which we use for query binding).
fn sea_type_to_pg_type(sea_type: &SeaType) -> ConnectorResult<tokio_postgres::types::Type> {
    use tokio_postgres::types::Type as PgType;

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Ensure the upstream column type is a real pgvector type like `vector(768)`
  2. Inspect the actual column type with `SELECT atttypmod FROM pg_attribute WHERE attrelid=... AND attname=...;` and re-discover the schema
  3. Fix any tooling that rewrites/normalizes type names before they reach RisingWave

Example fix

-- before (malformed)
CREATE TABLE t (v vector());
-- after
CREATE TABLE t (v vector(768));
Defensive patterns

Strategy: validation

Validate before calling

fn validate_vector_dim_text(type_name: &str) -> Result<(), String> {
    let inner = type_name.trim_start_matches("vector(").trim_end_matches(')').trim();
    inner.parse::<usize>().map(|_| ()).map_err(|_| format!("bad dimension in {type_name}"))
}

Type guard

fn is_well_formed_vector_type(s: &str) -> bool {
    let s = s.trim().to_ascii_lowercase();
    s.starts_with("vector(") && s.ends_with(')')
        && s["vector(".len()..s.len()-1].trim().parse::<usize>().is_ok()
}

Try / catch

match setup_result {
    Err(e) if e.to_string().contains("invalid pgvector dimension") => {
        log::warn!("type metadata malformed: {e}; re-run schema discovery");
        Err(CdcError::SchemaMetadataCorrupt(e))
    }
    other => other,
}

Prevention

When it happens

Trigger: `parse_pgvector_dimension` receiving a type name matching `vector(...)` whose inner text fails `parse::<usize>()` — e.g. `vector()`, `vector(abc)`, `vector(1.5)`, `vector(-4)`.

Common situations: Corrupted or hand-edited type metadata; typenames synthesized by tooling rather than real pgvector types; unusual whitespace or characters inside the parentheses.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/8e850e7c66dff4de. Report an issue: GitHub.