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  <anushshetty90@gmail.com>

* Update qdrant-landing/content/documentation/concepts/hybrid-queries.md

Co-authored-by: Anush  <anushshetty90@gmail.com>

* Update qdrant-landing/content/documentation/concepts/hybrid-queries.md

Co-authored-by: Anush  <anushshetty90@gmail.com>

* update snippets

---------

Co-authored-by: Anush <anushshetty90@gmail.com>
Co-authored-by: generall <andrey@vasnetsov.com>
This commit is contained in:
Arnaud Gourlay
2024-08-13 13:45:42 +02:00
committed by GitHub
co-authored by Anush generall
parent 952f4b473d
commit 250ab6dfa8
2 changed files with 101 additions and 0 deletions
@@ -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).
@@ -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 |