microsoft/semantic-kernel · error · NotSupportedException

Unsupported service type

Error message

Unsupported service type

What it means

Thrown by BedrockTextEmbeddingGenerationClient.GenerateEmbeddingsAsync when the resolved _ioVectorGenerationService implements neither IBedrockCommonSplitTextEmbeddingGenerationService nor IBedrockCommonBatchTextEmbeddingGenerationService. The switch expression's default arm is unreachable with the shipped factory (which only returns Amazon/Cohere embedding services that implement one of those interfaces), so this is a safety net against an unexpected service type.

Source

Thrown at dotnet/src/Connectors/Connectors.Amazon/Bedrock/Core/Clients/BedrockTextEmbeddingGenerationClient.cs:45

    {
        var serviceFactory = new BedrockServiceFactory();
        this._modelId = modelId;
        this._bedrockRuntime = bedrockRuntime;
        this._ioVectorGenerationService = serviceFactory.CreateTextEmbeddingService(modelId);
        this._logger = loggerFactory?.CreateLogger(this.GetType()) ?? NullLogger.Instance;
    }

    internal async Task<IList<ReadOnlyMemory<float>>> GenerateEmbeddingsAsync(
        IList<string> texts,
        CancellationToken cancellationToken = default)
    {
        Verify.NotNullOrEmpty(texts);

        return this._ioVectorGenerationService switch
        {
            IBedrockCommonSplitTextEmbeddingGenerationService => await this.GenerateSingleEmbeddingsAsync(texts, cancellationToken).ConfigureAwait(false),
            IBedrockCommonBatchTextEmbeddingGenerationService => await this.GenerateBatchEmbeddingsAsync(texts, cancellationToken).ConfigureAwait(false),
            _ => throw new NotSupportedException("Unsupported service type")
        };
    }

    private async Task<IList<ReadOnlyMemory<float>>> GenerateSingleEmbeddingsAsync(
        IList<string> texts,
        CancellationToken cancellationToken = default
    )
    {
        var embeddings = new List<ReadOnlyMemory<float>>();
        foreach (var item in texts)
        {
            try
            {
                var embedding = await this.GetEmbeddingForSingleTextAsync(item, cancellationToken).ConfigureAwait(false);
                embeddings.Add(embedding);
            }
            catch (Exception ex)
            {

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Confirm you are using an unmodified Connectors.Amazon package; if patched, ensure the embedding service class implements IBedrockCommonSplitTextEmbeddingGenerationService or IBedrockCommonBatchTextEmbeddingGenerationService.
  2. If contributing a new embedding provider, have the service implement one of those marker interfaces and map it in BedrockServiceFactory.CreateTextEmbeddingService.
  3. Report a bug against the connector if it reproduces on an unmodified release.
Defensive patterns

Strategy: validation

Validate before calling

// Unreachable on released packages; only relevant when injecting a custom service.
var svc = factory.CreateTextEmbeddingService(modelId);
if (svc is not IBedrockCommonSplitTextEmbeddingGenerationService
 && svc is not IBedrockCommonBatchTextEmbeddingGenerationService)
    throw new InvalidOperationException("Embedding service does not implement split or batch interface.");

Type guard

bool SupportsEmbeddingGeneration(IBedrockCommonTextEmbeddingGenerationService svc)
    => svc is IBedrockCommonSplitTextEmbeddingGenerationService
    || svc is IBedrockCommonBatchTextEmbeddingGenerationService;

Try / catch

try { await client.GenerateEmbeddingsAsync(texts, ct); }
catch (NotSupportedException ex) when (ex.Message == "Unsupported service type")
{ /* report a connector bug / ensure no patched service is in use */ throw; }

Prevention

When it happens

Trigger: Practically unreachable through public APIs: CreateTextEmbeddingService only returns AmazonEmbedGenerationService or CohereEmbedGenerationService, both of which implement one of the two interfaces. Could surface only if a custom/patched service is injected or a future embedding model is wired to a service class that implements IBedrockCommonTextEmbeddingGenerationService but neither split nor batch.

Common situations: Contributor added a new Bedrock embedding model+service but forgot to implement the split or batch marker interface. Reflection/diagnostic substitution of the service. Not something end users hit in released packages.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/39fb57b1b59d54e9. Report an issue: GitHub.