pub trait Embedder: Send + Sync {
// Required methods
fn embed(&self, text: &str) -> Result<Vec<f32>>;
fn embed_batch(&self, texts: &[String]) -> Result<Vec<Vec<f32>>>;
fn cosine_similarity(&self, a: &[f32], b: &[f32]) -> f64;
}Expand description
向量嵌入窄接口(analysis 层不依赖具体实现,实现方见 generate::embed)。
刻意使用同步方法而非 async fn in trait:当前编译器不支持 async fn in
trait 的 dyn 分发(llm.rs 已记载该限制),而特征聚类需要
Option<&dyn Embedder> 做运行时注入;同步方法由实现方内部驱动
tokio Runtime(EmbeddingEngine 持有 Handle)。
Required Methods§
Sourcefn cosine_similarity(&self, a: &[f32], b: &[f32]) -> f64
fn cosine_similarity(&self, a: &[f32], b: &[f32]) -> f64
余弦相似度(返回 0.0~1.0,负值截断为 0)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl Embedder for EmbeddingEngine
特征聚类用的 Embedder 实现(analysis::feature::Embedder)。
同步方法经内部持有的 tokio Handle 驱动 async 请求。