From 250ab6dfa87e65e54bb7511c69ae54ec247447db Mon Sep 17 00:00:00 2001 From: Arnaud Gourlay Date: Tue, 13 Aug 2024 13:45:42 +0200 Subject: [PATCH] Docs for query group API (#1061) * Docs for query group API * add info about grouping in query page * Update qdrant-landing/content/documentation/concepts/hybrid-queries.md Co-authored-by: Anush * Update qdrant-landing/content/documentation/concepts/hybrid-queries.md Co-authored-by: Anush * Update qdrant-landing/content/documentation/concepts/hybrid-queries.md Co-authored-by: Anush * update snippets --------- Co-authored-by: Anush Co-authored-by: generall --- .../documentation/concepts/hybrid-queries.md | 100 ++++++++++++++++++ .../content/documentation/concepts/search.md | 1 + 2 files changed, 101 insertions(+) diff --git a/qdrant-landing/content/documentation/concepts/hybrid-queries.md b/qdrant-landing/content/documentation/concepts/hybrid-queries.md index c2727ddcd..2879b4eb8 100644 --- a/qdrant-landing/content/documentation/concepts/hybrid-queries.md +++ b/qdrant-landing/content/documentation/concepts/hybrid-queries.md @@ -1079,3 +1079,103 @@ In this example, we first fetch 10 points with the color `"red"` and then 10 poi Then, we order the results by the price field. This is how we can guarantee even sampling of both colors in the results and also get the cheapest ones first. + +## Grouping + +*Available as of v1.11.0* + +It is possible to group results by a certain field. This is useful when you have multiple points for the same item, and you want to avoid redundancy of the same item in the results. + +REST API ([Schema](https://api.qdrant.tech/master/api-reference/query/query_points_groups)): + +```http +POST /collections/{collection_name}/points/query/groups +{ + "query": [0.01, 0.45, 0.67], + group_by="document_id", # Path of the field to group by + limit=4, # Max amount of groups + group_size=2, # Max amount of points per group +} +``` + +```python +from qdrant_client import QdrantClient, models + +client = QdrantClient(url="http://localhost:6333") + +client.query_point_groups( + collection_name="{collection_name}", + query=[0.01, 0.45, 0.67], + group_by="document_id", + limit=4, + group_size=2, +) +``` + +```typescript +import { QdrantClient } from "@qdrant/js-client-rest"; + +const client = new QdrantClient({ host: "localhost", port: 6333 }); + +client.queryGroups("{collection_name}", { + query: [0.01, 0.45, 0.67], + group_by: "document_id", + limit: 4, + group_size: 2, +}); +``` + +```rust +use qdrant_client::Qdrant; +use qdrant_client::qdrant::{Query, QueryPointsBuilder}; + +let client = Qdrant::from_url("http://localhost:6334").build()?; + +client.query_groups( + QueryPointGroupsBuilder::new("{collection_name}", "document_id") + .query(Query::from(vec![0.01, 0.45, 0.67])) + .limit(4u64) + .group_size(2u64) +).await?; +``` + +```java +import static io.qdrant.client.QueryFactory.nearest; + +import io.qdrant.client.QdrantClient; +import io.qdrant.client.QdrantGrpcClient; +import io.qdrant.client.grpc.Points.QueryPointGroups; + +QdrantClient client = + new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build()); + +client + .queryGroupsAsync( + QueryPointGroups.newBuilder() + .setCollectionName("{collection_name}") + .setGroupBy("document_id") + .setQuery(nearest(0.01f, 0.45f, 0.67f)) + .setLimit(4) + .setGroupSize(2) + .build()) + .get(); +``` + +```csharp +using Qdrant.Client; +using Qdrant.Client.Grpc; + +var client = new QdrantClient("localhost", 6334); + +await client.QueryGroupsAsync( + collectionName: "{collection_name}", + groupBy: "document_id", + query: new float[] { + 0.01f, 0.45f, 0.67f + }, + limit: 4, + groupSize: 2 +); +``` + +For more information on the `grouping` capabilities refer to the reference documentation for search with [grouping](./search/#search-groups) and [lookup](./search/#lookup-in-groups). \ No newline at end of file diff --git a/qdrant-landing/content/documentation/concepts/search.md b/qdrant-landing/content/documentation/concepts/search.md index 75d0f91f9..cc6f73c52 100644 --- a/qdrant-landing/content/documentation/concepts/search.md +++ b/qdrant-landing/content/documentation/concepts/search.md @@ -30,6 +30,7 @@ Depending on the `query` parameter, Qdrant might prefer different strategies for | [Recommendations](../explore/#recommendation-api) | Provide positive and negative examples | | [Discovery Search](../explore/#discovery-api) | Guide the search using context as a one-shot training set | | [Scroll](../points/#scroll-points) | Get all points with optional filtering | +| [Grouping](../search/#grouping-api) | Group results by a certain field | | [Order By](../hybrid-queries/#re-ranking-with-stored-values) | Order points by payload key | | [Hybrid Search](../hybrid-queries/#hybrid-search) | Combine multiple queries to get better results | | [Multi-Stage Search](../hybrid-queries/#multi-stage-queries) | Optimize performance for large embeddings |