OptionalapiKey: stringProtected_Protected property to store additional provider-specific settings
Get the current additional settings
ProtectedapiOnly sub-classes can access the API key
Read only getter method to get the Ollama client instance
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 the default (non-batch) path, on top of the initial attempt.
0 disables retry. Retrying each text a few times before giving up stops one transient 429/500
from failing the whole batch (whose failure rate otherwise scales with the text count N).
Read only getter method to get the Ollama client instance
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).
Embeds text and/or interleaved media content into a single fused vector.
Default behavior: text-only content is delegated to EmbedText; if any non-text block is present, throws — because the base provider can't embed media. Multimodal providers (e.g. GeminiEmbedding) should override this method.
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 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. To make it
fully fail-loud instead, replace the two emptyEmbedTextsResult(...) returns below with throw.
Embed a single text string using Ollama
Embed multiple texts in batch using Ollama Note: Ollama doesn't have native batch support, so we process sequentially For better performance, consider running multiple Ollama instances or using async processing
Get the dimension size for a specific embedding model This is useful for setting up vector databases
Get available embedding models Required by BaseEmbeddings abstract class
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().
Get information about a specific embedding model
List available embedding models in Ollama
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.
ProtectedrunRuns 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.
Override SetAdditionalSettings to handle Ollama specific settings
ProtectedsleepSleep helper for retry backoff, isolated so tests can override embedRetryBaseDelayMs to avoid real delays.
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.
Ollama implementation of the BaseEmbeddings class for local embedding generation Supports various embedding models like nomic-embed-text, mxbai-embed-large, etc.