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
//! Query and passage templates with `{text}` and `{instruction}` placeholders.

pub fn apply(template: Option<&str>, instruction: Option<&str>, text: &str) -> String {
  match template {
    None => text.to_string(),
    Some(template) => template
      .replace("{instruction}", instruction.unwrap_or_default())
      .replace("{text}", text),
  }
}

#[cfg(test)]
mod tests {
  use super::*;

  #[test]
  fn none_returns_text() {
    assert_eq!(apply(None, None, "hello"), "hello");
  }

  #[test]
  fn replaces_text_and_instruction() {
    let template = "Instruct: {instruction}\nQuery: {text}";
    assert_eq!(
      apply(Some(template), Some("Retrieve passages"), "what is x"),
      "Instruct: Retrieve passages\nQuery: what is x"
    );
    assert_eq!(apply(Some("query: {text}"), None, "a"), "query: a");
  }

  #[test]
  fn text_placeholders_are_not_reprocessed() {
    assert_eq!(
      apply(Some("{text}"), Some("i"), "{instruction}"),
      "{instruction}"
    );
  }
}