candding 0.1.0

Pure candle embeddings for Rust with no ONNX: dense, sparse, multi-vector and rerank models today, image models on the roadmap
Documentation
use super::*;

#[test]
fn every_nomic_bert_entry_holds_the_nomic_bert_family_and_the_common_fields() {
  let nomic: Vec<_> = all()
    .into_iter()
    .filter(|d| d.family == Family::NomicBert)
    .collect();
  assert_eq!(
    nomic.len(),
    3,
    "v1, v1.5 and the Snowflake arctic-embed-m-long checkpoint"
  );
  for d in &nomic {
    assert_eq!(d.dim, 768, "{}", d.id);
    assert_eq!(d.default_max_length, 8192, "{}", d.id);
    assert_eq!(d.default_dtype, DType::F32, "{}", d.id);
    assert_eq!(d.license, "Apache-2.0", "{}", d.id);
    assert!(!d.gated, "{}", d.id);
    assert!(d.dense_dirs.is_empty(), "{}", d.id);
    assert_eq!(d.size_gb, 0.55, "{}", d.id);
    assert_eq!(
      weights_format(&d.id),
      WeightsFormat::Safetensors,
      "{}",
      d.id
    );
  }
}

/// Snowflake's card carries neither prefix; its query prompt comes from `config_sentence_transformers.json`.
#[test]
fn v1_and_v1_5_are_mean_pooled_with_the_nomic_card_prefixes() {
  for id in [
    "nomic-ai/nomic-embed-text-v1",
    "nomic-ai/nomic-embed-text-v1.5",
  ] {
    let d = lookup(id).unwrap();
    assert_eq!(d.pooling, Pooling::Mean, "{id}");
    assert_eq!(
      d.query_template.as_deref(),
      Some("search_query: {text}"),
      "{id}"
    );
    assert_eq!(
      d.passage_template.as_deref(),
      Some("search_document: {text}"),
      "{id}"
    );
  }
}

#[test]
fn snowflake_is_cls_pooled_with_a_query_only_prompt() {
  let d = lookup("Snowflake/snowflake-arctic-embed-m-long").unwrap();
  assert_eq!(d.pooling, Pooling::Cls);
  assert_eq!(
    d.query_template.as_deref(),
    Some("Represent this sentence for searching relevant passages: {text}")
  );
  assert!(d.passage_template.is_none());
}

/// `v1.5`'s card applies an affine-free LayerNorm to the pooled vector before the Matryoshka slice.
#[test]
fn only_v1_5_has_mrl_and_layer_norm_after_pooling() {
  let d = lookup("nomic-ai/nomic-embed-text-v1.5").unwrap();
  assert!(d.mrl && d.layer_norm_after_pooling);
  for other in [
    "nomic-ai/nomic-embed-text-v1",
    "Snowflake/snowflake-arctic-embed-m-long",
  ] {
    let d = lookup(other).unwrap();
    assert!(!d.mrl && !d.layer_norm_after_pooling, "{other}");
  }
}

#[test]
fn no_other_catalog_entry_has_layer_norm_after_pooling() {
  let leaked: Vec<_> = all()
    .into_iter()
    .filter(|d| d.id != "nomic-ai/nomic-embed-text-v1.5" && d.layer_norm_after_pooling)
    .map(|d| d.id)
    .collect();
  assert!(leaked.is_empty(), "{leaked:?}");
}