Expand description
The embedder-supplied seam for submilli:embedding — batches of text embedded
by a remote provider from inside a Submilli program.
Mirrors crate::runtime::llm: the HTTP, key resolution and retry live in
the embedder behind EmbeddingProvider, and token accounting runs on the
shared TokenLedger.
No input text appears here. Not in an error Display, not in a log line,
not in a settlement. Errors carry the alias, numbers, an input index, and a
fixed kebab-case classification string; provider response bodies are dropped
at this boundary.
§Settlement protocol
A call is split by the provider into sub-batches, each sent as one outbound
request. The stdlib reserves the whole estimate up front
(EmbeddingTokenBudget::reserve) and hands the provider the budget. For
every sub-batch the provider:
- calls
EmbeddingTokenBudget::mark_sentwith that sub-batch’s estimate immediately before sending. This counts the request against the per-run cap (refusing past it) and moves the estimate from “reserved” to “held”, so a future dropped mid-flight leaves the sub-batch held while unsent sub-batches are returned when the budget drops; - records a
SubBatchSettlementwhen the response (or failure) arrives.
Settlements travel back on EmbeddingBatch::settlements or inside the
error, and the stdlib applies them with EmbeddingTokenBudget::settle,
which also releases whatever was reserved but never sent. The outcome table
the provider applies to each sent sub-batch:
| Sub-batch outcome | reported | indeterminate |
|---|---|---|
| Succeeded with nonzero usage | usage | 0 |
| Succeeded without usage, or usage 0 | 0 | estimate |
| Never sent (credential unresolved, blocked by network policy, connect failure) | 0 | 0 (released) |
| Rejected by provider with 4xx (incl. 429) | 0 | 0 (released) |
| Sent, then 5xx / transport / timeout / failed validation | usage if reported | else estimate |
| Sent, then the future is dropped (cancelled) | 0 | estimate |
Sub-batches never sent have no settlement; they are released by settle.
Re-exports§
Structs§
- Embedding
Batch - The result of one successful call:
countvectors ofdimensionsfloats, row-major, labeled with the embedding-spaceidentity. - Embedding
Limits - The ceilings an embedding call is checked against.
- Embedding
Model - An embedding model alias the provider serves.
- Embedding
Token Budget - One execution’s embedding budget: tokens against its own ceiling and the server-wide one, plus the outbound request counter.
- SubBatch
Settlement - What one sent sub-batch cost.
estimateis what was passed toEmbeddingTokenBudget::mark_sent; see the module table for the other two. The remainder (estimate - reported - indeterminate) is released.
Enums§
- Embedding
Bound Kind - Which input bound a call ran into.
- Embedding
Error - Why an embedding call failed. Variants after the pre-send group carry the settlements of every sub-batch that was sent before the failure.
- Embedding
Failure Reason - Why a sent request failed, as a closed vocabulary (the wire form is
Self::as_str). - Embedding
Limit Kind - Which ceiling refused a call. Carries numbers, never inputs.
- Embedding
Malformed Reason - Why a provider response was unusable.
- Embedding
Shape Error - Row access or construction outside an
EmbeddingBatch’s shape. - Purpose
- What an embedding is for. Some providers embed queries and documents differently.
Constants§
- DEFAULT_
MAX_ BYTES_ PER_ CALL - UTF-8 bytes across one call’s texts.
- DEFAULT_
MAX_ EMBEDDING_ REQUESTS - Outbound provider requests one execution may send.
- DEFAULT_
MAX_ EXECUTION_ EMBEDDING_ TOKENS - Tokens one execution may spend across every embedding call it makes.
- DEFAULT_
MAX_ HELD_ EMBEDDING_ TOKENS - Tokens one execution may hold as indeterminate reserve.
- DEFAULT_
MAX_ TEXTS_ PER_ CALL - Texts in one call.
- EMBEDDING_
MODULE_ NAME - The single internal host module every
submilli:embeddingcall dispatches through.
Traits§
- Embedding
Provider - The embedder-provided embedding provider: resolves credentials, performs the requests, and reports what each cost.
Functions§
- estimate_
embedding_ tokens - The token estimate for one input:
ceil(utf8_bytes / 3).