microsoft/semantic-kernel · error · KernelException

An error occurred while initializing the {nameof(BedrockText

Error message

An error occurred while initializing the {nameof(BedrockTextEmbeddingGenerationService)}: {ex.Message}

What it means

Thrown by AddBedrockTextEmbeddingGeneration (classic Kernel service DI) when the BedrockTextEmbeddingGenerationService factory throws. The factory resolves IAmazonBedrockRuntime and constructs the embedding service; the service constructor in turn calls BedrockServiceFactory.CreateTextEmbeddingService (which only supports 'amazon'/'cohere'). Any failure is wrapped in a KernelException.

Source

Thrown at dotnet/src/Connectors/Connectors.Amazon/Bedrock/Extensions/BedrockServiceCollectionExtensions.cs:144

            services.TryAddAWSService<IAmazonBedrockRuntime>();
        }
        services.AddKeyedSingleton<ITextEmbeddingGenerationService>(serviceId, (serviceProvider, _) =>
        {
            try
            {
                IAmazonBedrockRuntime runtime = bedrockRuntime ?? serviceProvider.GetRequiredService<IAmazonBedrockRuntime>();
                var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
                // Check if the runtime instance is a proxy object
                if (runtime.GetType().BaseType == typeof(AmazonServiceClient))
                {
                    // Cast to AmazonServiceClient and subscribe to the event
                    ((AmazonServiceClient)runtime).BeforeRequestEvent += BedrockClientUtilities.BedrockServiceClientRequestHandler;
                }
                return new BedrockTextEmbeddingGenerationService(modelId, runtime, loggerFactory);
            }
            catch (Exception ex)
            {
                throw new KernelException($"An error occurred while initializing the {nameof(BedrockTextEmbeddingGenerationService)}: {ex.Message}", ex);
            }
        });

        return services;
    }
}

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Register the runtime: services.AddAWSService<IAmazonBedrockRuntime>();.
  2. Use a supported embedding modelId without a region prefix: 'amazon.titan-embed-text-v2:0' or 'cohere.embed-english-v3:0'.
  3. Inspect ex.InnerException for the precise factory error.
  4. Pass an explicit IAmazonBedrockRuntime if constructed manually.

Example fix

// before
services.AddAWSService<IAmazonBedrockRuntime>();
services.AddBedrockTextEmbeddingGeneration("us.amazon.titan-embed-text-v2:0");
// wraps 'Unsupported model provider: us'

// after
services.AddAWSService<IAmazonBedrockRuntime>();
services.AddBedrockTextEmbeddingGeneration("amazon.titan-embed-text-v2:0");
Defensive patterns

Strategy: validation

Validate before calling

// strip cross-region prefix and validate provider for embeddings
static string Scrub(string id)
{
    foreach (var p in new[] { "us.", "eu.", "apac." }) if (id.StartsWith(p, StringComparison.OrdinalIgnoreCase)) return id[p.Length..];
    return id;
}
bool ok = Scrub(modelId).Split('.')[0] is "amazon" or "cohere";

Try / catch

try { services.AddBedrockTextEmbeddingGeneration(modelId); }
catch (KernelException ex) when (ex.InnerException?.Message.StartsWith("Unsupported model provider") == true)
{ throw new InvalidOperationException("Use an amazon. or cohere. embedding modelId without a cross-region prefix.", ex); }

Prevention

When it happens

Trigger: services.AddBedrockTextEmbeddingGeneration(modelId) without a registered IAmazonBedrockRuntime, or with a modelId whose provider is not 'amazon' or 'cohere' (CreateTextEmbeddingService throws NotSupportedException, wrapped here). Cross-region prefix ('us.') is also NOT scrubbed for embeddings, so 'us.amazon.titan-embed-text-v2:0' fails as 'Unsupported model provider: us'.

Common situations: Missing runtime registration. Passing a chat/text modelId to the embedding extension. Using a cross-region inference profile prefix for embeddings.

Related errors


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