From d4f07f7e50a7c14323c280229c74692468410736 Mon Sep 17 00:00:00 2001 From: Anush Date: Fri, 23 Aug 2024 22:44:32 +0530 Subject: [PATCH] docs: Query API snippets with C# (#1102) --- .../content/documentation/concepts/explore.md | 116 ++++++++++-------- .../content/documentation/concepts/search.md | 115 ++++++++--------- .../content/documentation/concepts/vectors.md | 9 +- .../guides/distributed_deployment.md | 4 +- .../guides/multiple-partitions.md | 4 +- .../content/documentation/guides/optimize.md | 8 +- .../documentation/guides/quantization.md | 58 ++++----- .../content/documentation/quickstart.md | 21 ++-- 8 files changed, 174 insertions(+), 161 deletions(-) diff --git a/qdrant-landing/content/documentation/concepts/explore.md b/qdrant-landing/content/documentation/concepts/explore.md index 868f0c10e..1d86de76d 100644 --- a/qdrant-landing/content/documentation/concepts/explore.md +++ b/qdrant-landing/content/documentation/concepts/explore.md @@ -145,10 +145,12 @@ using static Qdrant.Client.Grpc.Conditions; var client = new QdrantClient("localhost", 6334); -await client.RecommendAsync( - "{collection_name}", - positive: new ulong[] { 100, 231 }, - negative: new ulong[] { 718 }, +await client.QueryAsync( + collectionName: "{collection_name}", + query: new RecommendInput { + Positive = { 100, 231 }, + Negative = { 718 } + }, filter: MatchKeyword("city", "London"), limit: 3 ); @@ -292,15 +294,18 @@ client.queryAsync(QueryPoints.newBuilder() ```csharp using Qdrant.Client; +using Qdrant.Client.Grpc; var client = new QdrantClient("localhost", 6334); -await client.RecommendAsync( - collectionName: "{collection_name}", - positive: new ulong[] { 100, 231 }, - negative: new ulong[] { 718 }, - usingVector: "image", - limit: 10 +await client.QueryAsync( + collectionName: "{collection_name}", + query: new RecommendInput { + Positive = { 100, 231 }, + Negative = { 718 } + }, + usingVector: "image", + limit: 10 ); ``` @@ -411,13 +416,15 @@ using Qdrant.Client.Grpc; var client = new QdrantClient("localhost", 6334); -await client.RecommendAsync( - collectionName: "{collection_name}", - positive: new ulong[] { 100, 231 }, - negative: new ulong[] { 718 }, +await client.QueryAsync( + collectionName: "{collection_name}", + query: new RecommendInput { + Positive = { 100, 231 }, + Negative = { 718 } + }, usingVector: "image", limit: 10, - lookupFrom: new LookupLocation + lookupFrom: new LookupLocation { CollectionName = "{external_collection_name}", VectorName = "{external_vector_name}", @@ -627,23 +634,27 @@ var client = new QdrantClient("localhost", 6334); var filter = MatchKeyword("city", "london"); -await client.RecommendBatchAsync( +await client.QueryBatchAsync( collectionName: "{collection_name}", - recommendSearches: + queries: [ - new() + new QueryPoints() { CollectionName = "{collection_name}", - Positive = { new PointId[] { 100, 231 } }, - Negative = { new PointId[] { 718 } }, + Query = new RecommendInput { + Positive = { 100, 231 }, + Negative = { 718 }, + }, Limit = 3, Filter = filter, }, - new() + new QueryPoints() { CollectionName = "{collection_name}", - Positive = { new PointId[] { 200, 67 } }, - Negative = { new PointId[] { 300 } }, + Query = new RecommendInput { + Positive = { 200, 67 }, + Negative = { 300 }, + }, Limit = 3, Filter = filter, } @@ -847,25 +858,23 @@ using Qdrant.Client.Grpc; var client = new QdrantClient("localhost", 6334); -await client.DiscoverAsync( +await client.QueryAsync( collectionName: "{collection_name}", - target: new TargetVector - { - Single = new VectorExample { Vector = new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, } - }, - context: - [ - new() - { - Positive = new VectorExample { Id = 100 }, - Negative = new VectorExample { Id = 718 } - }, - new() - { - Positive = new VectorExample { Id = 200 }, - Negative = new VectorExample { Id = 300 } - } - ], + query: new DiscoverInput { + Target = new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + Context = new ContextInput { + Pairs = { + new ContextInputPair { + Positive = 100, + Negative = 718 + }, + new ContextInputPair { + Positive = 200, + Negative = 300 + }, + } + }, + }, limit: 10 ); ``` @@ -1023,21 +1032,20 @@ using Qdrant.Client.Grpc; var client = new QdrantClient("localhost", 6334); -await client.DiscoverAsync( +await client.QueryAsync( collectionName: "{collection_name}", - context: - [ - new() - { - Positive = new VectorExample { Id = 100 }, - Negative = new VectorExample { Id = 718 } - }, - new() - { - Positive = new VectorExample { Id = 200 }, - Negative = new VectorExample { Id = 300 } + query: new ContextInput { + Pairs = { + new ContextInputPair { + Positive = 100, + Negative = 718 + }, + new ContextInputPair { + Positive = 200, + Negative = 300 + }, } - ], + }, limit: 10 ); ``` diff --git a/qdrant-landing/content/documentation/concepts/search.md b/qdrant-landing/content/documentation/concepts/search.md index 46b0f6684..89003f590 100644 --- a/qdrant-landing/content/documentation/concepts/search.md +++ b/qdrant-landing/content/documentation/concepts/search.md @@ -323,12 +323,12 @@ using static Qdrant.Client.Grpc.Conditions; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( - collectionName: "{collection_name}", - vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, - filter: MatchKeyword("city", "London"), - searchParams: new SearchParams { Exact = false, HnswEf = 128 }, - limit: 3 +await client.QueryAsync( + collectionName: "{collection_name}", + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + filter: MatchKeyword("city", "London"), + searchParams: new SearchParams { Exact = false, HnswEf = 128 }, + limit: 3 ); ``` @@ -443,10 +443,10 @@ using Qdrant.Client; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( +await client.QueryAsync( collectionName: "{collection_name}", - vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, - vectorName: "image", + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + usingVector: "image", limit: 3 ); ``` @@ -558,12 +558,11 @@ using Qdrant.Client; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( - collectionName: "{collection_name}", - vector: new float[] { 2.0f, 1.0f }, - vectorName: "text", - limit: 3, - sparseIndices: new uint[] { 1, 7 } +await client.QueryAsync( + collectionName: "{collection_name}", + query: new (float, uint)[] { (2.0f, 1), (1.0f, 2) }, + usingVector: "text", + limit: 3 ); ``` @@ -654,9 +653,9 @@ using Qdrant.Client; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( +await client.QueryAsync( collectionName: "{collection_name}", - vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, payloadSelector: true, vectorsSelector: true, limit: 3 @@ -747,17 +746,17 @@ using Qdrant.Client.Grpc; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( - collectionName: "{collection_name}", - vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, - payloadSelector: new WithPayloadSelector - { - Include = new PayloadIncludeSelector - { - Fields = { new string[] { "city", "village", "town" } } - } - }, - limit: 3 +await client.QueryAsync( + collectionName: "{collection_name}", + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + payloadSelector: new WithPayloadSelector + { + Include = new PayloadIncludeSelector + { + Fields = { new string[] { "city", "village", "town" } } + } + }, + limit: 3 ); ``` @@ -849,9 +848,9 @@ using Qdrant.Client.Grpc; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( +await client.QueryAsync( collectionName: "{collection_name}", - vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, payloadSelector: new WithPayloadSelector { Exclude = new PayloadExcludeSelector { Fields = { new string[] { "city" } } } @@ -1037,23 +1036,25 @@ var client = new QdrantClient("localhost", 6334); var filter = MatchKeyword("city", "London"); -var searches = new List +var queries = new List { - new() - { - Vector = { new float[] { 0.2f, 0.1f, 0.9f, 0.7f } }, - Filter = filter, - Limit = 3 - }, - new() - { - Vector = { new float[] { 0.5f, 0.3f, 0.2f, 0.3f } }, - Filter = filter, - Limit = 3 - } + new() + { + CollectionName = "{collection_name}", + Query = new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + Filter = filter, + Limit = 3 + }, + new() + { + CollectionName = "{collection_name}", + Query = new float[] { 0.5f, 0.3f, 0.2f, 0.3f }, + Filter = filter, + Limit = 3 + } }; -await client.SearchBatchAsync(collectionName: "{collection_name}", searches: searches); +await client.QueryBatchAsync(collectionName: "{collection_name}", queries: queries); ``` The result of this API contains one array per search requests. @@ -1173,13 +1174,13 @@ using Qdrant.Client; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( - "{collection_name}", - new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, - payloadSelector: true, - vectorsSelector: true, - limit: 10, - offset: 100 +await client.QueryAsync( + collectionName: "{collection_name}", + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + payloadSelector: true, + vectorsSelector: true, + limit: 10, + offset: 100 ); ``` @@ -1331,12 +1332,12 @@ using Qdrant.Client; var client = new QdrantClient("localhost", 6334); -await client.SearchGroupsAsync( - collectionName: "{collection_name}", - vector: new float[] { 1.1f }, - groupBy: "document_id", - limit: 4, - groupSize: 2 +await client.QueryGroupsAsync( + collectionName: "{collection_name}", + query: new float[] { 1.1f }, + groupBy: "document_id", + limit: 4, + groupSize: 2 ); ``` diff --git a/qdrant-landing/content/documentation/concepts/vectors.md b/qdrant-landing/content/documentation/concepts/vectors.md index 0f73d0dd7..1d0444ace 100644 --- a/qdrant-landing/content/documentation/concepts/vectors.md +++ b/qdrant-landing/content/documentation/concepts/vectors.md @@ -399,12 +399,11 @@ using Qdrant.Client; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( +await client.QueryAsync( collectionName: "{collection_name}", - vector: new float[] {0.1f, 0.2f, 0.3f, 0.4f}, - vectorName: "text", - limit: 3, - sparseIndices: new uint[] {1, 3, 5, 7} + query: new (float, uint)[] {(0.1f, 1), (0.2f, 3), (0.3f, 5), (0.4f, 7)}, + usingVector: "text", + limit: 3 ); ``` diff --git a/qdrant-landing/content/documentation/guides/distributed_deployment.md b/qdrant-landing/content/documentation/guides/distributed_deployment.md index da851c4d0..d65043a28 100644 --- a/qdrant-landing/content/documentation/guides/distributed_deployment.md +++ b/qdrant-landing/content/documentation/guides/distributed_deployment.md @@ -1164,9 +1164,9 @@ using static Qdrant.Client.Grpc.Conditions; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( +await client.QueryAsync( collectionName: "{collection_name}", - vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, filter: MatchKeyword("city", "London"), searchParams: new SearchParams { HnswEf = 128, Exact = true }, limit: 3, diff --git a/qdrant-landing/content/documentation/guides/multiple-partitions.md b/qdrant-landing/content/documentation/guides/multiple-partitions.md index fb79b2e7b..77ce129ed 100644 --- a/qdrant-landing/content/documentation/guides/multiple-partitions.md +++ b/qdrant-landing/content/documentation/guides/multiple-partitions.md @@ -280,9 +280,9 @@ using static Qdrant.Client.Grpc.Conditions; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( +await client.QueryAsync( collectionName: "{collection_name}", - vector: new float[] { 0.1f, 0.1f, 0.9f }, + query: new float[] { 0.1f, 0.1f, 0.9f }, filter: MatchKeyword("group_id", "user_1"), limit: 10 ); diff --git a/qdrant-landing/content/documentation/guides/optimize.md b/qdrant-landing/content/documentation/guides/optimize.md index 1fdf30d6d..a0de74696 100644 --- a/qdrant-landing/content/documentation/guides/optimize.md +++ b/qdrant-landing/content/documentation/guides/optimize.md @@ -250,9 +250,9 @@ using Qdrant.Client.Grpc; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( +await client.QueryAsync( collectionName: "{collection_name}", - vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, searchParams: new SearchParams { Quantization = new QuantizationSearchParams { Rescore = false } @@ -606,9 +606,9 @@ using Qdrant.Client.Grpc; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( +await client.QueryAsync( collectionName: "{collection_name}", - vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, searchParams: new SearchParams { HnswEf = 128, Exact = false }, limit: 3 ); diff --git a/qdrant-landing/content/documentation/guides/quantization.md b/qdrant-landing/content/documentation/guides/quantization.md index 4bb4ef325..cf2dce060 100644 --- a/qdrant-landing/content/documentation/guides/quantization.md +++ b/qdrant-landing/content/documentation/guides/quantization.md @@ -676,19 +676,19 @@ using Qdrant.Client.Grpc; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( - collectionName: "{collection_name}", - vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, - searchParams: new SearchParams - { - Quantization = new QuantizationSearchParams - { - Ignore = false, - Rescore = true, - Oversampling = 2.0 - } - }, - limit: 10 +await client.QueryAsync( + collectionName: "{collection_name}", + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + searchParams: new SearchParams + { + Quantization = new QuantizationSearchParams + { + Ignore = false, + Rescore = true, + Oversampling = 2.0 + } + }, + limit: 10 ); ``` @@ -808,14 +808,14 @@ using Qdrant.Client.Grpc; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( - collectionName: "{collection_name}", - vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, - searchParams: new SearchParams - { - Quantization = new QuantizationSearchParams { Ignore = true } - }, - limit: 10 +await client.QueryAsync( + collectionName: "{collection_name}", + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + searchParams: new SearchParams + { + Quantization = new QuantizationSearchParams { Ignore = true } + }, + limit: 10 ); ``` @@ -1065,14 +1065,14 @@ using Qdrant.Client.Grpc; var client = new QdrantClient("localhost", 6334); -await client.SearchAsync( - collectionName: "{collection_name}", - vector: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, - searchParams: new SearchParams - { - Quantization = new QuantizationSearchParams { Rescore = false } - }, - limit: 3 +await client.QueryAsync( + collectionName: "{collection_name}", + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + searchParams: new SearchParams + { + Quantization = new QuantizationSearchParams { Rescore = false } + }, + limit: 3 ); ``` diff --git a/qdrant-landing/content/documentation/quickstart.md b/qdrant-landing/content/documentation/quickstart.md index d282c2117..ebfa19dc8 100644 --- a/qdrant-landing/content/documentation/quickstart.md +++ b/qdrant-landing/content/documentation/quickstart.md @@ -349,10 +349,12 @@ System.out.println(searchResult); ``` ```csharp -var searchResult = await client.SearchAsync(collectionName: "test_collection", vector: new float[] -{ - 0.2f, 0.1f, 0.9f, 0.7f -}, limit: 3, payloadSelector: true); +var searchResult = await client.QueryAsync( + collectionName: "test_collection", + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + limit: 3, + payloadSelector: true +); Console.WriteLine(searchResult); ``` @@ -456,10 +458,13 @@ System.out.println(searchResult); ```csharp using static Qdrant.Client.Grpc.Conditions; -var searchResult = await client.SearchAsync(collectionName: "test_collection", vector: new float[] -{ - 0.2f, 0.1f, 0.9f, 0.7f -}, filter: MatchKeyword("city", "London"), limit: 3, payloadSelector: true); +var searchResult = await client.QueryAsync( + collectionName: "test_collection", + query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f }, + filter: MatchKeyword("city", "London"), + limit: 3, + payloadSelector: true +); Console.WriteLine(searchResult); ```