Protected_Protected property to store additional provider-specific settings
Get the current additional settings
ProtectedapiOnly sub-classes can access the API key
ProtectedembedBase delay (ms) for exponential backoff between per-text retries: delay = base * 2^(n-1).
ProtectedmaxMax in-flight EmbedText calls for the default (non-batch) path. Override to tune.
Only the per-text fallback is throttled this way — the native embedBatch path sends all texts in ONE request, so there is nothing to bound. That asymmetry is intentional: N small calls need a concurrency ceiling; a single batched call does not.
ProtectedmaxExtra retry attempts per text on a transient failure, on top of the initial call. 0 disables retry.
Whether this provider needs an API key to run. Defaults to true, because most embedding
providers call a hosted API. A provider that runs in-process or against a local server (e.g.
LocalEmbedding, which runs ONNX models in-process) overrides this to return false, so a
caller that checks credentials before a call (such as AIEmbeddingRunner) does not reject it
for having no key. Mirrors VectorDBBase.RequiresAPIKey.
Whether this provider's embedding model has a NATIVE batch endpoint that returns one vector
per input in a single request. Defaults to false. Providers that pass an array of texts
straight to their API (e.g. OpenAI, Azure, Cohere, Mistral) override this to return true
and implement embedBatch. Providers without one inherit the safe per-text default below.
Clear all additional settings This is useful for resetting the state of the provider or when switching between different configurations.
ProtectedembedNative batch path. A provider that returns SupportsBatchEmbeddings = true MUST override this
with a single batched API call returning one vector per input. The default throws so the flag
and the implementation can't drift apart (claim batch ⇒ must implement it).
Multimodal embed: text and/or interleaved media blocks (image/audio/video/document) fused into ONE vector in the same space as text embeddings — enabling cross-modal retrieval (a text query matching an image, audio, or video). Overrides the base BaseEmbeddings.EmbedContent, which is text-only. Content blocks are mapped to Gemini parts via GeminiLLM.MapMJContentToGeminiParts. Returns an empty vector on error, consistent with the text methods.
ProtectedembedDefault (non-batch) path: fans out one EmbedText call per text with bounded concurrency, preserving order. The 1:1 vector/text count is enforced by the dispatcher (EmbedTexts).
Each text is first retried with bounded exponential backoff (retryEmbedText) so a lone transient failure doesn't sink the batch; only a text that STILL fails after its retries counts as failed.
ERROR CONTRACT (deliberate — change here if a different policy is wanted): mirrors the
per-provider Gemini fix. On any other per-text failure that survives retry (EmbedText throws OR
yields an empty vector) we return an EMPTY result rather than throwing, so batch pipelines that
don't wrap EmbedTexts (e.g. EntityVectorSyncer) degrade gracefully instead of aborting. An aborted
request (cancelled or timed out) is the exception: it is rethrown (see EmbedTexts). To
make it fully fail-loud instead, replace the two emptyEmbedTextsResult(...) returns below with
throw.
Embeds a SINGLE text into one vector.
ERROR CONVENTION — note the deliberate asymmetry with EmbedTexts: on failure a provider
returns an empty vector: [] here (a single-item soft failure the caller inspects directly).
The batch EmbedTexts is stricter and ALL-OR-NOTHING — one failed item collapses the whole
result to vectors: [] rather than returning a partially-filled array — because its consumers pair
vectors[i] ↔ records[i] by index and a stray empty slot is silent corruption. The one case that
THROWS instead of degrading is a structural collapse (vector count ≠ text count); see EmbedTexts.
Embeds an array of texts, returning exactly ONE vector per input text, in input order.
IMPORTANT: gemini-embedding-2 is multimodal — passing the whole texts array as a single
contents value makes Gemini FUSE the texts into ONE blended vector (response.embeddings
has length 1). That silently corrupts any caller that pairs vectors to records by index
(e.g. EntityVectorSyncer). To guarantee a 1:1 mapping we issue a separate embedContent
call per text with bounded concurrency, then hard-assert the count before returning.
Error contract is preserved from the original: on an API/embedding failure this returns an
empty vectors array (matching the prior behavior and the other MJ embedding providers), so
batch pipelines degrade gracefully instead of aborting. A SUCCESSFUL run is then hard-asserted
to be 1:1 with the inputs and throws on mismatch — so the batch-collapse bug can never again
silently return a short/blended array that downstream code mis-pairs by index.
Once params.CancellationToken fires, no further text is sent, no retry or backoff continues,
and this throws a cancellation error rather than returning the empty result.
Declares which non-text mime types this provider's embedding model can embed. null = text-only (the default). Multimodal providers override this. Mirrors BaseLLM.GetFileCapabilities().
ProtectedretryRuns a single-text embed attempt with bounded exponential-backoff retry. A transient failure —
attempt throws, or returns an empty/missing vector — is retried up to maxEmbedTextsRetries
times, sleeping embedRetryBaseDelayMs * 2^(n-1) between tries. Returns the first successful
result; after the final attempt returns whatever it produced (or rethrows its error) so the caller's
existing empty-vector / throw handling still applies. This is what keeps one transient 429/500 from
failing the whole batch.
An aborted signal ends the retries: no attempt starts once it has fired, the backoff wait
rejects as soon as it fires, and a failure caused by an abort is rethrown rather than retried.
Optionalsignal: AbortSignalProtectedrunRuns fn over items with at most maxConcurrency in flight at once, preserving order.
The per-item await inside each worker is what bounds concurrency; parallelism comes from
running up to maxConcurrency workers at the same time.
Set additional provider-specific settings Subclasses should override this method to validate required settings
Provider-specific settings
ProtectedsleepSleep helper for retry backoff, isolated so tests can override embedRetryBaseDelayMs to avoid
real delays. Rejects with a cancellation error as soon as signal fires.
Optionalsignal: AbortSignalProtectedThrowRethrows a failure caused by an aborted request as a cancellation error: one classified
Cancelled (never retried or failed over), or a retriable NetworkError when the signal was
aborted by a timeout. Does nothing for any other failure. A driver that catches its SDK's
errors calls this first, so an abort is reported as such instead of as an empty result.
The error the request failed with.
Optionalsignal: AbortSignalThe request's CancellationToken.
ProtectedValidateThrows if content contains a media block whose mime type the model can't embed.
Text-only content always passes. Called by multimodal providers at the top of EmbedContent.
Base class for all embedding model implementations