pub mod bow;
#[cfg(feature = "fastembed")]
pub mod fast;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum EmbedKind {
Query,
Document,
}
pub trait Embedder {
fn id(&self) -> String;
fn embed(&self, texts: &[String], kind: EmbedKind) -> anyhow::Result<Vec<Vec<f32>>>;
fn min_similarity(&self) -> f32 {
0.30
}
fn score_margin(&self) -> f32 {
0.15
}
}
pub fn is_dense(model: &str) -> bool {
#[cfg(feature = "fastembed")]
{
fast::FastEmbedder::recognized(model)
}
#[cfg(not(feature = "fastembed"))]
{
let _ = model;
false
}
}
pub fn expected_id(model: &str) -> String {
if is_dense(model) {
model.to_string()
} else {
bow::BowEmbedder::new().id()
}
}
pub fn build(model: &str) -> anyhow::Result<Box<dyn Embedder>> {
#[cfg(feature = "fastembed")]
{
if let Some(e) = fast::FastEmbedder::try_for(model)? {
return Ok(Box::new(e));
}
}
let _ = model;
Ok(Box::new(bow::BowEmbedder::new()))
}