#[non_exhaustive]pub struct ChunkedEmbeddingProgress {
pub completed_inputs: usize,
pub usage: Option<Usage>,
}Expand description
What a failed chunked embedding call
(embed_chunks or
embed_chunked) had done
before it failed: where to resume, and the usage billed. It never holds
vectors.
embed_chunks yields the chunks that succeeded before its error, and
completed_inputs is the offset to resume from.
embed_chunked is all-or-nothing: on failure it returns the error, never
the vectors of the chunks that succeeded. Both attach this record to the
error’s ErrorContext::metadata under
allama.embedding, so the tokens already billed are not lost to cost
accounting; the redacted as_log view keeps it. The
error itself is returned unchanged, so its kind,
is_retryable, and
retry_after still apply. Read it back with
from_error.
use allama::mock::MockEmbeddingProvider;
use allama::{
ChunkedEmbeddingProgress, EmbeddingProviderExt, EmbeddingRequest, EmbeddingResponse, Error,
Usage,
};
let provider = MockEmbeddingProvider::new([
Ok(EmbeddingResponse::new(vec![vec![0.1], vec![0.2]]).usage(Usage::new().input_tokens(8))),
Err(Error::rate_limited("slow down")),
]);
let request = EmbeddingRequest::new("m").inputs(["a", "b", "c"]);
let err = provider.embed_chunked(&request, 2).await.unwrap_err();
assert!(err.is_retryable());
let progress = ChunkedEmbeddingProgress::from_error(&err).unwrap();
assert_eq!(progress.completed_inputs, 2);
assert_eq!(progress.usage.unwrap().input_tokens, Some(8));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.completed_inputs: usizeThe number of leading inputs whose chunks completed: their vectors
arrived, one per input. Inputs from this index on were not embedded
(or their chunk was rejected), so it is the offset to resume from:
embed request.inputs[completed_inputs..].
usage: Option<Usage>The summed usage the provider reported for every chunk it answered,
including a chunk rejected for its vector count. None when no
answered chunk reported usage.
Implementations§
Source§impl ChunkedEmbeddingProgress
impl ChunkedEmbeddingProgress
Sourcepub fn from_error(error: &Error) -> Option<Self>
pub fn from_error(error: &Error) -> Option<Self>
The record embed_chunked attached to error, if any.
embed_chunked attaches it to every error it returns, except a
Serialization error, which has no context.
For an error that ended a failover it is on that error’s own context,
not on the errors it fell back from.