qdrant/qdrant-dotnet
关于
Qdrant .Net SDK
开发工具实测星标增长
- 24小时
- 0
- 7天
- +1
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Qdrant .NET SDK
📥 Installation
dotnet add package Qdrant.Client
📖 Documentation
Usage examples are available throughout the Qdrant documentation.
🔌 Getting started
Creating a client
A client can be instantiated with
var client = new QdrantClient("localhost");
which creates a client that will connect to Qdrant on http://localhost:6334.
Internally, the high level client uses a low level gRPC client to interact with Qdrant. Additional constructor overloads provide more control over how the gRPC client is configured. The following example configures a client to use TLS, validating the certificate using its thumbprint, and also configures API key authentication:
var channel = QdrantChannel.ForAddress("https://localhost:6334", new ClientConfiguration
{
ApiKey = "<api key>",
CertificateThumbprint = "<certificate thumbprint>"
});
var grpcClient = new QdrantGrpcClient(channel);
var client = new QdrantClient(grpcClient);
[!IMPORTANT] IMPORTANT NOTICE for .NET Framework
.NET Framework has limited supported for gRPC over HTTP/2, but it can be enabled by
- Configuring qdrant to use TLS, and you must use HTTPS, so you will need to set up server certificate validation
- Referencing
System.Net.Http.WinHttpHandler6.0.1 or later, and configuringWinHttpHandleras the inner handler forGrpcChannelOptionsThe following example configures a client for .NET Framework to use TLS, validating the certificate using its thumbprint, and also configures API key authentication:
var channel = GrpcChannel.ForAddress($"https://localhost:6334", new GrpcChannelOptions { HttpHandler = new WinHttpHandler { ServerCertificateValidationCallback = CertificateValidation.Thumbprint("<certificate thumbprint>") } }); var callInvoker = channel.Intercept(metadata => { metadata.Add("api-key", "<api key>"); return metadata; }); var grpcClient = new QdrantGrpcClient(callInvoker); var client = new QdrantClient(grpcClient);
User-Agent
When a channel is created via QdrantChannel.ForAddress (which both
QdrantClient("localhost") and the ClientConfiguration overloads use), the
client adds a qdrant-dotnet/<version> token to the request User-Agent
alongside the gRPC library token, e.g.:
grpc-dotnet/2.71.0 (.NET 8.0.4; CLR 8.0.4; net8.0; linux; x64) qdrant-dotnet/1.20.0
This lets server-side tooling attribute traffic to the .NET client and its version. On .NET Framework, where the underlying channel handler must be configured manually, the token is not added automatically.
Working with collections
Once a client has been created, create a new collection
await client.CreateCollectionAsync("my_collection",
new VectorParams { Size = 100, Distance = Distance.Cosine });
Insert vectors into a collection
// generate some vectors
var random = new Random();
var points = Enumerable.Range(1, 100).Select(i => new PointStruct
{
Id = (ulong)i,
Vectors = Enumerable.Range(1, 100).Select(_ => (float)random.NextDouble()).ToArray(),
Payload =
{
["color"] = "red",
["rand_number"] = i % 10
}
}).ToList();
var updateResult = await client.UpsertAsync("my_collection", points);
Search for similar vectors
var queryVector = Enumerable.Range(1, 100).Select(_ => (float)random.NextDouble()).ToArray();
// return the 5 closest points
var points = await client.SearchAsync(
"my_collection",
queryVector,
limit: 5);
Search for similar vectors with filtering condition
// static import Conditions to easily build filtering
using static Qdrant.Client.Grpc.Conditions;
// return the 5 closest points where rand_number >= 3
var points = await _client.SearchAsync(
"my_collection",
queryVector,
filter: Range("rand_number", new Range { Gte = 3 }),
limit: 5);
探索相关项目
加载中…