Skip to content

System.InvalidOperationException: ITextEmbeddingGenerationService not registered #17

@labidiaymen

Description

@labidiaymen

Hello

I’m encountering an issue while using `Codeblaze.SemanticKernel.Connectors.Ollama version 1.3.1. My code is throwing a System.InvalidOperationException, indicating that the ITextEmbeddingGenerationService has not been registered.

Here is a snippet of the code that leads to the error:

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Embeddings;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Plugins.Memory;
using TransactionChecker;
using Codeblaze.SemanticKernel.Connectors.Ollama;

var config = new ConfigurationBuilder()
    .AddUserSecrets<Config>()
    .Build();

var builder = Kernel.CreateBuilder();
builder.Services.AddTransient<HttpClient>();

builder.Services.AddSingleton<IConfiguration>(config);

#pragma warning disable SKEXP0070
builder.AddOllamaTextEmbeddingGeneration(
    modelId: "mistral",
    baseUrl: "http://localhost:11434"
);

builder.AddOllamaChatCompletion(
    modelId: "mistral",
    baseUrl: "http://localhost:11434"
);

var kernel = builder.Build();

var embeddingGenerator = kernel.Services.GetRequiredService<ITextEmbeddingGenerationService>();

Error:
System.InvalidOperationException: 'No service for type 'Microsoft.SemanticKernel.Embeddings.ITextEmbeddingGenerationService' has been registered.'

It appears that the ITextEmbeddingGenerationService is not being properly registered within the DI container.

<ItemGroup>
   <PackageReference Include="Codeblaze.SemanticKernel.Connectors.Ollama" Version="1.3.1" />
   <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.41.0" />
   <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
   <PackageReference Include="Microsoft.SemanticKernel" Version="1.17.2" />
   <PackageReference Include="Microsoft.SemanticKernel.Connectors.MistralAI" Version="1.18.0-alpha" />
   <PackageReference Include="Microsoft.SemanticKernel.Planners.Handlebars" Version="1.15.1-preview" />
   <PackageReference Include="Microsoft.SemanticKernel.Plugins.Memory" Version="1.18.0-alpha" />
</ItemGroup>

Here’s the list of package references included in my project:

Is there something I’m missing in the registration process, or is there a known issue with this version? Any guidance would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions