1use anyhow::Result;
19use rlx_core::gguf_config::{EmbedGgufKind, embed_gguf_kind};
20use rlx_gguf::GgufFile;
21use std::path::Path;
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub enum Arch {
26 Bert,
27 NomicBert,
28 NomicVision,
29}
30
31pub fn detect_arch_from_gguf(weights_path: &Path) -> Result<Arch> {
33 let raw = GgufFile::from_path(weights_path)?;
34 Ok(match embed_gguf_kind(&raw)? {
35 EmbedGgufKind::Bert => Arch::Bert,
36 EmbedGgufKind::NomicBert => Arch::NomicBert,
37 })
38}
39
40pub fn detect_arch(config_path: &Path) -> Result<Arch> {
42 let data = std::fs::read_to_string(config_path)?;
43 let json: serde_json::Value = serde_json::from_str(&data)?;
44
45 if json.get("img_size").is_some() && json.get("patch_size").is_some() {
46 return Ok(Arch::NomicVision);
47 }
48 if json.get("rotary_emb_base").is_some() || json.get("rotary_emb_fraction").is_some() {
49 return Ok(Arch::NomicBert);
50 }
51 Ok(Arch::Bert)
52}
53
54pub fn default_pooling(repo_id: &str) -> super::Pooling {
56 let lower = repo_id.to_lowercase();
57 if lower.contains("bge") || lower.contains("nomic") {
58 super::Pooling::Cls
59 } else {
60 super::Pooling::Mean
61 }
62}