pub struct EmbeddingEngine { /* private fields */ }Expand description
Embedding engine for converting text to vectors.
Wraps different embedding providers with a unified interface.
Implementations§
Source§impl EmbeddingEngine
impl EmbeddingEngine
Sourcepub fn new(dimensions: usize) -> Self
pub fn new(dimensions: usize) -> Self
Create a new embedding engine with hash-based embeddings.
Use this for development, testing, or offline scenarios. Hash embeddings are fast and free but lower quality.
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create from environment variables.
Reads OPENAI_API_KEY. Falls back to hash embeddings if not set.
Sourcepub fn from_env_required() -> Result<Self>
pub fn from_env_required() -> Result<Self>
Create from environment, returning error if not configured.
Sourcepub fn with_openai(api_key: impl Into<String>, model: Option<String>) -> Self
pub fn with_openai(api_key: impl Into<String>, model: Option<String>) -> Self
Create with OpenAI embeddings.
Sourcepub fn with_openai_config(
api_key: impl Into<String>,
config: OpenAIConfig,
) -> Self
pub fn with_openai_config( api_key: impl Into<String>, config: OpenAIConfig, ) -> Self
Create with OpenAI using custom configuration.
Sourcepub fn with_provider(provider: Box<dyn EmbeddingProvider>) -> Self
pub fn with_provider(provider: Box<dyn EmbeddingProvider>) -> Self
Create with a custom provider.
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Get the embedding dimensions.
Sourcepub fn embed(&self, text: &str) -> Result<Vec<f32>>
pub fn embed(&self, text: &str) -> Result<Vec<f32>>
Generate an embedding for the given text (sync wrapper).
Sourcepub async fn embed_async(&self, text: &str) -> Result<Vec<f32>>
pub async fn embed_async(&self, text: &str) -> Result<Vec<f32>>
Generate an embedding asynchronously.
Sourcepub async fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>
pub async fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>
Generate embeddings for multiple texts.
Sourcepub fn similarity(&self, a: &[f32], b: &[f32]) -> f32
pub fn similarity(&self, a: &[f32], b: &[f32]) -> f32
Compute similarity between two embeddings.
Auto Trait Implementations§
impl Freeze for EmbeddingEngine
impl !RefUnwindSafe for EmbeddingEngine
impl Send for EmbeddingEngine
impl Sync for EmbeddingEngine
impl Unpin for EmbeddingEngine
impl UnsafeUnpin for EmbeddingEngine
impl !UnwindSafe 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
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request