Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Bug: AzureCosmosDBNoSQLMemoryStore failed to UpsertItemAsync #8348

Closed
nikkla opened this issue Aug 24, 2024 · 5 comments
Closed

.Net: Bug: AzureCosmosDBNoSQLMemoryStore failed to UpsertItemAsync #8348

nikkla opened this issue Aug 24, 2024 · 5 comments
Assignees
Labels
bug Something isn't working memory connector .NET Issue or Pull requests regarding .NET code

Comments

@nikkla
Copy link

nikkla commented Aug 24, 2024

Describe the bug
AzureCosmosDBNoSQLMemoryStore can not save Information to Azure NoSQL Cosmos DB because CosmosDb Method UpsertItemAsync() fails to execute with following message:

"One of the specified inputs is invalid"
Request URI: /apps/fd29713b-7ba0-4581-97e1-fcfd27fff740/services/25f80866-fd95-4d2d-83e1-6f1105dd2cbb/partitions/03101c5a-976d-4bcf-a84e-95c0c7d8d279/replicas/133689900035225751p/, RequestStats: Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum, SDK: Windows/10.0.22631 cosmos-netstandard-sdk/3.34.4

at Microsoft.Azure.Documents.StoreResult.ToResponse(RequestChargeTracker requestChargeTracker)     at Microsoft.Azure.Documents.ConsistencyWriter.WritePrivateAsync(DocumentServiceRequest request, TimeoutHelper timeout, Boolean forceRefresh)     at Microsoft.Azure.Documents.BackoffRetryUtility`1.ExecuteRetryAsync[TParam,TPolicy
](Func`1 callbackMethod, Func`3 callbackMethodWithParam, Func`2 callbackMethodWithPolicy, TParam param, IRetryPolicy retryPolicy, IRetryPolicy`1 retryPolicyWithArg, Func`1 inBackoffAlternateCallbackMethod, Func`2 inBackoffAlternateCallbackMethodWithPolicy, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action`1 preRetryCallback)     at Microsoft.Azure.Documents.ShouldRetryResult.ThrowIfDoneTrying(ExceptionDispatchInfo capturedException)     at Microsoft.Azure.Documents.BackoffRetryUtility`1.ExecuteRetryAsync[TParam,TPolicy
](Func`1 callbackMethod, Func`3 callbackMethodWithParam, Func`2 callbackMethodWithPolicy, TParam param, IRetryPolicy retryPolicy, IRetryPolicy`1 retryPolicyWithArg, Func`1 inBackoffAlternateCallbackMethod, Func`2 inBackoffAlternateCallbackMethodWithPolicy, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action`1 preRetryCallback)     at Microsoft.Azure.Documents.BackoffRetryUtility`1.ExecuteRetryAsync[TParam,TPolicy
](Func`1 callbackMethod, Func`3 callbackMethodWithParam, Func`2 callbackMethodWithPolicy, TParam param, IRetryPolicy retryPolicy, IRetryPolicy`1 retryPolicyWithArg, Func`1 inBackoffAlternateCallbackMethod, Func`2 inBackoffAlternateCallbackMethodWithPolicy, TimeSpan minBackoffForInBackoffCallback, CancellationToken cancellationToken, Action`1 preRetryCallback)     at Microsoft.Azure.Documents.ConsistencyWriter.WriteAsync(DocumentServiceRequest entity, TimeoutHelper timeout, Boolean forceRefresh, CancellationToken cancellationToken)     at Microsoft.Azure.Documents.ReplicatedResourceClient.<>c__DisplayClass32_0.<<InvokeAsync>b__0>d.MoveNext()  --- End of stack trace from previous location ---     at Microsoft.Azure.Documents.RequestRetryUtility.ProcessRequestAsync[TRequest,IRetriableResponse
](Func`1 executeAsync, Func`1 prepareRequest, IRequestRetryPolicy`2 policy, CancellationToken cancellationToken, Func`1 inBackoffAlternateCallbackMethod, Nullable`1 minBackoffForInBackoffCallback)     at Microsoft.Azure.Documents.ShouldRetryResult.ThrowIfDoneTrying(ExceptionDispatchInfo capturedException)     at Microsoft.Azure.Documents.RequestRetryUtility.ProcessRequestAsync[TRequest,IRetriableResponse
](Func`1 executeAsync, Func`1 prepareRequest, IRequestRetryPolicy`2 policy, CancellationToken cancellationToken, Func`1 inBackoffAlternateCallbackMethod, Nullable`1 minBackoffForInBackoffCallback)     at Microsoft.Azure.Documents.RequestRetryUtility.ProcessRequestAsync[TRequest,IRetriableResponse
](Func`1 executeAsync, Func`1 prepareRequest, IRequestRetryPolicy`2 policy, CancellationToken cancellationToken, Func`1 inBackoffAlternateCallbackMethod, Nullable`1 minBackoffForInBackoffCallback)     at Microsoft.Azure.Documents.StoreClient.ProcessMessageAsync(DocumentServiceRequest request, CancellationToken cancellationToken, IRetryPolicy retryPolicy)     at Microsoft.Azure.Cosmos.Handlers.TransportHandler.ProcessMessageAsync(RequestMessage request, CancellationToken cancellationToken)     at Microsoft.Azure.Cosmos.Handlers.TransportHandler.SendAsync(RequestMessage request, CancellationToken cancellationToken)

To Reproduce
Steps to reproduce the behavior:

  1. Setup MemoryStore:
var comsmosClient = new CosmosClient(Environment.GetEnvironmentVariable("DocumentEndpointConnectionString"));
var embedding = new Embedding
{
    DataType = VectorDataType.Float32,
    DistanceFunction = DistanceFunction.Cosine,
    Path = "/embedding",
    Dimensions = 1536,
};

var indexPolicy = new IndexingPolicy
{
    VectorIndexes = new()
    {
        new()
        {
            Path = embedding.Path,
            Type = VectorIndexType.QuantizedFlat
        }
    }
};

new MemoryBuilder()
            .WithOpenAITextEmbeddingGeneration("text-embedding-3-small", Environment.GetEnvironmentVariable("openAiKey")!)
            .WithMemoryStore(new AzureCosmosDBNoSQLMemoryStore(comsmosClient, "memoryDb", new VectorEmbeddingPolicy([embedding]), indexPolicy))
            .Build();
  1. Store new Item to Memory:
private readonly ISemanticTextMemory semanticTextMemory;

---
var content = "Some awesome content";
var id = await semanticTextMemory.SaveInformationAsync(CollectionName, content, Guid.NewGuid().ToString());

Expected behavior
The Semantic Text Memory stores the information correctly without errors in the Azure NoSQL Cosmos DB.

Screenshots
CosmosVectorIndex

Platform

  • Windows 11
  • Visual Studio 17.11.0
  • C# Azure Function over local debugging
  • Sources:
    • Microsoft.Azure.Cosmos (3.43.0-preview.0)
    • Microsoft.SemanticKernel (1.18.0-rc)
    • Microsoft.SemanticKernel.Connectors.AzureCosmosDBNoSQL (1.18.0-alpha)

Additional context
Semantic Kernel correctly creates the container and also adds the vector index. The error only occurs when storing the information.

@nikkla nikkla added the bug Something isn't working label Aug 24, 2024
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Aug 24, 2024
@github-actions github-actions bot changed the title Bug: AzureCosmosDBNoSQLMemoryStore failed to UpsertItemAsync .Net: Bug: AzureCosmosDBNoSQLMemoryStore failed to UpsertItemAsync Aug 24, 2024
@dmytrostruk
Copy link
Member

Hi @nikkla ! While we investigate this issue, I would recommend trying newly updated NoSQL connector which allows to work with your custom schema. You can try it now by downloading SK v1.17.2:
https://www.nuget.org/packages/Microsoft.SemanticKernel.Connectors.AzureCosmosDBNoSQL/1.17.2-alpha

Class to operate with collections is AzureCosmosDBNoSQLVectorStoreRecordCollection:
https://github.com/microsoft/semantic-kernel/blob/main/dotnet/src/Connectors/Connectors.Memory.AzureCosmosDBNoSQL/AzureCosmosDBNoSQLVectorStoreRecordCollection.cs

Would be great to receive your feedback, thanks!

@nikkla
Copy link
Author

nikkla commented Aug 26, 2024

Hi @dmytrostruk thank you for your answer. As a mentioned in the bug description, I'm currently using the newest version of the AzureCosmosDBNoSQL which is 1.18.0-alpha referring to Nuget https://www.nuget.org/packages/Microsoft.SemanticKernel.Connectors.AzureCosmosDBNoSQL.

I'm using no custom schema, the collection was created by Semantic Kernel. I just added the vector index with semantic kernel based on the documentation I could found. Based on the error calling stack it seems like the error is not in the vector index, because the upsert failed. May Semantic Kernel not passing the correct arguments.

@markwallace-microsoft
Copy link
Member

@dmytrostruk is this still an issue with the new Vector Store implementation?

@dmytrostruk
Copy link
Member

@markwallace-microsoft I can't reproduce this issue with the new Vector Store implementation.
@nikkla I would recommend using this documentation to work with Cosmos NoSQL connector and let us know if the issue can be still reproduced. Thanks!

@dmytrostruk
Copy link
Member

@nikkla I'm going to close this issue, since AzureCosmosDBNoSQLMemoryStore is no longer supported. For Cosmos DB NoSQL connector, please use following documentation:
https://learn.microsoft.com/en-us/semantic-kernel/concepts/vector-store-connectors/out-of-the-box-connectors/azure-cosmosdb-nosql-connector?pivots=programming-language-csharp

@dmytrostruk dmytrostruk moved this from Bug to Sprint: Done in Semantic Kernel Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working memory connector .NET Issue or Pull requests regarding .NET code
Projects
Archived in project
Development

No branches or pull requests

4 participants