Member Junction
    Preparing search index...

    Cohere embedding provider for MemberJunction, backed by Cohere embed-v4.0 via the v2 embed API.

    Supports the text-only BaseEmbeddings contract (EmbedText/EmbedTexts) and overrides EmbedContent for multimodal input (text + images fused into one vector). All three methods go through client.v2.embed, which accepts either texts (text) or inputs (structured content blocks for multimodal). Cohere's required input_type defaults to search_document and can be overridden via SetAdditionalSettings({ inputType: '...' }).

    Resolved via ClassFactory.CreateInstance(BaseEmbeddings, "CohereEmbedding", apiKey).

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _additionalSettings: Record<string, any>

    Protected property to store additional provider-specific settings

    Accessors

    • get AdditionalSettings(): Record<string, any>

      Get the current additional settings

      Returns Record<string, any>

    • get apiKey(): string

      Only sub-classes can access the API key

      Returns string

    • get embedRetryBaseDelayMs(): number

      Base delay (ms) for exponential backoff between per-text retries: delay = base * 2^(n-1).

      Returns number

    • get maxEmbedTextsConcurrency(): number

      Max 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.

      Returns number

    • get maxEmbedTextsRetries(): number

      Extra 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).

      Returns number

    • get RequiresAPIKey(): boolean

      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.

      Returns boolean

    Methods

    • Clear all additional settings This is useful for resetting the state of the provider or when switching between different configurations.

      Returns void

    • Default (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.

      Parameters

      Returns Promise<EmbedTextsResult>

    • 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.

      Parameters

      Returns Promise<EmbedTextResult>

    • Embeds an array of texts, returning exactly ONE vector per input text, in input order.

      DISPATCHES on SupportsBatchEmbeddings: providers with a native batch endpoint set it to true and implement embedBatch; everyone else gets the safe per-text fallback in embedPerText. (A provider may still override this method directly for fully custom behavior.)

      Whichever path runs, the result is hard-asserted to be 1:1 with the inputs (an intentional empty result — the per-text graceful-degrade — is allowed): a native embedBatch that drops or reorders vectors, or any other collapse, throws here rather than letting a misaligned array reach index-based consumers (e.g. EntityVectorSyncer).

      CANCELLATION: once params.CancellationToken fires, no further batch or text is sent and this throws a cancellation error (see CreateCancellationError) instead of degrading to an empty result, since an empty result would read as a model failure. An aborted text is never retried.

      Parameters

      Returns Promise<EmbedTextsResult>

    • Cohere embed-v4 accepts images via the v2 inputs/image_url path — and that path only supports PNG/JPEG/WebP/GIF (the API errors "only PNG, JPEG, WebP, and GIF are supported"). Embed-v4's marketed PDF/document support isn't reachable here (it requires rendering pages to images / a different endpoint), so PDF is intentionally NOT declared — declaring it would pass client-side validation but fail at the API.

      Returns FileCapabilities

    • Runs 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.

      Parameters

      Returns Promise<EmbedTextResult>

    • Runs 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.

      Type Parameters

      • T

      Parameters

      • items: string[]
      • fn: (item: string, index: number) => Promise<T>
      • maxConcurrency: number

      Returns Promise<T[]>

    • Set additional provider-specific settings Subclasses should override this method to validate required settings

      Parameters

      • settings: Record<string, any>

        Provider-specific settings

      Returns void

    • Sleep helper for retry backoff, isolated so tests can override embedRetryBaseDelayMs to avoid real delays. Rejects with a cancellation error as soon as signal fires.

      Parameters

      • ms: number
      • Optionalsignal: AbortSignal

      Returns Promise<void>

    • Rethrows 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.

      Parameters

      • error: unknown

        The error the request failed with.

      • Optionalsignal: AbortSignal

        The request's CancellationToken.

      Returns void

    • Throws 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.

      Parameters

      Returns void