Giter VIP home page Giter VIP logo

qdrant-dotnet's Introduction

.NET SDK for Qdrant vector database

NuGet Release Build

.NET SDK for Qdrant vector database.

Getting started

Installing

dotnet add package Qdrant.Client

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.WinHttpHandler 6.0.1 or later, and configuring WinHttpHandler as the inner handler for GrpcChannelOptions

The 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);

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);

qdrant-dotnet's People

Contributors

russcam avatar ivanpleshkov avatar anush008 avatar roji avatar ffuugoo avatar generall avatar azayarni avatar lordhansolo avatar timvisee avatar vaishalid2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.