-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
The data type of the Id
member in the ScoredPoint
class may need to be changed to int
.
#794
Comments
@AwesomeYuer Qdrant definition for Points object allows for both 64-bit integers and UUID strings You can look at the ExtendedPointId object here: |
@tawalke Thanks for your feedback in advance. Here is some sample code for reference, I have test it passed and succeed when invoke
// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.SemanticKernel.Connectors.Memory.Qdrant.Http.ApiSchema;
#pragma warning disable CA1812 // Avoid uninstantiated internal classes: Used for Json Deserialization
internal sealed class SearchVectorsResponse : QdrantResponse
{
internal sealed class ScoredPoint
{
[JsonPropertyName("id")]
// add by AwesomeYuer@Microshaoft @ 2023-05-04
[JsonConverter(typeof(NumberToStringConverter))]
public string Id { get; }
[JsonPropertyName("version")]
public int Version { get; set; }
[JsonPropertyName("score")]
public double? Score { get; }
[JsonPropertyName("payload")]
public Dictionary<string, object> Payload { get; set; }
[JsonPropertyName("vector")]
public IEnumerable<float>? Vector { get; }
[JsonConstructor]
public ScoredPoint(string id, double? score, Dictionary<string, object> payload, IEnumerable<float> vector)
{
this.Id = id;
this.Score = score;
this.Payload = payload;
this.Vector = vector;
}
}
[JsonPropertyName("result")]
public IEnumerable<ScoredPoint> Results { get; set; }
[JsonConstructor]
public SearchVectorsResponse(IEnumerable<ScoredPoint> results)
{
this.Results = results;
}
#region private ================================================================================
private SearchVectorsResponse()
{
this.Results = new List<ScoredPoint>();
}
#endregion
}
#pragma warning restore CA1812 // Avoid uninstantiated internal classes
// add by AwesomeYuer@Microshaoft @ 2023-05-04
public class NumberToStringConverter : JsonConverter<string>
{
public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (typeToConvert != typeof(string))
{
throw new NotSupportedException($"{nameof(typeToConvert)}: {typeToConvert}");
}
var result = string.Empty;
var tokenType = reader.TokenType;
if
(
tokenType == JsonTokenType.String
)
{
result = reader.GetString();
}
else if
(
tokenType == JsonTokenType.Number
)
{
reader.TryGetInt32(out var valueInt);
result = valueInt.ToString("D", NumberFormatInfo.InvariantInfo);
}
else
{
throw new NotSupportedException($"{nameof(JsonTokenType)}.{tokenType}");
}
return result!;
}
public override void Write(Utf8JsonWriter writer, string @value, JsonSerializerOptions options)
{
writer.WriteStringValue(@value);
}
} |
good |
Another simple option we can consider: [JsonPropertyName("id")]
[JsonNumberHandling(JsonNumberHandling.WriteAsString)]
public string Id { get; } |
…1075) ### Motivation and Context Qdrant supports both string and int for the id of a ScoredPoint. This minor change allows the serialiser to handle both of these scenarios while retaining string as the type for SK. Thank you to @AwesomeYuer for the heads up in #794 ### Description Added a single attribute decorating the attribute that massages ints to string and leaves string as-is.
Closing as the PR has been merged. Please reopen if this issue persists! |
…icrosoft#1075) ### Motivation and Context Qdrant supports both string and int for the id of a ScoredPoint. This minor change allows the serialiser to handle both of these scenarios while retaining string as the type for SK. Thank you to @AwesomeYuer for the heads up in microsoft#794 ### Description Added a single attribute decorating the attribute that massages ints to string and leaves string as-is.
glad to hear that |
### Motivation and Context This PR fixes a regression introduced in #1075 and includes unit tests to correctly validate that both string and integer property ids are supported. ### Description The changes are based on the code suggested by AwesomeYuer over in #794 - the JsonNumberHandling attribute behaved in an unexpected way and was removed.
…oft#1313) ### Motivation and Context This PR fixes a regression introduced in microsoft#1075 and includes unit tests to correctly validate that both string and integer property ids are supported. ### Description The changes are based on the code suggested by AwesomeYuer over in microsoft#794 - the JsonNumberHandling attribute behaved in an unexpected way and was removed.
…oft#1313) ### Motivation and Context This PR fixes a regression introduced in microsoft#1075 and includes unit tests to correctly validate that both string and integer property ids are supported. ### Description The changes are based on the code suggested by AwesomeYuer over in microsoft#794 - the JsonNumberHandling attribute behaved in an unexpected way and was removed.
Describe the bug
The data type of the
Id
member in theScoredPoint
class may need to be changed toint
.semantic-kernel/dotnet/src/Connectors/Connectors.Memory.Qdrant/Http/ApiSchema/SearchVectorsResponse.cs
Line 14 in 562ab5b
To Reproduce
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: