Refactoring & QdrantClient

pull/4/head
Ogoun 1 year ago
parent 05a9b779ba
commit fdaeeb3e5d

@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -1,51 +0,0 @@
namespace AppContainer
{
public class Endpoint
{
public string VersionEndpoint { get; set; }
public string AppEndpoint { get; set; }
public string PingEndpoint { get; set; }
public string Token { get; set; }
}
public class HostSettings
{
public IEnumerable<Endpoint> Endpoints { get; set; }
public string EntryClass { get; set; }
public string EntryMethod { get; set; }
}
public class Host
{
private readonly HostSettings _settings;
public Host(HostSettings settings)
{
if (settings == null) throw new ArgumentNullException(nameof(settings));
_settings = settings;
}
public async Task<bool> HasUpdate()
{
if (_settings.Endpoints != null)
{
foreach (var ep in _settings.Endpoints)
{
try
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("token", ep.Token);
var response = await client.GetAsync(ep.PingEndpoint);
response.EnsureSuccessStatusCode();
}
}
catch (Exception ex)
{
}
}
}
return false;
}
}
}

@ -8,7 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\ZeroLevel\ZeroLevel.csproj" /> <ProjectReference Include="..\..\..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\ZeroLevel\ZeroLevel.csproj" /> <ProjectReference Include="..\..\..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\ZeroLevel\ZeroLevel.csproj" /> <ProjectReference Include="..\..\..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\ZeroLevel\ZeroLevel.csproj" /> <ProjectReference Include="..\..\..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

@ -11,15 +11,15 @@ namespace FileTransferServer
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
private FileReceiver _server = null!;
private readonly IExchange _exchange;
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
_exchange = Bootstrap.CreateExchange(); _exchange = Bootstrap.CreateExchange();
} }
private FileReceiver _server;
private IExchange _exchange;
private void Button_Click(object sender, RoutedEventArgs e) private void Button_Click(object sender, RoutedEventArgs e)
{ {
int port = -1; int port = -1;

@ -9,9 +9,9 @@ namespace HNSWDemo
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
new QuantizatorTest().Run(); //new QuantizatorTest().Run();
// new AutoClusteringMNISTTest().Run(); //new AutoClusteringMNISTTest().Run();
// new AccuracityTest().Run(); new AccuracityTest().Run();
Console.WriteLine("Completed"); Console.WriteLine("Completed");
Console.ReadKey(); Console.ReadKey();
} }

@ -27,7 +27,7 @@ namespace HNSWDemo.Tests
var sw = new Stopwatch(); var sw = new Stopwatch();
var test = new VectorsDirectCompare(samples, Metrics.CosineDistance); var test = new VectorsDirectCompare(samples, Metrics.CosineDistance);
var world = new SmallWorld<float[]>(NSWOptions<float[]>.Create(8, 12, 100, 100, Metrics.CosineDistance)); var world = new SmallWorld<float[]>(NSWOptions<float[]>.Create(8, 16, 100, 100, (a, b) => (float)Metrics.DotProductDistance(a, b)));
sw.Start(); sw.Start();
var ids = world.AddItems(samples.ToArray()); var ids = world.AddItems(samples.ToArray());

@ -83,7 +83,7 @@ namespace HNSWDemo.Tests
var exists = links.Where(n => n > 0).ToArray(); var exists = links.Where(n => n > 0).ToArray();
var histogram = new Histogram(HistogramMode.LOG, links); var histogram = new Histogram(HistogramMode.LOG, links);
DrawHistogram(histogram, @"D:\Mnist\histogram.jpg"); DrawHistogram(histogram, @"D:\histogram.jpg");
var clusters = AutomaticGraphClusterer.DetectClusters(world); var clusters = AutomaticGraphClusterer.DetectClusters(world);
Console.WriteLine($"Found {clusters.Count} clusters"); Console.WriteLine($"Found {clusters.Count} clusters");

@ -2,9 +2,6 @@
{ {
public static class Compressor public static class Compressor
{ {
/// <summary>
/// Упаковка набора чисел в массив байтов
/// </summary>
public static byte[] GetEncodedBytes(IEnumerable<ulong> list, ref ulong last) public static byte[] GetEncodedBytes(IEnumerable<ulong> list, ref ulong last)
{ {
byte[] segmentsBytes; byte[] segmentsBytes;
@ -38,7 +35,6 @@
} }
} }
public static void Write7BitEncodedULong(this MemoryStream writer, ulong value) public static void Write7BitEncodedULong(this MemoryStream writer, ulong value)
{ {
var first = true; var first = true;

@ -17,14 +17,9 @@
{ {
public static MsisdnParts SplitParts(this ulong msisdn) public static MsisdnParts SplitParts(this ulong msisdn)
{ {
//расчитываем только на номера российской нумерации ("7" и 10 цифр)
//это числа от 70_000_000_000 до 79_999_999_999
if (msisdn < 70_000_000_000 || msisdn > 79_999_999_999) throw new ArgumentException(nameof(msisdn)); if (msisdn < 70_000_000_000 || msisdn > 79_999_999_999) throw new ArgumentException(nameof(msisdn));
var firstDigit = (int)((msisdn / 1_000_000_000L) % 10); var firstDigit = (int)((msisdn / 1_000_000_000L) % 10);
var otherDigits = (int)(msisdn % 1_000_000_000L); var otherDigits = (int)(msisdn % 1_000_000_000L);
return new MsisdnParts(firstDigit, otherDigits); return new MsisdnParts(firstDigit, otherDigits);
} }
@ -45,42 +40,25 @@
} }
} }
/// <summary>
/// возвращаются только номера российской нумерации ("7" и 10 цифр) в виде long
/// </summary>
/// <param name="source"></param>
/// <param name="msisdn"></param>
/// <returns></returns>
public static bool TryParseMsisdn(this string source, out ulong msisdn) public static bool TryParseMsisdn(this string source, out ulong msisdn)
{ {
var line = source.Trim(); var line = source.Trim();
var length = line.Length; var length = line.Length;
msisdn = 0; msisdn = 0;
//допустимы форматы номеров "+71234567890", "71234567890", "1234567890"
if (length < 10 || length > 12) return false; if (length < 10 || length > 12) return false;
var start = 0; var start = 0;
if (length == 12) //"+71234567890" if (length == 12)
{ {
if (line[0] != '+' || line[1] != '7') return false; if (line[0] != '+' || line[1] != '7') return false;
start = 2; start = 2;
} }
if (length == 11) //"71234567890" и "81234567890" if (length == 11)
{ {
if (line[0] != '7') return false; if (line[0] != '7') return false;
start = 1; start = 1;
} }
/*
else if (length == 10) //"1234567890"
{
start = 0;
}
*/
ulong number = 7; ulong number = 7;
for (var i = start; i < length; i++) for (var i = start; i < length; i++)
{ {
var c = line[i]; var c = line[i];
@ -93,7 +71,6 @@
return false; return false;
} }
} }
msisdn = number; msisdn = number;
return true; return true;
} }

@ -8,11 +8,11 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.FASTER.Core" Version="2.5.18" /> <PackageReference Include="Microsoft.FASTER.Core" Version="2.6.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ZeroLevel\ZeroLevel.csproj" /> <ProjectReference Include="..\..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -0,0 +1,41 @@
using Grpc.Net.Client;
using static Qdrant.Collections;
namespace Qdrant.Test
{
// QDRANT VERSION 1.15.1
internal class Program
{
const string COLLECTION_NAME = "my_test_collection";
static void Main(string[] args)
{
var address = @"http://localhost:6334";
var channel = GrpcChannel.ForAddress(address);
var collections = new CollectionsClient(channel);
var response = collections.Create(new CreateCollection
{
CollectionName = COLLECTION_NAME,
VectorsConfig = new VectorsConfig
{
Params = new VectorParams
{
Distance = Distance.Dot,
Size = 32,
HnswConfig = new HnswConfigDiff
{
OnDisk = false
}
}
}
});
Console.WriteLine($"CREATED: {response.Result}");
var d_response = collections.Delete(new DeleteCollection
{
CollectionName = COLLECTION_NAME
});
Console.WriteLine($"DELETED: {d_response.Result}");
}
}
}

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.24.3" />
<PackageReference Include="Grpc.Net.Client" Version="2.57.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="ZeroLevel.Qdrant.GrpcClient">
<HintPath>..\..\ZeroLevel.Qdrant.GrpcClient\bin\Release\net6.0\ZeroLevel.Qdrant.GrpcClient.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

@ -8,7 +8,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="ZeroLevel" Version="3.3.9.9" /> <PackageReference Include="ZeroLevel" Version="3.4.0.8" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\ZeroLevel\ZeroLevel.csproj" /> <ProjectReference Include="..\..\..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\ZeroLevel\ZeroLevel.csproj" /> <ProjectReference Include="..\..\..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\ZeroLevel\ZeroLevel.csproj" /> <ProjectReference Include="..\..\..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\ZeroLevel\ZeroLevel.csproj" /> <ProjectReference Include="..\..\..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save

Powered by TurnKey Linux.