Add the Scroll method

pull/1/head
Ogoun 3 years ago
parent 11b0c5634f
commit 03fa1f503b

@ -0,0 +1,9 @@
namespace ZeroLevel.Qdrant.Models
{
public sealed class Point
{
public long id { get; set; }
public dynamic payload;
public double[] vector;
}
}

@ -3,5 +3,7 @@
internal sealed class PointsRequest internal sealed class PointsRequest
{ {
public long[] ids { get; set; } public long[] ids { get; set; }
/*public bool with_payload { get; set; } = true;
public bool with_vector { get; set; } = true;*/
} }
} }

@ -0,0 +1,51 @@
using System;
using System.Text;
using ZeroLevel.Qdrant.Models.Filters;
namespace ZeroLevel.Qdrant.Models.Requests
{
internal sealed class ScrollRequest
{
public Filter Filter { get; set; }
public bool WithPayload { get; set; } = true;
public bool WithVector { get; set; } = true;
public long Limit { get; set; }
public long Offset { get; set; }
/*
{
"filter": {
"must": [
{ "has_id": [0, 3, 100] }
]
},
"limit": 10000,
"offset": 0,
"with_payload": false,
"with_vector": true
}
*/
public string ToJson()
{
var json = new StringBuilder();
json.Append("{");
if (Filter == null || Filter.IsEmpty)
{
throw new ArgumentException("Filter must not by null or empty");
}
else
{
json.Append(Filter.ToJSON());
json.Append(',');
}
json.Append($"\"limit\": {Limit},");
json.Append($"\"offset\": {Offset},");
json.Append($"\"with_payload\": {WithPayload.ToString().ToLowerInvariant()},");
json.Append($"\"with_vector\": {WithVector.ToString().ToLowerInvariant()}");
json.Append("}");
return json.ToString();
}
}
}

@ -1,12 +1,5 @@
namespace ZeroLevel.Qdrant.Models.Responces namespace ZeroLevel.Qdrant.Models.Responces
{ {
public sealed class Point
{
public long id { get; set; }
public dynamic payload;
public double[] vector;
}
public sealed class PointResponse public sealed class PointResponse
{ {
public Point[] result { get; set; } public Point[] result { get; set; }

@ -0,0 +1,15 @@
namespace ZeroLevel.Qdrant.Models.Responces
{
public sealed class ScrollResult
{
public Point[] points { get; set; }
public long? next_page_offset { get; set; }
}
public sealed class ScrollResponse
{
public ScrollResult result { get; set; }
public string status { get; set; }
public float time { get; set; }
}
}

@ -171,8 +171,7 @@ namespace ZeroLevel.Qdrant
var points = new PointsRequest { ids = ids }; var points = new PointsRequest { ids = ids };
var json = JsonConvert.SerializeObject(points); var json = JsonConvert.SerializeObject(points);
var data = new StringContent(json, Encoding.UTF8, "application/json"); var data = new StringContent(json, Encoding.UTF8, "application/json");
var url = $"/collections/{collection_name}/points"; string url = $"/collections/{collection_name}/points";
var response = await _request<PointResponse>(url, new HttpMethod("POST"), data); var response = await _request<PointResponse>(url, new HttpMethod("POST"), data);
return InvokeResult.Succeeding<PointResponse>(response); return InvokeResult.Succeeding<PointResponse>(response);
} }
@ -182,6 +181,30 @@ namespace ZeroLevel.Qdrant
return InvokeResult.Fault<PointResponse>($"[QdrantClient.Points] Collection name: {collection_name}.\r\n{ex.ToString()}"); return InvokeResult.Fault<PointResponse>($"[QdrantClient.Points] Collection name: {collection_name}.\r\n{ex.ToString()}");
} }
} }
/// <summary>
/// There is a method for retrieving points by their ids.
/// </summary>
public async Task<InvokeResult<ScrollResponse>> Scroll(string collection_name, Filter filter, long limit, long offset = 0, bool with_vector = true, bool with_payload = true)
{
try
{
var scroll = new ScrollRequest { Filter = filter, Limit = limit, Offset = offset, WithPayload = with_payload, WithVector = with_vector };
var json = scroll.ToJson();
var data = new StringContent(json, Encoding.UTF8, "application/json");
string url = url = $"/collections/{collection_name}/points/scroll";
var response = await _request<ScrollResponse>(url, new HttpMethod("POST"), data);
return InvokeResult.Succeeding<ScrollResponse>(response);
}
catch (Exception ex)
{
Log.Error(ex, $"[QdrantClient.Scroll] Collection name: {collection_name}.");
return InvokeResult.Fault<ScrollResponse>($"[QdrantClient.Scroll] Collection name: {collection_name}.\r\n{ex.ToString()}");
}
}
/// <summary> /// <summary>
/// Record-oriented of creating batches /// Record-oriented of creating batches
/// </summary> /// </summary>

Loading…
Cancel
Save

Powered by TurnKey Linux.