pub struct ApiEmbedder { /* private fields */ }Expand description
Generates embeddings via a remote API endpoint, with hash fallback.
§API Mode
When a valid API key is available, sends requests to the provider’s
/embeddings endpoint in the OpenAI-compatible format.
§Fallback Mode
When no API key is set or the API call fails, produces deterministic pseudo-embeddings using SHA-256 hashing. These are NOT semantically meaningful but provide consistent, reproducible vectors for testing and development workflows.
Implementations§
Source§impl ApiEmbedder
impl ApiEmbedder
Sourcepub fn new(config: ApiEmbedderConfig) -> Self
pub fn new(config: ApiEmbedderConfig) -> Self
Create a new ApiEmbedder with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create an ApiEmbedder with default configuration (OpenAI, 384-dim).
Sourcepub fn hash_only(dimension: usize) -> Self
pub fn hash_only(dimension: usize) -> Self
Create a fallback-only embedder that never calls an API.
Useful for testing or environments without API access.
Sourcepub fn hash_fallback(&self, text: &str) -> Vec<f32>
pub fn hash_fallback(&self, text: &str) -> Vec<f32>
Generate a deterministic pseudo-embedding from text using SHA-256.
This is NOT semantically meaningful – it is a fallback for when no API is available. The output is deterministic: same input always produces the same vector.
Trait Implementations§
Source§impl Embedder for ApiEmbedder
impl Embedder for ApiEmbedder
Source§fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn embed_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn embed_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for ApiEmbedder
impl !RefUnwindSafe for ApiEmbedder
impl Send for ApiEmbedder
impl Sync for ApiEmbedder
impl Unpin for ApiEmbedder
impl UnsafeUnpin for ApiEmbedder
impl !UnwindSafe for ApiEmbedder
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
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>
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>
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