BotSharp/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/View/VectorKnowledgeViewModel.cs

49 lines
1.3 KiB
C#
Raw Normal View History

2024-08-15 23:19:10 +00:00
using BotSharp.Abstraction.VectorStorage.Models;
2024-08-15 03:46:01 +00:00
using System.Text.Json.Serialization;
namespace BotSharp.OpenAPI.ViewModels.Knowledges;
2024-08-15 23:19:10 +00:00
public class VectorKnowledgeViewModel
2024-08-15 03:46:01 +00:00
{
[JsonPropertyName("id")]
public string Id { get; set; }
[JsonPropertyName("data")]
2025-08-15 04:40:15 +00:00
public IDictionary<string, VectorPayloadValue> Data { get; set; }
2024-08-15 03:46:01 +00:00
2025-08-21 20:44:10 +00:00
[JsonPropertyName("payload")]
public IDictionary<string, object> Payload { get; set; }
2024-08-15 03:46:01 +00:00
[JsonPropertyName("score")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public double? Score { get; set; }
2025-08-08 04:43:07 +00:00
[JsonPropertyName("vector_dimension")]
2024-08-15 03:46:01 +00:00
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
2025-08-08 04:43:07 +00:00
public int? VectorDimension { get; set; }
2024-08-15 03:46:01 +00:00
2024-08-15 23:19:10 +00:00
public static VectorKnowledgeViewModel From(VectorSearchResult result)
2024-08-15 03:46:01 +00:00
{
2024-08-15 23:19:10 +00:00
return new VectorKnowledgeViewModel
2024-08-15 03:46:01 +00:00
{
Id = result.Id,
Data = result.Data,
2025-08-21 20:44:10 +00:00
Payload = result.Payload,
2024-08-15 03:46:01 +00:00
Score = result.Score,
2025-08-08 04:43:07 +00:00
VectorDimension = result.Vector?.Length
2024-08-15 03:46:01 +00:00
};
}
2025-08-06 22:40:47 +00:00
public static VectorKnowledgeViewModel From(VectorCollectionData data)
{
return new VectorKnowledgeViewModel
{
Id = data.Id,
Data = data.Data,
2025-08-21 20:44:10 +00:00
Payload = data.Payload,
2025-08-08 04:43:07 +00:00
VectorDimension = data.Vector?.Length
2025-08-06 22:40:47 +00:00
};
}
2024-08-15 03:46:01 +00:00
}