pub struct OllamaEmbeddingEngine { /* private fields */ }Expand description
Embedding engine that calls the Ollama /api/embed HTTP endpoint.
Sends a batched array input per request, sub-batched by batch_size, and
falls back to one concurrent request per text (via
futures::future::join_all) for servers that do not accept array input.
Transient HTTP errors (network failures, 429, 5xx) are retried with
exponential back-off starting at 8 s (doubling to 128 s) for up to 128 s total.
§Response shapes
Ollama can return embeddings in three shapes depending on the version and endpoint:
{"embeddings": [[...]]}— standard/api/embedresponse{"embedding": [...]}— legacy single-embedding response{"data": [{"embedding": [...]}]}— OpenAI-compatible shape
All three shapes are handled transparently.
Implementations§
Source§impl OllamaEmbeddingEngine
impl OllamaEmbeddingEngine
Sourcepub fn new(config: &EmbeddingConfig) -> EmbeddingResult<Self>
pub fn new(config: &EmbeddingConfig) -> EmbeddingResult<Self>
Construct a new engine from the given EmbeddingConfig.
Returns EmbeddingError::ConfigError if the reqwest client cannot
be built (e.g. invalid TLS or API key header value).
Trait Implementations§
Source§impl EmbeddingEngine for OllamaEmbeddingEngine
impl EmbeddingEngine for OllamaEmbeddingEngine
Source§fn embed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = EmbeddingResult<Vec<Vec<f32>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn embed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = EmbeddingResult<Vec<Vec<f32>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Embed a batch of text strings into normalized vectors Read more
Source§fn dimension(&self) -> usize
fn dimension(&self) -> usize
Get the dimensionality of embeddings produced by this engine Read more
Source§fn batch_size(&self) -> usize
fn batch_size(&self) -> usize
Get the optimal batch size for this engine Read more
Source§fn max_sequence_length(&self) -> usize
fn max_sequence_length(&self) -> usize
Get the maximum sequence length (in tokens) supported Read more
Auto Trait Implementations§
impl !RefUnwindSafe for OllamaEmbeddingEngine
impl !UnwindSafe for OllamaEmbeddingEngine
impl Freeze for OllamaEmbeddingEngine
impl Send for OllamaEmbeddingEngine
impl Sync for OllamaEmbeddingEngine
impl Unpin for OllamaEmbeddingEngine
impl UnsafeUnpin for OllamaEmbeddingEngine
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