microsoft / kernel-memory

RAG architecture: index and query any data using LLM and natural language, track sources, show citations, asynchronous memory patterns.
https://microsoft.github.io/kernel-memory
MIT License
1.63k stars 313 forks source link

Method not found: 'Void Azure.AI.OpenAI.AzureOpenAIClientOptions.set_ApplicationId(System.String) #821

Closed johnnyreilly closed 2 months ago

johnnyreilly commented 2 months ago

Context / Scenario

Following upgrading to 0.76.240930.3, we started to see errors when we ran our application:

[BE]       Error processing document
[BE]       System.MissingMethodException: Method not found: 'Void Azure.AI.OpenAI.AzureOpenAIClientOptions.set_ApplicationId(System.String)'.
[BE]          at Microsoft.KernelMemory.AI.AzureOpenAI.Internals.AzureOpenAIClientBuilder.Build(AzureOpenAIConfig config, HttpClient httpClient, ILoggerFactory loggerFactory)
[BE]          at Microsoft.KernelMemory.AI.AzureOpenAI.AzureOpenAITextEmbeddingGenerator..ctor(AzureOpenAIConfig config, ITextTokenizer textTokenizer, ILoggerFactory loggerFactory, HttpClient httpClient)
[BE]          at Microsoft.KernelMemory.KernelMemoryBuilderExtensions.WithAzureOpenAITextEmbeddingGeneration(IKernelMemoryBuilder builder, AzureOpenAIConfig config, ITextTokenizer textTokenizer, ILoggerFactory loggerFactory, Boolean onlyForRetrieval, HttpClient httpClient)

Possible cause

After some further investigation it seems to be related to Azure.AI.OpenAI. It may not be directly a KM issue at all. KM works with:

    <PackageReference Include="Azure.AI.OpenAI" Version="2.0.0-beta.5" />

It doesn't with

    <PackageReference Include="Azure.AI.OpenAI" Version="2.0.0-beta.6" />

or

    <PackageReference Include="Azure.AI.OpenAI" Version="2.0.0" />

It looks like it the issue there might be related to a property name change; ApplicationId -> UserAgentApplicationId:

-        Core.TelemetryDetails telemetryDetails = new(typeof(AzureOpenAIClient).Assembly, options?.ApplicationId);
+        Core.TelemetryDetails telemetryDetails = new(typeof(AzureOpenAIClient).Assembly, options?.UserAgentApplicationId);

Before: https://github.com/Azure/azure-sdk-for-net/blob/f5b4dfdd191e90df616209dd4d9d434a769dc8e0/sdk/openai/Azure.AI.OpenAI/src/Custom/AzureOpenAIClient.cs#L302 After: https://github.com/Azure/azure-sdk-for-net/blob/c5bc53adb7006da46c9e5cbe1092f6e1e074b76d/sdk/openai/Azure.AI.OpenAI/src/Custom/AzureOpenAIClient.cs#L306

So if you pin to beta-5 it's fine - but ideally it would be great to fix this in KM I guess?

Potential fix?

Would the fixes be required here?

What happened?

The error above happens when we try to use the following code (which worked with previous versions of KM):

        _memory = new KernelMemoryBuilder()
            .WithAzureOpenAITextEmbeddingGeneration(new AzureOpenAIConfig
            {
                APIType = AzureOpenAIConfig.APITypes.EmbeddingGeneration,
                Auth = AzureOpenAIConfig.AuthTypes.AzureIdentity,
                Endpoint = $"https://{openAIClientParametersEmbeddings.CognitiveServicesAccountName}.openai.azure.com/",
                Deployment = openAIClientParametersEmbeddings.DeploymentName
            })

Importance

I cannot use Kernel Memory with Azure.AI.OpenAI@2.0.0

Platform, Language, Versions

.NET 8, Kernel Memory 0.76.240930.3

Other thoughts

I'm also wondering if I should avoid directly referencing Azure.AI.OpenAI as a package reference as it's a transitive dependency of https://www.nuget.org/packages/Microsoft.SemanticKernel/#dependencies-body-tab

larcai commented 2 months ago

We are also stuck I think it is similar to https://github.com/microsoft/semantic-kernel/issues/8956

dluc commented 2 months ago

That’s an unfortunate side effect of using serverless mode (and beta libraries). This is why we recommend running KM as a service - to keep KM’s internal dependencies separate from your app’s dependencies.

If your code references KM serverless classes and explicitly uses Azure.AI.OpenAI, it’s important to align your app with the same version KM is using to prevent breaking changes, especially since the Azure OpenAI library is still in beta. The same applies to any other libraries KM depends on, if different versions are used in your solution.

For reference: