add order by
This commit is contained in:
parent
ed1576f7e0
commit
0c0101408b
|
|
@ -9,11 +9,20 @@ public class VectorFilter : StringIdPagination
|
|||
/// Filter group: each item contains a logical operator and a list of key-value pairs
|
||||
/// </summary>
|
||||
[JsonPropertyName("filter_groups")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public IEnumerable<VectorFilterGroup>? FilterGroups { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Order by a specific field
|
||||
/// </summary>
|
||||
[JsonPropertyName("order_by")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public VectorSort? OrderBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Included payload fields
|
||||
/// </summary>
|
||||
[JsonPropertyName("fields")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public IEnumerable<string>? Fields { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
namespace BotSharp.Abstraction.VectorStorage.Models;
|
||||
|
||||
public class VectorSort
|
||||
{
|
||||
[JsonPropertyName("field")]
|
||||
public string? Field { get; set; }
|
||||
|
||||
[JsonPropertyName("order")]
|
||||
public string? Order { get; set; } = "desc";
|
||||
}
|
||||
|
|
@ -144,6 +144,7 @@ public class QdrantDb : IVectorDb
|
|||
|
||||
Filter? queryFilter = BuildQueryFilter(filter.FilterGroups);
|
||||
WithPayloadSelector? payloadSelector = BuildPayloadSelector(filter.Fields);
|
||||
OrderBy? orderBy = BuildOrderBy(filter.OrderBy);
|
||||
|
||||
var client = GetClient();
|
||||
var tasks = new List<Task>();
|
||||
|
|
@ -154,6 +155,7 @@ public class QdrantDb : IVectorDb
|
|||
limit: (uint)filter.Size,
|
||||
offset: !string.IsNullOrWhiteSpace(filter.StartId) ? new PointId { Uuid = filter.StartId } : null,
|
||||
filter: queryFilter,
|
||||
orderBy: orderBy,
|
||||
payloadSelector: payloadSelector,
|
||||
vectorsSelector: filter.WithVector);
|
||||
|
||||
|
|
@ -371,7 +373,13 @@ public class QdrantDb : IVectorDb
|
|||
|
||||
var client = GetClient();
|
||||
var schemaType = ConvertPayloadSchemaType(options.FieldSchemaType);
|
||||
var result = await client.CreatePayloadIndexAsync(collectionName, options.FieldName, schemaType);
|
||||
var result = await client.CreatePayloadIndexAsync(collectionName, options.FieldName, schemaType, indexParams: new()
|
||||
{
|
||||
IntegerIndexParams = new()
|
||||
{
|
||||
Range = true
|
||||
}
|
||||
});
|
||||
return result.Status == UpdateStatus.Completed;
|
||||
}
|
||||
|
||||
|
|
@ -618,6 +626,20 @@ public class QdrantDb : IVectorDb
|
|||
return payloadSelector;
|
||||
}
|
||||
|
||||
private OrderBy? BuildOrderBy(VectorSort? sort)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(sort?.Field))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new OrderBy
|
||||
{
|
||||
Key = sort.Field,
|
||||
Direction = sort.Order == "asc" ? Direction.Asc : Direction.Desc
|
||||
};
|
||||
}
|
||||
|
||||
private PayloadSchemaType ConvertPayloadSchemaType(string schemaType)
|
||||
{
|
||||
PayloadSchemaType res;
|
||||
|
|
|
|||
Loading…
Reference in a new issue