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: Cannot get the value of a token type 'False' as a number when using Chroma Memory Store #2790

Closed
paolosalvatori opened this issue Sep 12, 2023 · 3 comments · Fixed by #2796
Assignees
Labels
.NET Issue or Pull requests regarding .NET code python Pull requests for the Python Semantic Kernel triage

Comments

@paolosalvatori
Copy link
Member

paolosalvatori commented Sep 12, 2023

Describe the bug
It looks like the problem is still there. I use the latest Microsoft.SemanticKernel.Connectors.Memory.Chroma, 0.24.230911.2-preview nuget package in the 09-memory-with-chroma.ipynb sample. I get the following error:

**Error: System.Text.Json.JsonException: The JSON value could not be converted to Microsoft.SemanticKernel.Memory.MemoryRecordMetadata. Path: $.is_reference | LineNumber: 0 | BytePositionInLine: 102.
---> System.InvalidOperationException: Cannot get the value of a token type 'False' as a number.

The issue has been already reported several times: #2568, #2049 and a PR was created: #2072

To Reproduce
Steps to reproduce the behavior:

  1. Go to09-memory-with-chroma.ipynb polygot notebook
  2. Use the Microsoft.SemanticKernel.Connectors.Memory.Chroma, 0.24.230911.2-preview nuget package
  3. Run the sample
  4. See error:
**Error: System.Text.Json.JsonException: The JSON value could not be converted to Microsoft.SemanticKernel.Memory.MemoryRecordMetadata. Path: $.is_reference | LineNumber: 0 | BytePositionInLine: 102.
---> System.InvalidOperationException: Cannot get the value of a token type 'False' as a number.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedNumber(JsonTokenType tokenType)
at System.Text.Json.Utf8JsonReader.TryGetInt16(Int16& value)
at Microsoft.SemanticKernel.Connectors.Memory.Chroma.ChromaBooleanConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.TryReadAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state, Object& value)
at System.Text.Json.Serialization.Converters.LargeObjectWithParameterizedConstructorConverter`1.ReadAndCacheConstructorArgument(ReadStack& state, Utf8JsonReader& reader, JsonParameterInfo jsonParameterInfo)
at System.Text.Json.Serialization.Converters.ObjectWithParameterizedConstructorConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
at Microsoft.SemanticKernel.Connectors.Memory.Chroma.ChromaMemoryStore.GetMetadataForMemoryRecord(List`1 metadatas, Int32 recordIndex)
at Microsoft.SemanticKernel.Connectors.Memory.Chroma.ChromaMemoryStore.GetMemoryRecordFromModel(List`1 metadatas, List`1 embeddings, List`1 ids, Int32 recordIndex)
at Microsoft.SemanticKernel.Connectors.Memory.Chroma.ChromaMemoryStore.GetMemoryRecordFromQueryResultModel(ChromaQueryResultModel queryResultModel, Int32 recordIndex)
at Microsoft.SemanticKernel.Connectors.Memory.Chroma.ChromaMemoryStore.GetNearestMatchesAsync(String collectionName, ReadOnlyMemory`1 embedding, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext()
at Microsoft.SemanticKernel.Connectors.Memory.Chroma.ChromaMemoryStore.GetNearestMatchesAsync(String collectionName, ReadOnlyMemory`1 embedding, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at Microsoft.SemanticKernel.Memory.SemanticTextMemory.SearchAsync(String collection, String query, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext()
at Microsoft.SemanticKernel.Memory.SemanticTextMemory.SearchAsync(String collection, String query, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext()
at Microsoft.SemanticKernel.Memory.SemanticTextMemory.SearchAsync(String collection, String query, Int32 limit, Double minRelevanceScore, Boolean withEmbeddings, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at System.Linq.AsyncEnumerable.<TryGetFirst>g__Core|95_0[TSource](IAsyncEnumerable`1 source, CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/FirstOrDefault.cs:line 130
at System.Linq.AsyncEnumerable.<TryGetFirst>g__Core|95_0[TSource](IAsyncEnumerable`1 source, CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/FirstOrDefault.cs:line 132
at System.Linq.AsyncEnumerable.<FirstOrDefaultAsync>g__Core|91_0[TSource](IAsyncEnumerable`1 source, CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/FirstOrDefault.cs:line 30
at Submission#6.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)**

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Platform**
 - OS: [e.g. Windows, Mac]
 - IDE: [e.g. Visual Studio, VS Code]
 - Language: [e.g. C#, Python]
 - Source: [e.g. NuGet package version 0.1.0, pip package version 0.1.0, main branch of repository]

**Additional context**
Add any other context about the problem here.
@shawncal shawncal added .NET Issue or Pull requests regarding .NET code python Pull requests for the Python Semantic Kernel triage labels Sep 12, 2023
@github-actions github-actions bot changed the title Cannot get the value of a token type 'False' as a number when using Chroma Memory Store Python: Cannot get the value of a token type 'False' as a number when using Chroma Memory Store Sep 12, 2023
@github-actions github-actions bot changed the title Cannot get the value of a token type 'False' as a number when using Chroma Memory Store .Net: Cannot get the value of a token type 'False' as a number when using Chroma Memory Store Sep 12, 2023
@dmytrostruk dmytrostruk self-assigned this Sep 12, 2023
@dmytrostruk
Copy link
Member

@paolosalvatori Good catch, thank you for creating this issue!
Unfortunately, this is happening every time when Chroma releases breaking changes, so we need to handle them on our side as well.

This PR should resolve an issue: #2796
In case you need a quick fix, you should be able to run examples with Chroma 0.4.0. I just checked notebook and integration tests and it's working as expected.

As part of my PR, I've updated notebook and Chroma README file to mention the latest Chroma version, which was used to verify Chroma connector and examples.

I noticed that Chroma notebook also contains some obsolete code, which should be updated together with SK version upgrade. We will update it as soon as new SK version will be published, including PR mentioned above.

Thanks again!

github-merge-queue bot pushed a commit that referenced this issue Sep 12, 2023
…2796)

### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Resolves: #2790

This PR contains changes to update processing of boolean values in order
to be compatible with Chroma 0.4.10.
With new Chroma updates we need to update Chroma connector on regular
basis to be compatible.

The note has been added to Chroma notebook and README file to show the
latest version of Chroma, which was used to verify the connector.

In order to fix notebook to be compatible with latest version, the
notebook should be updated as soon as this PR is released.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
1. Removed `ChromaBooleanConverter` to be compatible with Chroma 0.4.10.
2. Added note with latest tested version of Chroma in notebook and
README file.
3. Updated unit tests.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [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 😄
@paolosalvatori
Copy link
Member Author

Thanks @dmytrostruk, will the fix ship in the next SK release? If yes, what is the ETA?

@dmytrostruk
Copy link
Member

@paolosalvatori Preview version of package with fix should be published to NuGet next Monday (18th September).

But if you want to work with it earlier, we have nightly builds, the latest one was published 7 hours ago, which should include the fix:
https://github.com/microsoft/semantic-kernel/pkgs/nuget/Microsoft.SemanticKernel.Connectors.Memory.Chroma/127417566

SOE-YoungS pushed a commit to SOE-YoungS/semantic-kernel that referenced this issue Nov 1, 2023
…icrosoft#2796)

### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Resolves: microsoft#2790

This PR contains changes to update processing of boolean values in order
to be compatible with Chroma 0.4.10.
With new Chroma updates we need to update Chroma connector on regular
basis to be compatible.

The note has been added to Chroma notebook and README file to show the
latest version of Chroma, which was used to verify the connector.

In order to fix notebook to be compatible with latest version, the
notebook should be updated as soon as this PR is released.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
1. Removed `ChromaBooleanConverter` to be compatible with Chroma 0.4.10.
2. Added note with latest tested version of Chroma in notebook and
README file.
3. Updated unit tests.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [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 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Issue or Pull requests regarding .NET code python Pull requests for the Python Semantic Kernel triage
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants