### Build and Run Application Source: https://github.com/qdrant/qdrant-dotnet/blob/main/example/README.md Execute this script to build and run the Qdrant .NET client example application. ```bash bash -x build-and-run.sh ``` -------------------------------- ### Start Qdrant with Docker Source: https://github.com/qdrant/qdrant-dotnet/blob/main/example/README.md Use this command to start a Qdrant instance locally using Docker. Ensure ports 6334 and 6333 are available. ```bash docker run --rm -it -p 6334:6334 -p 6333:6333 qdrant/qdrant ``` -------------------------------- ### Install Qdrant .NET SDK Source: https://github.com/qdrant/qdrant-dotnet/blob/main/README.md Add the Qdrant.Client package to your .NET project using the dotnet CLI. ```sh dotnet add package Qdrant.Client ``` -------------------------------- ### Instantiate QdrantClient Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Demonstrates various ways to instantiate the QdrantClient, from simple host/port configurations to more complex setups involving HTTPS, API keys, custom timeouts, logging, and TLS with certificate thumbprint validation. Includes a basic health check. ```csharp using Qdrant.Client; using Qdrant.Client.Grpc; using Microsoft.Extensions.Logging; // 1. Simplest: host + port (plain HTTP) var client = new QdrantClient("localhost", port: 6334); // 2. With HTTPS and API key var client = new QdrantClient( host: "xyz.cloud.qdrant.io", port: 6334, https: true, apiKey: "your-api-key"); // 3. From Uri with optional logger using var loggerFactory = LoggerFactory.Create(b => b.AddConsole()); var client = new QdrantClient( new Uri("http://localhost:6334"), apiKey: null, grpcTimeout: TimeSpan.FromSeconds(30), loggerFactory: loggerFactory); // 4. Via QdrantChannel for custom TLS (self-signed cert) var channel = QdrantChannel.ForAddress("https://localhost:6334", new ClientConfiguration { ApiKey = "secret", CertificateThumbprint = "AA:BB:CC:..", Headers = new Dictionary { ["x-tenant"] = "acme" } }); var grpcClient = new QdrantGrpcClient(channel); var client = new QdrantClient(grpcClient); // Health check var health = await client.HealthAsync(); Console.WriteLine(health.Title); // "qdrant - 1.17.0" client.Dispose(); ``` -------------------------------- ### Content-Based Recommendations with RecommendAsync Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Generate recommendations using `RecommendAsync`. This method finds points similar to positive examples and dissimilar to negative examples. Examples can be provided as point IDs or raw vectors. Filtering and recommendation strategies are supported. ```csharp // Recommend based on liked/disliked point IDs IReadOnlyList recs = await client.RecommendAsync( collectionName: "my-docs", positive: new ulong[] { 1UL, 5UL, 12UL }, negative: new ulong[] { 3UL }, limit: 10, filter: Conditions.MatchKeyword("type", "article"), strategy: RecommendStrategy.AverageVector); // Recommend using raw vector examples IReadOnlyList recs2 = await client.RecommendAsync( collectionName: "my-docs", positive: Array.Empty(), positiveVectors: new Vector[] { new float[] { 0.9f, 0.1f, 0.2f, 0.8f } }, negativeVectors: new Vector[] { new float[] { 0.1f, 0.9f, 0.8f, 0.2f } }, limit: 5); ``` ```csharp // Grouped recommendations IReadOnlyList groups = await client.RecommendGroupsAsync( "my-docs", groupBy: "category", positive: new ulong[] { 7UL }, limit: 4, groupSize: 2); ``` -------------------------------- ### Control Distributed Cluster Setup Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Manage distributed cluster settings for collections, including getting cluster info, moving shard replicas, and managing custom sharding keys. Use `GetCollectionClusterSetupInfoAsync`, `UpdateCollectionClusterSetupAsync`, `CreateShardKeyAsync`, and `DeleteShardKeyAsync`. ```csharp // Get cluster info for a collection CollectionClusterInfoResponse clusterInfo = await client.GetCollectionClusterSetupInfoAsync("my-docs"); Console.WriteLine($"Shards: {clusterInfo.LocalShards.Count}"); // Move a shard replica to another peer await client.UpdateCollectionClusterSetupAsync(new UpdateCollectionClusterSetupRequest { CollectionName = "my-docs", MoveShard = new MoveShard { ShardId = 0, ToShard = 1 } }); // Custom sharding key management await client.CreateShardKeyAsync("my-docs", new CreateShardKey { ShardKey = new ShardKey { Keyword = "region-us" } }); await client.DeleteShardKeyAsync("my-docs", new DeleteShardKey { ShardKey = new ShardKey { Keyword = "region-us" } }); ``` -------------------------------- ### RecommendAsync Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Provides content-based recommendations by finding points similar to positive examples and dissimilar to negative examples. ```APIDOC ## RecommendAsync — Content-based recommendation Finds points similar to positive examples and dissimilar from negative examples. Examples can be point IDs or raw vectors. ```csharp // Recommend based on liked/disliked point IDs IReadOnlyList recs = await client.RecommendAsync( collectionName: "my-docs", positive: new ulong[] { 1UL, 5UL, 12UL }, negative: new ulong[] { 3UL }, limit: 10, filter: Conditions.MatchKeyword("type", "article"), strategy: RecommendStrategy.AverageVector); // Recommend using raw vector examples IReadOnlyList recs2 = await client.RecommendAsync( collectionName: "my-docs", positive: Array.Empty(), positiveVectors: new Vector[] { new float[] { 0.9f, 0.1f, 0.2f, 0.8f } }, negativeVectors: new Vector[] { new float[] { 0.1f, 0.9f, 0.8f, 0.2f } }, limit: 5); // Grouped recommendations IReadOnlyList groups = await client.RecommendGroupsAsync( "my-docs", groupBy: "category", positive: new ulong[] { 7UL }, limit: 4, groupSize: 2); ``` ``` -------------------------------- ### Context-Aware Discovery with DiscoverAsync Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Perform context-aware discovery using `DiscoverAsync`. This method finds points closer to positive context examples than negative ones, optionally anchored to a target vector. It supports both target vector and context pairs, or context-only searches. ```csharp // Discovery with target + context pairs IReadOnlyList discovered = await client.DiscoverAsync( collectionName: "my-docs", target: new TargetVector { Single = new VectorExample { Id = 42UL } }, context: new List { new() { Positive = new VectorExample { Id = 1UL }, Negative = new VectorExample { Id = 2UL } } }, limit: 10); // Context-only search (no target — score is loss-based, max 0.0) IReadOnlyList contextOnly = await client.DiscoverAsync( collectionName: "my-docs", context: new List { new() { Positive = new VectorExample { Id = 5UL }, Negative = new VectorExample { Id = 9UL } } }, limit: 5); ``` -------------------------------- ### DiscoverAsync Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Performs context-aware discovery, finding points that are closer to positive context examples than negative ones, with optional anchoring to a target vector. ```APIDOC ## DiscoverAsync — Context-aware discovery Finds points that are closer to positive context examples than to negative ones, optionally anchored to a target vector. ```csharp // Discovery with target + context pairs IReadOnlyList discovered = await client.DiscoverAsync( collectionName: "my-docs", target: new TargetVector { Single = new VectorExample { Id = 42UL } }, context: new List { new() { Positive = new VectorExample { Id = 1UL }, Negative = new VectorExample { Id = 2UL } } }, limit: 10); // Context-only search (no target — score is loss-based, max 0.0) IReadOnlyList contextOnly = await client.DiscoverAsync( collectionName: "my-docs", context: new List { new() { Positive = new VectorExample { Id = 5UL }, Negative = new VectorExample { Id = 9UL } } }, limit: 5); ``` ``` -------------------------------- ### Upsert Points with Qdrant .NET Client Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Insert or update points in a collection. Supports numeric and GUID IDs, dense, sparse, and multi-vector formats. Payload values are implicitly converted from C# primitives. ```csharp using Qdrant.Client.Grpc; // Upsert with numeric IDs and dense vectors var result = await client.UpsertAsync("my-docs", new List { new() { Id = 1UL, Vectors = new float[] { 0.1f, 0.2f, 0.3f, 0.4f }, Payload = { ["title"] = "First document", ["year"] = 2024L, ["active"] = true, ["score"] = 9.5 } }, new() { Id = Guid.NewGuid(), // GUID IDs also supported Vectors = new float[] { 0.5f, 0.6f, 0.7f, 0.8f }, Payload = { ["title"] = "Second document" } } }); // result.Status == UpdateStatus.Completed ``` ```csharp // Named multi-vector point (hybrid) await client.UpsertAsync("hybrid-search", new List { new() { Id = 42UL, Vectors = new NamedVectors { Vectors = { ["dense"] = new float[] { 0.1f, 0.2f, 0.3f }, ["sparse"] = (new float[] { 0.9f, 0.1f }, new uint[] { 5, 100 }) } } } }); ``` -------------------------------- ### Client Instantiation Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Demonstrates various ways to instantiate the QdrantClient, including basic host/port, HTTPS with API key, from a Uri, and using QdrantChannel for custom TLS configurations. Also shows a basic health check. ```APIDOC ## Client Instantiation `QdrantClient` can be constructed from a host/port pair, a `Uri`, or an existing `QdrantGrpcClient`. All public operations are async and accept an optional `CancellationToken`. ```csharp using Qdrant.Client; using Qdrant.Client.Grpc; using Microsoft.Extensions.Logging; // 1. Simplest: host + port (plain HTTP) var client = new QdrantClient("localhost", port: 6334); // 2. With HTTPS and API key var client = new QdrantClient( host: "xyz.cloud.qdrant.io", port: 6334, https: true, apiKey: "your-api-key"); // 3. From Uri with optional logger using var loggerFactory = LoggerFactory.Create(b => b.AddConsole()); var client = new QdrantClient( new Uri("http://localhost:6334"), apiKey: null, grpcTimeout: TimeSpan.FromSeconds(30), loggerFactory: loggerFactory); // 4. Via QdrantChannel for custom TLS (self-signed cert) var channel = QdrantChannel.ForAddress("https://localhost:6334", new ClientConfiguration { ApiKey = "secret", CertificateThumbprint = "AA:BB:CC:..", Headers = new Dictionary { ["x-tenant"] = "acme" } }); var grpcClient = new QdrantGrpcClient(channel); var client = new QdrantClient(grpcClient); // Health check var health = await client.HealthAsync(); Console.WriteLine(health.Title); // "qdrant - 1.17.0" client.Dispose(); ``` ``` -------------------------------- ### Create Basic Qdrant Client Source: https://github.com/qdrant/qdrant-dotnet/blob/main/README.md Instantiate a Qdrant client to connect to a local Qdrant instance running on the default port. ```csharp var client = new QdrantClient("localhost"); ``` -------------------------------- ### Create Qdrant Collection Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Shows how to create a new Qdrant collection with different vector configurations, including single dense vectors and named vectors for hybrid search. Also demonstrates checking collection existence, retrieving collection info, listing collections, and deleting a collection. ```csharp using Qdrant.Client.Grpc; // Single dense vector (Cosine, 1536 dimensions) await client.CreateCollectionAsync( collectionName: "my-docs", vectorsConfig: new VectorParams { Size = 1536, Distance = Distance.Cosine }); // Named vectors (e.g. dense + sparse hybrid) await client.CreateCollectionAsync( collectionName: "hybrid-search", vectorsConfig: new VectorParamsMap { Map = { ["dense"] = new VectorParams { Size = 768, Distance = Distance.Cosine }, } }, sparseVectorsConfig: new SparseVectorConfig { Map = { ["sparse"] = new SparseVectorParams() } }, onDiskPayload: true, hnswConfig: new HnswConfigDiff { M = 16, EfConstruct = 100 }); // Check if collection exists bool exists = await client.CollectionExistsAsync("my-docs"); // true // Get collection info CollectionInfo info = await client.GetCollectionInfoAsync("my-docs"); Console.WriteLine($"Points: {info.PointsCount}, Status: {info.Status}"); // List all collections IReadOnlyList names = await client.ListCollectionsAsync(); // Delete a collection await client.DeleteCollectionAsync("my-docs", timeout: TimeSpan.FromSeconds(10)); ``` -------------------------------- ### Generate Client Stubs (Windows) Source: https://github.com/qdrant/qdrant-dotnet/blob/main/CONTRIBUTING.md Execute this command on Windows to download dependencies, format code, and generate the latest client stubs, overwriting existing ones. ```bash .\build.bat build --overwrite-protos ``` -------------------------------- ### Create Configured Qdrant Client with TLS and API Key Source: https://github.com/qdrant/qdrant-dotnet/blob/main/README.md Configure a Qdrant client for secure communication using TLS, certificate thumbprint validation, and API key authentication. ```csharp var channel = QdrantChannel.ForAddress("https://localhost:6334", new ClientConfiguration { ApiKey = "", CertificateThumbprint = "" }); var grpcClient = new QdrantGrpcClient(channel); var client = new QdrantClient(grpcClient); ``` -------------------------------- ### Filtering with Conditions and Filter Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Demonstrates how to build complex filter expressions using a fluent DSL for Qdrant search queries. ```APIDOC ## Filtering with `Conditions` and `Filter` The `Conditions` static class and `Filter` operator overloads provide a fluent DSL for building Qdrant filter expressions. ```csharp using Qdrant.Client.Grpc; using static Qdrant.Client.Grpc.Conditions; // Keyword match Filter f1 = MatchKeyword("status", "published"); // Boolean match Filter f2 = Match("active", true); // Numeric match / range Filter f3 = Match("year", 2024L); Filter f4 = Range("score", new Range { Gte = 7.0, Lte = 10.0 }); // DateTime range Filter f5 = DatetimeRange("created_at", gte: new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc), lt: new DateTime(2025, 1, 1, 0, 0, 0, DateTimeKind.Utc)); // Multi-value match (any of) Filter f6 = Match("tags", new[] { "ml", "nlp", "llm" }); // Except (none of) Filter f7 = MatchExcept("category", new[] { "spam", "ads" }); // Null / empty checks Filter f8 = IsNull("archived_at"); Filter f9 = IsEmpty("description"); // Has ID Filter f10 = HasId(new ulong[] { 1UL, 5UL, 10UL }); // Geo filters Filter f11 = GeoRadius("location", latitude: 48.8566, longitude: 2.3522, radius: 5000f); Filter f12 = GeoBoundingBox("location", 51.5, -0.2, 51.4, 0.0); // Nested field condition Filter f13 = Nested("metadata", MatchKeyword("source", "web")); // Compose with & (AND) and | (OR) Filter combined = (f1 & f3 & f4) | f6; // Use in search var results = await client.SearchAsync("my-docs", vector: new float[] { 0.1f, 0.2f, 0.3f, 0.4f }, filter: combined, limit: 10); ``` ``` -------------------------------- ### Format Code with dotnet format Source: https://github.com/qdrant/qdrant-dotnet/blob/main/CONTRIBUTING.md Run this command from the project root to format the code according to project rules before submitting a PR. ```bash ./build.sh format ``` -------------------------------- ### Generate Client Stubs (OSX/Linux) Source: https://github.com/qdrant/qdrant-dotnet/blob/main/CONTRIBUTING.md Execute this command on OSX/Linux to download dependencies, format code, and generate the latest client stubs, overwriting existing ones. ```bash ./build.sh build --overwrite-protos ``` -------------------------------- ### Create Qdrant Client for .NET Framework with TLS and API Key Source: https://github.com/qdrant/qdrant-dotnet/blob/main/README.md Configure a Qdrant client for .NET Framework to use TLS with certificate validation and API key authentication via WinHttpHandler. ```csharp var channel = GrpcChannel.ForAddress($"https://localhost:6334", new GrpcChannelOptions { HttpHandler = new WinHttpHandler { ServerCertificateValidationCallback = CertificateValidation.Thumbprint("") } }); var callInvoker = channel.Intercept(metadata => { metadata.Add("api-key", ""); return metadata; }); var grpcClient = new QdrantGrpcClient(callInvoker); var client = new QdrantClient(grpcClient); ``` -------------------------------- ### Tag a New Release Source: https://github.com/qdrant/qdrant-dotnet/blob/main/CONTRIBUTING.md Use these Git commands to create a new version tag and push it to the repository, which triggers the CI for package uploading. ```bash git tag 1.6.0 git push --tags ``` -------------------------------- ### Create a Qdrant Collection Source: https://github.com/qdrant/qdrant-dotnet/blob/main/README.md Create a new collection in Qdrant with a specified name and vector parameters, including size and distance metric. ```csharp await client.CreateCollectionAsync("my_collection", new VectorParams { Size = 100, Distance = Distance.Cosine }); ``` -------------------------------- ### Run Tests (OSX/Linux) Source: https://github.com/qdrant/qdrant-dotnet/blob/main/CONTRIBUTING.md Ensure Docker is running and execute this command on OSX/Linux to run the project's tests. ```bash ./build.sh test ``` -------------------------------- ### Run Tests (Windows) Source: https://github.com/qdrant/qdrant-dotnet/blob/main/CONTRIBUTING.md Ensure Docker is running and execute this command on Windows to run the project's tests. ```bash .\build.bat test ``` -------------------------------- ### Create and Delete Payload Indexes Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Demonstrates how to create keyword, float, and text indexes on payload fields, as well as how to delete them. ```APIDOC ## CreatePayloadIndexAsync / DeletePayloadIndexAsync — Index payload fields Creates or removes a payload field index to speed up filtered searches. ### Description Use `CreatePayloadIndexAsync` to add an index for a specific payload field to optimize filtered searches. Use `DeletePayloadIndexAsync` to remove an existing index. ### Method `CreatePayloadIndexAsync` and `DeletePayloadIndexAsync` ### Parameters - `collectionName` (string) - The name of the collection. - `fieldName` (string) - The name of the payload field to index. - `schemaType` (PayloadSchemaType) - The type of schema for the index (e.g., Keyword, Float, Text). - `indexParams` (PayloadIndexParams, optional) - Additional parameters for text indexing, such as tokenizer and token length. ### Request Example ```csharp // Create a keyword index on the "tags" field await client.CreatePayloadIndexAsync("my-docs", fieldName: "tags", schemaType: PayloadSchemaType.Keyword); // Create a float index on the "score" field await client.CreatePayloadIndexAsync("my-docs", fieldName: "score", schemaType: PayloadSchemaType.Float); // Create full-text index with custom tokenizer await client.CreatePayloadIndexAsync("my-docs", fieldName: "title", schemaType: PayloadSchemaType.Text, indexParams: new PayloadIndexParams { TextIndexParams = new TextIndexParams { Tokenizer = TokenizerType.Word, MinTokenLen = 2, MaxTokenLen = 20 } }); // Delete the index await client.DeletePayloadIndexAsync("my-docs", "score"); ``` ``` -------------------------------- ### Implicit Conversions for Qdrant SDK Types Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Shows how PointId, Value, Vector, Query, and Filter types can be implicitly converted from primitive types, arrays, dictionaries, and other SDK-specific types. ```csharp using Qdrant.Client.Grpc; // PointId: ulong and Guid convert implicitly PointId numId = 42UL; PointId guidId = Guid.NewGuid(); // Value: primitives convert implicitly Value strVal = "hello"; Value intVal = 42L; Value boolVal = true; Value dblVal = 3.14; Value arrVal = new string[] { "a", "b", "c" }; Value nested = new Dictionary { ["x"] = 1L, ["y"] = "foo" }; // Vector: float arrays and sparse tuples convert implicitly Vector dense = new float[] { 0.1f, 0.2f, 0.3f }; Vector sparse = (new float[] { 0.9f, 0.1f }, new uint[] { 5, 100 }); Vector multi = new float[][] { new[] { 0.1f, 0.2f }, new[] { 0.3f, 0.4f } }; Vector docVec = new Document { Text = "embed this text" }; // Query: many types convert to Query Query nearestById = 42UL; Query nearestByGuid = Guid.NewGuid(); Query nearestByVec = new float[] { 0.1f, 0.2f, 0.3f }; Query recommend = new RecommendInput { Positive = { 1UL, 5UL }, Negative = { 3UL } }; Query fuse = Fusion.Rrf; // Filter: Condition converts to Filter implicitly Filter f = Conditions.MatchKeyword("status", "active"); // implicit Condition→Filter Filter combined = Conditions.Match("year", 2024L) & Conditions.Match("active", true); Filter either = Conditions.MatchKeyword("cat", "a") | Conditions.MatchKeyword("cat", "b"); ``` -------------------------------- ### Manage Aliases with Qdrant .NET Client Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Use these methods to create, update, rename, list, and delete aliases for collections. Alias operations are atomic, providing stable names over collection deployments. ```csharp // Create alias pointing to "my-docs-v2" await client.CreateAliasAsync("my-docs", "my-docs-v2"); ``` ```csharp // Swap to new version atomically await client.UpdateAliasesAsync(new[] { new AliasOperations { DeleteAlias = new DeleteAlias { AliasName = "my-docs" } }, new AliasOperations { CreateAlias = new CreateAlias { AliasName = "my-docs", CollectionName = "my-docs-v3" } } }); ``` ```csharp // Rename await client.RenameAliasAsync("my-docs", "production-docs"); ``` ```csharp // List aliases for a collection IReadOnlyList aliases = await client.ListCollectionAliasesAsync("my-docs-v3"); ``` ```csharp // List all aliases globally IReadOnlyList all = await client.ListAliasesAsync(); ``` ```csharp // Delete alias await client.DeleteAliasAsync("production-docs"); ``` -------------------------------- ### Universal Query API with `QueryAsync` Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Utilize `QueryAsync` for a unified query endpoint supporting various search strategies including nearest-neighbor, recommend, discover, re-ranking, hybrid fusion (RRF/DBSFusion), multi-stage prefetch, MMR, formula scoring, and ordering. This API supersedes `SearchAsync`, `RecommendAsync`, and `DiscoverAsync` for complex queries. ```csharp using Qdrant.Client.Grpc; // 1. Simple nearest-neighbor query (implicit float[] → Query) IReadOnlyList r1 = await client.QueryAsync( "my-docs", query: new float[] { 0.1f, 0.2f, 0.9f, 0.7f }, limit: 5); // 2. Query by point ID (look up and use that point's vector) IReadOnlyList r2 = await client.QueryAsync( "my-docs", query: 42UL, filter: Conditions.MatchKeyword("status", "published"), limit: 10); // 3. Hybrid search with RRF fusion via prefetch IReadOnlyList r3 = await client.QueryAsync( "hybrid-search", prefetch: new List { new() { Query = new float[] { 0.1f, 0.2f, 0.3f }, Using = "dense", Limit = 50 }, new() { Query = (new float[] { 0.9f, 0.1f }, new uint[] { 5, 100 }), Using = "sparse", Limit = 50 } }, query: Fusion.Rrf, // reciprocal rank fusion limit: 10); // 4. Multi-stage re-ranking with MMR IReadOnlyList r4 = await client.QueryAsync( "my-docs", prefetch: new List { new() { Query = new float[] { 0.1f, 0.2f, 0.9f, 0.7f }, Limit = 100 } }, query: (new VectorInput(new float[] { 0.1f, 0.2f, 0.9f, 0.7f }), new Mmr { Diversity = 0.5f }), limit: 10); // 5. Order points by payload field (no vector) IReadOnlyList r5 = await client.QueryAsync( "my-docs", query: (Query)"year", // explicit cast to create order-by Query limit: 20); ``` -------------------------------- ### Manage Collection Snapshots Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Create, list, and delete snapshots for a specific collection using `CreateSnapshotAsync`, `ListSnapshotsAsync`, and `DeleteSnapshotAsync`. Also supports creating, listing, and deleting full storage snapshots. ```csharp // Create a snapshot for a collection SnapshotDescription snap = await client.CreateSnapshotAsync("my-docs"); Console.WriteLine($"Snapshot: {snap.Name}, size={snap.Size}"); // List snapshots IReadOnlyList snaps = await client.ListSnapshotsAsync("my-docs"); // Delete a snapshot await client.DeleteSnapshotAsync("my-docs", snap.Name); // Full storage snapshot SnapshotDescription full = await client.CreateFullSnapshotAsync(); IReadOnlyList fullList = await client.ListFullSnapshotsAsync(); await client.DeleteFullSnapshotAsync(full.Name); ``` -------------------------------- ### Recreate Qdrant Collection Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Atomically drops and recreates a collection with specified vector parameters. This is particularly useful for development and testing scenarios. ```csharp await client.RecreateCollectionAsync( collectionName: "test-collection", vectorsConfig: new VectorParams { Size = 4, Distance = Distance.Dot }); ``` -------------------------------- ### CreateCollectionAsync Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Creates a new vector collection with specified parameters, including vector configuration, HNSW index tuning, quantization, sharding, and replication. ```APIDOC ## CreateCollectionAsync — Create a new vector collection Creates a named collection with vector configuration (dimension, distance metric). Supports single anonymous vectors or named multi-vector configurations, HNSW index tuning, quantization, sharding, and replication. ```csharp using Qdrant.Client.Grpc; // Single dense vector (Cosine, 1536 dimensions) await client.CreateCollectionAsync( collectionName: "my-docs", vectorsConfig: new VectorParams { Size = 1536, Distance = Distance.Cosine }); // Named vectors (e.g. dense + sparse hybrid) await client.CreateCollectionAsync( collectionName: "hybrid-search", vectorsConfig: new VectorParamsMap { Map = { ["dense"] = new VectorParams { Size = 768, Distance = Distance.Cosine }, } }, sparseVectorsConfig: new SparseVectorConfig { Map = { ["sparse"] = new SparseVectorParams() } }, onDiskPayload: true, hnswConfig: new HnswConfigDiff { M = 16, EfConstruct = 100 }); // Check if collection exists bool exists = await client.CollectionExistsAsync("my-docs"); // true // Get collection info CollectionInfo info = await client.GetCollectionInfoAsync("my-docs"); Console.WriteLine($"Points: {info.PointsCount}, Status: {info.Status}"); // List all collections IReadOnlyList names = await client.ListCollectionsAsync(); // Delete a collection await client.DeleteCollectionAsync("my-docs", timeout: TimeSpan.FromSeconds(10)); ``` ``` -------------------------------- ### Search for Similar Vectors Source: https://github.com/qdrant/qdrant-dotnet/blob/main/README.md Perform a similarity search in a Qdrant collection using a query vector and retrieve a specified number of the closest points. ```csharp 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); ``` -------------------------------- ### Build Qdrant Filters with Fluent DSL Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Use the `Conditions` static class and `Filter` operator overloads to construct Qdrant filter expressions fluently. Supports keyword, boolean, numeric, range, datetime, multi-value, except, null/empty checks, ID matching, geo filters, and nested conditions. Filters can be combined using AND (&) and OR (|) operators. ```csharp using Qdrant.Client.Grpc; using static Qdrant.Client.Grpc.Conditions; // Keyword match Filter f1 = MatchKeyword("status", "published"); // Boolean match Filter f2 = Match("active", true); // Numeric match / range Filter f3 = Match("year", 2024L); Filter f4 = Range("score", new Range { Gte = 7.0, Lte = 10.0 }); // DateTime range Filter f5 = DatetimeRange("created_at", gte: new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc), lt: new DateTime(2025, 1, 1, 0, 0, 0, DateTimeKind.Utc)); // Multi-value match (any of) Filter f6 = Match("tags", new[] { "ml", "nlp", "llm" }); // Except (none of) Filter f7 = MatchExcept("category", new[] { "spam", "ads" }); // Null / empty checks Filter f8 = IsNull("archived_at"); Filter f9 = IsEmpty("description"); // Has ID Filter f10 = HasId(new ulong[] { 1UL, 5UL, 10UL }); // Geo filters Filter f11 = GeoRadius("location", latitude: 48.8566, longitude: 2.3522, radius: 5000f); Filter f12 = GeoBoundingBox("location", 51.5, -0.2, 51.4, 0.0); // Nested field condition Filter f13 = Nested("metadata", MatchKeyword("source", "web")); // Compose with & (AND) and | (OR) Filter combined = (f1 & f3 & f4) | f6; // Use in search var results = await client.SearchAsync("my-docs", vector: new float[] { 0.1f, 0.2f, 0.3f, 0.4f }, filter: combined, limit: 10); ``` -------------------------------- ### Batch Universal Queries with QueryBatchAsync Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Execute multiple universal queries efficiently using `QueryBatchAsync`. This method accepts a list of `QueryPoints` objects, each defining its own collection, query vector, and limits. Supports both vector queries and ID-based queries. ```csharp IReadOnlyList results = await client.QueryBatchAsync( "my-docs", queries: new List { new() { CollectionName = "my-docs", Query = new float[] { 0.1f, 0.2f, 0.9f, 0.7f }, Limit = 5 }, new() { CollectionName = "my-docs", Query = 42UL, Limit = 5 } }); ``` -------------------------------- ### Retrieve Points by ID with Qdrant .NET Client Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Fetch points by their IDs, optionally including payload and vectors. Supports retrieving single or multiple points and selecting specific payload fields. ```csharp // Retrieve a single point IReadOnlyList points = await client.RetrieveAsync( "my-docs", id: 1UL, withPayload: true, withVectors: true); Console.WriteLine(points[0].Payload["title"]); // "First document" ``` ```csharp // Retrieve multiple points with specific payload fields IReadOnlyList batch = await client.RetrieveAsync( "my-docs", ids: new PointId[] { 1UL, 2UL, 3UL }, payloadSelector: new WithPayloadSelector { Include = new PayloadIncludeSelector { Fields = { "title", "year" } } }, vectorSelector: new WithVectorsSelector { Enable = false }); ``` -------------------------------- ### Search with Filtering Conditions Source: https://github.com/qdrant/qdrant-dotnet/blob/main/README.md Execute a similarity search in Qdrant, applying a filter to retrieve points that meet specific criteria, such as a range condition on a payload field. ```csharp // 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); ``` -------------------------------- ### GetCollectionClusterSetupInfoAsync / UpdateCollectionClusterSetupAsync / CreateShardKeyAsync / DeleteShardKeyAsync Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Provides control over distributed cluster operations, including shard management and custom sharding keys. ```APIDOC ## Cluster Management ### `GetCollectionClusterSetupInfoAsync` / `UpdateCollectionClusterSetupAsync` / `CreateShardKeyAsync` / `DeleteShardKeyAsync` — Distributed cluster control ```csharp // Get cluster info for a collection CollectionClusterInfoResponse clusterInfo = await client.GetCollectionClusterSetupInfoAsync("my-docs"); Console.WriteLine($"Shards: {clusterInfo.LocalShards.Count}"); // Move a shard replica to another peer await client.UpdateCollectionClusterSetupAsync(new UpdateCollectionClusterSetupRequest { CollectionName = "my-docs", MoveShard = new MoveShard { ShardId = 0, ToShard = 1 } }); // Custom sharding key management await client.CreateShardKeyAsync("my-docs", new CreateShardKey { ShardKey = new ShardKey { Keyword = "region-us" } }); await client.DeleteShardKeyAsync("my-docs", new DeleteShardKey { ShardKey = new ShardKey { Keyword = "region-us" } }); ``` ``` -------------------------------- ### QueryBatchAsync Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Executes multiple universal queries in a single batch request for efficiency. ```APIDOC ## QueryBatchAsync — Batch universal queries ```csharp IReadOnlyList results = await client.QueryBatchAsync( "my-docs", queries: new List { new() { CollectionName = "my-docs", Query = new float[] { 0.1f, 0.2f, 0.9f, 0.7f }, Limit = 5 }, new() { CollectionName = "my-docs", Query = 42UL, Limit = 5 } }); ``` ``` -------------------------------- ### QueryAsync — Universal query API Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt The unified query endpoint covering nearest-neighbor, recommend, discover, re-ranking, hybrid fusion (RRF/DBSFusion), multi-stage prefetch, MMR, formula scoring, and ordering. ```APIDOC ## QueryAsync — Universal query API The unified query endpoint covering nearest-neighbor, recommend, discover, re-ranking, hybrid fusion (RRF/DBSFusion), multi-stage prefetch, MMR, formula scoring, and ordering. Supersedes `SearchAsync`, `RecommendAsync`, and `DiscoverAsync` for complex scenarios. ### Description Provides a flexible and powerful API for various search and retrieval scenarios, including basic vector search, hybrid search, re-ranking, and ordering by payload fields without requiring a vector. ### Method `QueryAsync` ### Parameters - `collectionName` (string) - The name of the collection. - `query` - The query definition. Can be a vector (float[]), a point ID (ulong), a fusion strategy (Fusion), a re-ranking configuration (VectorInput with Mmr), or an order-by field (Query). - `prefetch` (List, optional) - A list of prefetch queries to be used for hybrid search or re-ranking. - `filter` (Filter, optional) - Conditions to filter the search results. - `limit` (int, optional) - The maximum number of results to return. - `scoreThreshold` (float, optional) - The minimum score for a result to be included. - `payloadSelector` (PayloadSelector, optional) - Specifies which payload fields to include in the response. - `timeout` (TimeSpan, optional) - The timeout for the query operation. - `using` (string, optional) - The name of the vector to use for the query. ### Request Example ```csharp using Qdrant.Client.Grpc; // 1. Simple nearest-neighbor query (implicit float[] → Query) IReadOnlyList r1 = await client.QueryAsync( "my-docs", query: new float[] { 0.1f, 0.2f, 0.9f, 0.7f }, limit: 5); // 2. Query by point ID (look up and use that point's vector) IReadOnlyList r2 = await client.QueryAsync( "my-docs", query: 42UL, filter: Conditions.MatchKeyword("status", "published"), limit: 10); // 3. Hybrid search with RRF fusion via prefetch IReadOnlyList r3 = await client.QueryAsync( "hybrid-search", prefetch: new List { new() { Query = new float[] { 0.1f, 0.2f, 0.3f }, Using = "dense", Limit = 50 }, new() { Query = (new float[] { 0.9f, 0.1f }, new uint[] { 5, 100 }), Using = "sparse", Limit = 50 } }, query: Fusion.Rrf, // reciprocal rank fusion limit: 10); // 4. Multi-stage re-ranking with MMR IReadOnlyList r4 = await client.QueryAsync( "my-docs", prefetch: new List { new() { Query = new float[] { 0.1f, 0.2f, 0.9f, 0.7f }, Limit = 100 } }, query: (new VectorInput(new float[] { 0.1f, 0.2f, 0.9f, 0.7f }), new Mmr { Diversity = 0.5f }), limit: 10); // 5. Order points by payload field (no vector) IReadOnlyList r5 = await client.QueryAsync( "my-docs", query: (Query)"year", // explicit cast to create order-by Query limit: 20); ``` ``` -------------------------------- ### Create and Delete Payload Indexes Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Use `CreatePayloadIndexAsync` to add indexes for payload fields to speed up filtered searches. Use `DeletePayloadIndexAsync` to remove them. Supports Keyword, Float, and Text schema types with customizable parameters for text indexing. ```csharp // Create a keyword index on the "tags" field await client.CreatePayloadIndexAsync("my-docs", fieldName: "tags", schemaType: PayloadSchemaType.Keyword); // Create a float index on the "score" field await client.CreatePayloadIndexAsync("my-docs", fieldName: "score", schemaType: PayloadSchemaType.Float); // Create full-text index with custom tokenizer await client.CreatePayloadIndexAsync("my-docs", fieldName: "title", schemaType: PayloadSchemaType.Text, indexParams: new PayloadIndexParams { TextIndexParams = new TextIndexParams { Tokenizer = TokenizerType.Word, MinTokenLen = 2, MaxTokenLen = 20 } }); // Delete the index await client.DeletePayloadIndexAsync("my-docs", "score"); ``` -------------------------------- ### Compute Distance Matrix with SearchMatrixPairsAsync / SearchMatrixOffsetsAsync Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Compute pairwise distance matrices for a sample of points using `SearchMatrixPairsAsync` (returns triples of IDs and scores) or `SearchMatrixOffsetsAsync` (returns CSR-style data). Useful for cluster analysis and data exploration. ```csharp // Pair format: list of (id_a, id_b, score) triples SearchMatrixPairs pairs = await client.SearchMatrixPairsAsync( "my-docs", sample: 50, // sample 50 points limit: 5, // 5 neighbours per point usingVector: null); // default vector // Offset format: CSR-style (ids, offsets, scores) SearchMatrixOffsets offsets = await client.SearchMatrixOffsetsAsync( "my-docs", sample: 50, limit: 5); ``` -------------------------------- ### Perform Batch Vector Search Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Use `SearchBatchAsync` to execute multiple search requests in a single RPC call, optimizing for reduced network overhead. ```csharp var searches = new List { new() { CollectionName = "my-docs", Vector = { 0.1f, 0.2f, 0.3f, 0.4f }, Limit = 3 }, new() { CollectionName = "my-docs", Vector = { 0.9f, 0.8f, 0.7f, 0.6f }, Limit = 3, Filter = Conditions.Match("active", true) } }; IReadOnlyList batchResults = await client.SearchBatchAsync("my-docs", searches); ``` -------------------------------- ### Manage Point Payloads with Qdrant .NET Client Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Perform operations on point payloads: merge, overwrite, delete specific keys, or clear all payload data. Use `SetPayloadAsync` for merging and `OverwritePayloadAsync` for replacing. ```csharp // Set (merge) payload for a single point await client.SetPayloadAsync("my-docs", payload: new Dictionary { ["tags"] = new string[] { "ml", "nlp" } }, id: 1UL); ``` ```csharp // Overwrite entire payload for points matching a filter await client.OverwritePayloadAsync("my-docs", payload: new Dictionary { ["status"] = "archived" }, filter: Conditions.Match("year", 2020L)); ``` ```csharp // Delete specific payload keys from a list of IDs await client.DeletePayloadAsync("my-docs", keys: new[] { "score", "active" }, ids: new ulong[] { 1UL, 2UL }); ``` ```csharp // Clear all payload for a point await client.ClearPayloadAsync("my-docs", id: 1UL); ``` -------------------------------- ### CreateSnapshotAsync / ListSnapshotsAsync / DeleteSnapshotAsync Source: https://context7.com/qdrant/qdrant-dotnet/llms.txt Manages collection snapshots, allowing for backup and restoration of collection data. ```APIDOC ## Snapshots ### `CreateSnapshotAsync` / `ListSnapshotsAsync` / `DeleteSnapshotAsync` — Collection snapshots ```csharp // Create a snapshot for a collection SnapshotDescription snap = await client.CreateSnapshotAsync("my-docs"); Console.WriteLine($"Snapshot: {snap.Name}, size={snap.Size}"); // List snapshots IReadOnlyList snaps = await client.ListSnapshotsAsync("my-docs"); // Delete a snapshot await client.DeleteSnapshotAsync("my-docs", snap.Name); // Full storage snapshot SnapshotDescription full = await client.CreateFullSnapshotAsync(); IReadOnlyList fullList = await client.ListFullSnapshotsAsync(); await client.DeleteFullSnapshotAsync(full.Name); ``` ```