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

Error while saving to Semantic Memory using NoSQL #6379

Closed
sandeepsnairms opened this issue May 23, 2024 · 1 comment · Fixed by #6393
Closed

Error while saving to Semantic Memory using NoSQL #6379

sandeepsnairms opened this issue May 23, 2024 · 1 comment · Fixed by #6393
Assignees

Comments

@sandeepsnairms
Copy link

sandeepsnairms commented May 23, 2024

I am trying to store into Semantic Memory using below code

public async Task SaveEmbeddingsAsync(string data, string id)
{
    try
    {
        await meomoryWithCosmosNoSQL.SaveReferenceAsync(
            collection: MemoryCollectionName,
            text: data,
            externalId:id,
            externalSourceName:"RecipeApp"
            );


    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());   
    }
}

I am getting the below exception and can’t make out what it refers to as input name.

"Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: 76cf2457-164b-49c0-b249-6e929bef8dfc; Reason: (Message: {"Errors":["The input name '' is invalid.

@Pilchie

@Pilchie
Copy link
Member

Pilchie commented May 23, 2024

I believe this is because the Cosmos NoSQL connector uses the key as a partition key, but SaveReferenceAsync doesn't pass in a key. I'll take a look probably tomorrow.

github-merge-queue bot pushed a commit that referenced this issue Jun 12, 2024
### Motivation and Context

When using SemanticTextMemory.SaveReferenceAsync, no value is passed for
the `Key` to use. In the Cosmos DB Memory Connector, we treat the "Key"
as the Id and PartitionKey, and so it has to have a value. Address this
by generating a `GUID` to use if none are provided.

### Description

* Assign a GUID key when the passed in `MemoryRecord.Key` is null or
empty so that CosmosDB always has a valid PartitionKey.
* While adding test coverage for this I noticed two things:
1. `withEmbeddings` is ignored in
`AzureCosmosDBNoSQLMemoryStore.GetAsync`. It's not clear whether it's
worth changing this, as point reads like the current one tend to be less
expensive than queries in Cosmos DB.
2. The SimilarityScore returned from `GetNearestAsync` wasn't actually a
similarity, it was a cosine distance. Normalize that.

Fixes #6379.

### Contribution Checklist

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Dmytro Struk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants