Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions rust/src/embeddings/embed/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::embeddings::local::{
text_embedding::ONNXModel,
};


pub enum TextEmbedder {
OpenAI(OpenAIEmbedder),
Cohere(CohereEmbedder),
Expand Down Expand Up @@ -89,12 +88,14 @@ impl TextEmbedder {
model_id, token, None,
)?))),

"ModernBertForMaskedLM" => Ok(Self::ModernBert(Box::new(ModernBertEmbedder::new(
model_id.to_string(),
revision.map(|s| s.to_string()),
token,
dtype,
)?))),
architecture if is_modernbert_architecture(architecture) => {
Ok(Self::ModernBert(Box::new(ModernBertEmbedder::new(
model_id.to_string(),
revision.map(|s| s.to_string()),
token,
dtype,
)?)))
}
"Qwen3ForCausalLM" => Ok(Self::Qwen3(Box::new(Qwen3Embedder::new(
model_id,
revision.map(|s| s.to_string()),
Expand Down Expand Up @@ -196,3 +197,20 @@ pub trait TextEmbed {
batch_size: Option<usize>,
) -> impl Future<Output = anyhow::Result<Vec<EmbeddingResult>>>;
}

fn is_modernbert_architecture(architecture: &str) -> bool {
matches!(architecture, "ModernBertForMaskedLM" | "ModernBertModel")
}

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

#[test]
fn supports_modernbert_embedding_architectures() {
for architecture in ["ModernBertForMaskedLM", "ModernBertModel"] {
assert!(is_modernbert_architecture(architecture));
}
assert!(!is_modernbert_architecture("BertModel"));
}
}
Loading