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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! bge prepends an instruction to queries and nothing to passages; `embed` applies no template.

use candding::TextEmbedding;

fn main() -> candding::Result<()> {
  let model = TextEmbedding::builder("BAAI/bge-small-en-v1.5").build()?;
  let text = "what is a matryoshka embedding";
  let raw = model.embed(&[text], None)?;
  let query = model.query_embed(&[text], None)?;
  let cosine: f32 = raw[0].iter().zip(&query[0]).map(|(a, b)| a * b).sum();
  println!("query template: {:?}", model.descriptor().query_template);
  println!(
    "tokens without the template: {:?}",
    model.token_count(&[text])?
  );
  println!("cosine(raw, query) = {cosine:.4}");
  Ok(())
}