mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-09 04:48:30 +02:00
Document custom RRF (#1985)
* make dedicated fusion strategy sections * docs: Java, Go, C# snippets Signed-off-by: Anush008 <anushshetty90@gmail.com> * add formula for rrf * add rust and python snippets * Use consistent formatting --------- Signed-off-by: Anush008 <anushshetty90@gmail.com> Co-authored-by: Anush008 <anushshetty90@gmail.com> Co-authored-by: Tim Visée <tim@visee.me>
This commit is contained in:
co-authored by
Anush008
Tim Visée
parent
5ed4822559
commit
902e937a25
+1
@@ -0,0 +1 @@
|
||||
This code snippet demonstrates a hybrid search functionality where you can query points from a collection using both sparse and dense vectors. The code showcases how to combine the results of multiple queries with different vector representations using Reciprocal Rank Fusion (RRF). RRF boosts results that are closer to the top in multiple queries. This hybrid search approach can be useful for obtaining semantic and specific word matching results simultaneously.
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
```csharp
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.QueryAsync(
|
||||
collectionName: "{collection_name}",
|
||||
prefetch: new List < PrefetchQuery > {
|
||||
new() {
|
||||
Query = new(float, uint)[] {
|
||||
(0.22f, 1), (0.8f, 42),
|
||||
},
|
||||
Using = "sparse",
|
||||
Limit = 20
|
||||
},
|
||||
new() {
|
||||
Query = new float[] {
|
||||
0.01f, 0.45f, 0.67f
|
||||
},
|
||||
Using = "dense",
|
||||
Limit = 20
|
||||
}
|
||||
},
|
||||
query: Fusion.Rrf
|
||||
);
|
||||
```
|
||||
@@ -0,0 +1,27 @@
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
client.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Prefetch: []*qdrant.PrefetchQuery{
|
||||
{
|
||||
Query: qdrant.NewQuerySparse([]uint32{1, 42}, []float32{0.22, 0.8}),
|
||||
Using: qdrant.PtrOf("sparse"),
|
||||
},
|
||||
{
|
||||
Query: qdrant.NewQueryDense([]float32{0.01, 0.45, 0.67}),
|
||||
Using: qdrant.PtrOf("dense"),
|
||||
},
|
||||
},
|
||||
Query: qdrant.NewQueryFusion(qdrant.Fusion_RRF),
|
||||
})
|
||||
```
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
```http
|
||||
POST /collections/{collection_name}/points/query
|
||||
{
|
||||
"prefetch": [
|
||||
{
|
||||
"query": {
|
||||
"indices": [1, 42], // <┐
|
||||
"values": [0.22, 0.8] // <┴─sparse vector
|
||||
},
|
||||
"using": "sparse",
|
||||
"limit": 20
|
||||
},
|
||||
{
|
||||
"query": [0.01, 0.45, 0.67, ...], // <-- dense vector
|
||||
"using": "dense",
|
||||
"limit": 20
|
||||
}
|
||||
],
|
||||
"query": { "fusion": "rrf" }, // <--- reciprocal rank fusion
|
||||
"limit": 10
|
||||
}
|
||||
```
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
```java
|
||||
import java.util.List;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.fusion;
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.Fusion;
|
||||
import io.qdrant.client.grpc.Points.PrefetchQuery;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
|
||||
QdrantClient client = new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addPrefetch(PrefetchQuery.newBuilder()
|
||||
.setQuery(nearest(List.of(0.22f, 0.8f), List.of(1, 42)))
|
||||
.setUsing("sparse")
|
||||
.setLimit(20)
|
||||
.build())
|
||||
.addPrefetch(PrefetchQuery.newBuilder()
|
||||
.setQuery(nearest(List.of(0.01f, 0.45f, 0.67f)))
|
||||
.setUsing("dense")
|
||||
.setLimit(20)
|
||||
.build())
|
||||
.setQuery(fusion(Fusion.RRF))
|
||||
.build())
|
||||
.get();
|
||||
```
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
```python
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333")
|
||||
|
||||
client.query_points(
|
||||
collection_name="{collection_name}",
|
||||
prefetch=[
|
||||
models.Prefetch(
|
||||
query=models.SparseVector(indices=[1, 42], values=[0.22, 0.8]),
|
||||
using="sparse",
|
||||
limit=20,
|
||||
),
|
||||
models.Prefetch(
|
||||
query=[0.01, 0.45, 0.67], # <-- dense vector
|
||||
using="dense",
|
||||
limit=20,
|
||||
),
|
||||
],
|
||||
query=models.FusionQuery(fusion=models.Fusion.RRF),
|
||||
)
|
||||
```
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
```rust
|
||||
use qdrant_client::Qdrant;
|
||||
use qdrant_client::qdrant::{Fusion, PrefetchQueryBuilder, Query, QueryPointsBuilder};
|
||||
|
||||
let client = Qdrant::from_url("http://localhost:6334").build()?;
|
||||
|
||||
client.query(
|
||||
QueryPointsBuilder::new("{collection_name}")
|
||||
.add_prefetch(PrefetchQueryBuilder::default()
|
||||
.query(Query::new_nearest([(1, 0.22), (42, 0.8)].as_slice()))
|
||||
.using("sparse")
|
||||
.limit(20u64)
|
||||
)
|
||||
.add_prefetch(PrefetchQueryBuilder::default()
|
||||
.query(Query::new_nearest(vec![0.01, 0.45, 0.67]))
|
||||
.using("dense")
|
||||
.limit(20u64)
|
||||
)
|
||||
.query(Query::new_fusion(Fusion::Rrf))
|
||||
).await?;
|
||||
```
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
```typescript
|
||||
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 });
|
||||
|
||||
client.query("{collection_name}", {
|
||||
prefetch: [
|
||||
{
|
||||
query: {
|
||||
values: [0.22, 0.8],
|
||||
indices: [1, 42],
|
||||
},
|
||||
using: 'sparse',
|
||||
limit: 20,
|
||||
},
|
||||
{
|
||||
query: [0.01, 0.45, 0.67],
|
||||
using: 'dense',
|
||||
limit: 20,
|
||||
},
|
||||
],
|
||||
query: {
|
||||
fusion: 'rrf',
|
||||
},
|
||||
});
|
||||
```
|
||||
Reference in New Issue
Block a user