janhq/jan · error · KVCacheError::EmbeddingLengthInvalid

Invalid metadata: embedding_length not found or invalid

Error message

Invalid metadata: embedding_length not found or invalid

What it means

`KVCacheError::EmbeddingLengthInvalid` — the estimator could not find or parse the model embedding/hidden dimension (e.g. `llama.embedding_length`). This is the per-element width used to size each KV-cache entry.

Source

Thrown at src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/types.rs:69

    pub version: u32,
    pub tensor_count: u64,
    pub metadata: HashMap<String, String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct KVCacheEstimate {
    pub size: u64,
    pub per_token_size: u64,
}
#[derive(Debug, thiserror::Error)]
pub enum KVCacheError {
    #[error("Invalid metadata: architecture not found")]
    ArchitectureNotFound,
    #[error("Invalid metadata: block_count not found or invalid")]
    BlockCountInvalid,
    #[error("Invalid metadata: head_count not found or invalid")]
    HeadCountInvalid,
    #[error("Invalid metadata: embedding_length not found or invalid")]
    EmbeddingLengthInvalid,
    #[error("Invalid metadata: context_length not found or invalid")]
    ContextLengthInvalid,
}

impl serde::Serialize for KVCacheError {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(&self.to_string())
    }
}


#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize)]
pub enum ModelSupportStatus {
    #[serde(rename = "RED")]

View on GitHub (pinned to fad3f12a14)

Solutions

  1. Dump `<arch>.*` and find the key holding the hidden dimension; add it as a fallback.
  2. Parse defensively with trim and float-tolerant parse.
  3. Re-download or pick a known-good GGUF if the field is genuinely absent.
  4. Confirm the architecture name matches the key prefix your lookup uses.

Example fix

// before
let d: u64 = meta.metadata.get(&format!("{}.embedding_length", arch))
    .ok_or(KVCacheError::EmbeddingLengthInvalid)?
    .parse().map_err(|_| KVCacheError::EmbeddingLengthInvalid)?;

// after - synonym fallbacks
let d: u64 = ["embedding_length", "n_embd", "hidden_size"].iter()
    .find_map(|k| meta.metadata.get(&format!("{}.{}", arch, k)))
    .ok_or(KVCacheError::EmbeddingLengthInvalid)?
    .trim().parse().map_err(|_| KVCacheError::EmbeddingLengthInvalid)?;
Defensive patterns

Strategy: validation

Validate before calling

fn embedding_len(meta: &GgufMetadata, arch: &str) -> Option<u64> {
    ["embedding_length", "n_embd", "hidden_size"].iter()
        .find_map(|k| meta.metadata.get(&format!("{arch}.{k}")))
        .and_then(|s| s.trim().parse::<u64>().ok())
}

Type guard

null

Try / catch

match estimate_kv_cache(&meta) {
    Ok(est) => Ok(est),
    Err(KVCacheError::EmbeddingLengthInvalid) => Err(UserError::UnsupportedModel("missing embedding_length".into())),
    Err(e) => Err(e.into()),
}

Prevention

When it happens

Trigger: The `<arch>.embedding_length` key is missing from the parsed metadata, or its value does not parse to an integer. Some architectures expose this under a different name (e.g. `hidden_size`, `n_embd`).

Common situations: Architecture-specific key naming differences; stripped metadata; a value stored as a float string that fails integer parsing. The error fires after architecture and block_count have already been resolved, so the file is mostly valid but missing this one field.

Related errors


AI-assisted analysis of janhq/jan@fad3f12a14 (2026-08-12). Data as JSON: /api/errors/78400905b7298f31. Report an issue: GitHub.