pub struct EmbeddingEngine { /* private fields */ }Expand description
Embedding 引擎:将代码/文档文本转为向量表示。
调用 OpenAI 兼容的嵌入 API(支持 text-embedding-3-small 等模型)。
Implementations§
Source§impl EmbeddingEngine
impl EmbeddingEngine
Sourcepub fn new(config: &EmbedSection, rt: Handle) -> Result<Self>
pub fn new(config: &EmbedSection, rt: Handle) -> Result<Self>
从配置创建 Embedding 引擎。
优先使用 api_key 字段,其次从环境变量读取。
rt 传入全局 Runtime 句柄(语义索引与特征聚类共用)。
Sourcepub async fn embed_batch(&self, texts: &[String]) -> Result<Vec<Vec<f32>>>
pub async fn embed_batch(&self, texts: &[String]) -> Result<Vec<Vec<f32>>>
批量嵌入:将多个文本转为向量。
按 batch_size 分批发往 API,自动合并结果。
Sourcepub fn cosine_similarity(a: &[f32], b: &[f32]) -> f32
pub fn cosine_similarity(a: &[f32], b: &[f32]) -> f32
余弦相似度(-1~1)。
Sourcepub fn call_count(&self) -> usize
pub fn call_count(&self) -> usize
已完成的 API 调用次数。
Trait Implementations§
Source§impl Embedder for EmbeddingEngine
特征聚类用的 Embedder 实现(analysis::feature::Embedder)。
impl Embedder for EmbeddingEngine
特征聚类用的 Embedder 实现(analysis::feature::Embedder)。
同步方法经内部持有的 tokio Handle 驱动 async 请求。
Auto Trait Implementations§
impl !Freeze for EmbeddingEngine
impl !RefUnwindSafe for EmbeddingEngine
impl !UnwindSafe for EmbeddingEngine
impl Send for EmbeddingEngine
impl Sync for EmbeddingEngine
impl Unpin for EmbeddingEngine
impl UnsafeUnpin for EmbeddingEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more