janhq/jan · error · KVCacheError

EmbeddingLengthInvalid

EmbeddingLengthInvalid

Error message

Invalid metadata: embedding_length not found or invalid

What it means

KVCacheError::EmbeddingLengthInvalid is raised when GGUF metadata is missing a valid `embedding_length` (hidden size) key. The plugin needs this value to compute the size of each token's embedding/KV entries, so it fails when the key is absent or not an integer. It signals a malformed or unsupported GGUF file.

Solutions

  1. Re-download or re-extract the GGUF model and verify its checksum.
  2. Inspect metadata with gguf-dump to confirm `embedding_length` exists and is a positive integer.
  3. Re-run the model conversion with the latest llama.cpp scripts so full metadata is emitted.
  4. Update tauri-plugin-llamacpp if the model's architecture uses an unrecognized metadata prefix.

Example fix

// before
let emb_len = md.embedding_length(); // panics/errors when key absent

// after
let emb_len = match md.get("llama.embedding_length") {
    Some(v) => *v,
    None => anyhow::bail!("GGUF missing embedding_length; re-convert model with current llama.cpp"),
};
Defensive patterns

Strategy: validation

Validate before calling

// Rust: confirm embedding_length exists before cache init
fn has_embedding_length(md: &GgufMetadata, arch: &str) -> bool {
    md.get_u64(&format!("{arch}.embedding_length")).map(|v| v > 0).unwrap_or(false)
}

Type guard

fn valid_u64(v: Option<&u64>) -> bool {
    matches!(v, Some(n) if *n > 0)
}

Try / catch

match kv_cache::from_gguf(&path) {
    Err(KVCacheError::EmbeddingLengthInvalid) => anyhow::bail!("GGUF missing embedding_length; re-convert model"),
    other => other?,
}

Prevention

When it happens

Trigger: Loading a GGUF model whose metadata map lacks `{arch}.embedding_length`, or where the stored value cannot be read as the expected numeric type during KV-cache initialization.

Common situations: Truncated downloads; custom conversion pipelines that skip standard metadata keys; architectures with different metadata naming that the reader doesn't map.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of janhq/jan@7205d770c1 (2026-09-17). Data as JSON: /api/errors/d20823d4a66cf068. Report an issue: GitHub.

Appendix: 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 7205d770c1)