-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: Fix for Chroma boolean values processing (#2072)
### 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. --> With latest updates in Chroma ([Release 0.4.0](https://github.com/chroma-core/chroma/releases/tag/0.4.0)), boolean values are automatically converted to numeric representation (False = 0, True = 1). This PR contains changes to handle this case and convert boolean values properly. Should fix #2049 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> 1. Implemented `ChromaBooleanConverter` to be used during Chroma response deserialization. 2. Added more fixes based on new Chroma version - changed error message when trying to delete non-existent collection. 3. Added integration test to verify boolean values processing. ### 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#dev-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: Abby Harrison <[email protected]>
- Loading branch information
1 parent
9bdeb42
commit b79f3a0
Showing
5 changed files
with
98 additions
and
15 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
dotnet/src/Connectors/Connectors.Memory.Chroma/ChromaBooleanConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Microsoft.SemanticKernel.Connectors.Memory.Chroma; | ||
|
||
/// <summary> | ||
/// JSON Converter for Chroma boolean values. | ||
/// </summary> | ||
public class ChromaBooleanConverter : JsonConverter<bool> | ||
{ | ||
/// <inheritdoc/> | ||
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (!reader.TryGetInt16(out short value)) | ||
{ | ||
return false; | ||
} | ||
|
||
return Convert.ToBoolean(value); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteNumberValue(Convert.ToDecimal(value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters