mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-03 01:48:32 +02:00
upload snippets
This commit is contained in:
@@ -156,7 +156,7 @@ For custom fusion, use the [Formula Query](/documentation/search/search-relevanc
|
||||
|
||||
To evaluate which works better for your use case, create a small golden query set and compare [retrieval quality metrics](/documentation/improve-search/retrieval-relevance/) (for example, NDCG@10) under each method.
|
||||
|
||||
See also: [Hybrid Queries](/documentation/search/hybrid-queries/)
|
||||
See also: the [Choosing a Fusion Method](/documentation/search/hybrid-queries/#choosing-a-fusion-method) decision table in the Hybrid Queries reference, and the [Choosing a Fusion Method notebook](https://github.com/qdrant/examples/blob/master/fusion-methods/Choosing_a_Fusion_Method.ipynb) for a runnable RRF vs weighted RRF vs DBSF eval on BEIR/SciFact with a reusable weight-tuning helper.
|
||||
|
||||
### My hybrid search results aren't relevant. Where do I start debugging?
|
||||
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
This code snippet runs a hybrid query that fuses sparse and dense results with Distribution-Based Score Fusion (DBSF). DBSF normalizes each retriever's score distribution using the mean and three standard deviations as limits, then sums the normalized scores. Use it when the raw scores carry magnitude information you want to preserve, rather than discarding score information as RRF does.
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
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.Dbsf
|
||||
);
|
||||
}
|
||||
}
|
||||
+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.Dbsf
|
||||
);
|
||||
```
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
```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"),
|
||||
Limit: qdrant.PtrOf(uint64(20)),
|
||||
},
|
||||
{
|
||||
Query: qdrant.NewQueryDense([]float32{0.01, 0.45, 0.67}),
|
||||
Using: qdrant.PtrOf("dense"),
|
||||
Limit: qdrant.PtrOf(uint64(20)),
|
||||
},
|
||||
},
|
||||
Query: qdrant.NewQueryFusion(qdrant.Fusion_DBSF),
|
||||
})
|
||||
```
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
```java
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
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.DBSF))
|
||||
.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.DBSF),
|
||||
)
|
||||
```
|
||||
+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::Dbsf))
|
||||
).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: 'dbsf',
|
||||
},
|
||||
});
|
||||
```
|
||||
@@ -0,0 +1,33 @@
|
||||
package snippet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
func Main() {
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
if err != nil { panic(err) } // @hide
|
||||
|
||||
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"),
|
||||
Limit: qdrant.PtrOf(uint64(20)),
|
||||
},
|
||||
{
|
||||
Query: qdrant.NewQueryDense([]float32{0.01, 0.45, 0.67}),
|
||||
Using: qdrant.PtrOf("dense"),
|
||||
Limit: qdrant.PtrOf(uint64(20)),
|
||||
},
|
||||
},
|
||||
Query: qdrant.NewQueryFusion(qdrant.Fusion_DBSF),
|
||||
})
|
||||
}
|
||||
+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": "dbsf" }, // <--- distribution-based score fusion
|
||||
"limit": 10
|
||||
}
|
||||
```
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
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.DBSF))
|
||||
.build())
|
||||
.get();
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
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.DBSF),
|
||||
)
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
use qdrant_client::Qdrant;
|
||||
use qdrant_client::qdrant::{Fusion, PrefetchQueryBuilder, Query, QueryPointsBuilder};
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
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::Dbsf))
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
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: 'dbsf',
|
||||
},
|
||||
});
|
||||
+1
@@ -0,0 +1 @@
|
||||
This code snippet shows the canonical pattern for combining hybrid search fusion with business-logic ranking. The inner prefetch fuses sparse and dense results with RRF, then the outer `FormulaQuery` applies exponential decay on a `published_at` payload field to boost recent documents. Use this pattern any time you want fusion plus recency, popularity, geo decay, or category-conditional multipliers, rather than trying to encode those signals as fusion weights.
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.QueryAsync(
|
||||
collectionName: "{collection_name}",
|
||||
prefetch:
|
||||
[
|
||||
new PrefetchQuery {
|
||||
Prefetch = {
|
||||
new PrefetchQuery {
|
||||
Query = new(float, uint)[] { (0.22f, 1), (0.8f, 42) },
|
||||
Using = "sparse",
|
||||
Limit = 100
|
||||
},
|
||||
new PrefetchQuery {
|
||||
Query = new float[] { 0.01f, 0.45f, 0.67f },
|
||||
Using = "dense",
|
||||
Limit = 100
|
||||
},
|
||||
},
|
||||
Query = Fusion.Rrf,
|
||||
Limit = 100
|
||||
},
|
||||
],
|
||||
query: new Formula
|
||||
{
|
||||
Expression = new SumExpression
|
||||
{
|
||||
Sum =
|
||||
{
|
||||
"$score", // the fused score from the RRF prefetch
|
||||
Expression.FromExpDecay(
|
||||
new()
|
||||
{
|
||||
X = Expression.FromDateTimeKey("published_at"),
|
||||
Target = Expression.FromDateTime("YYYY-MM-DDT00:00:00Z"),
|
||||
Scale = 86400 * 180, // 180 days in seconds
|
||||
Midpoint = 0.5f
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
limit: 10
|
||||
);
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
```csharp
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.QueryAsync(
|
||||
collectionName: "{collection_name}",
|
||||
prefetch:
|
||||
[
|
||||
new PrefetchQuery {
|
||||
Prefetch = {
|
||||
new PrefetchQuery {
|
||||
Query = new(float, uint)[] { (0.22f, 1), (0.8f, 42) },
|
||||
Using = "sparse",
|
||||
Limit = 100
|
||||
},
|
||||
new PrefetchQuery {
|
||||
Query = new float[] { 0.01f, 0.45f, 0.67f },
|
||||
Using = "dense",
|
||||
Limit = 100
|
||||
},
|
||||
},
|
||||
Query = Fusion.Rrf,
|
||||
Limit = 100
|
||||
},
|
||||
],
|
||||
query: new Formula
|
||||
{
|
||||
Expression = new SumExpression
|
||||
{
|
||||
Sum =
|
||||
{
|
||||
"$score", // the fused score from the RRF prefetch
|
||||
Expression.FromExpDecay(
|
||||
new()
|
||||
{
|
||||
X = Expression.FromDateTimeKey("published_at"),
|
||||
Target = Expression.FromDateTime("YYYY-MM-DDT00:00:00Z"),
|
||||
Scale = 86400 * 180, // 180 days in seconds
|
||||
Midpoint = 0.5f
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
limit: 10
|
||||
);
|
||||
```
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
```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{
|
||||
{
|
||||
Prefetch: []*qdrant.PrefetchQuery{
|
||||
{
|
||||
Query: qdrant.NewQuerySparse([]uint32{1, 42}, []float32{0.22, 0.8}),
|
||||
Using: qdrant.PtrOf("sparse"),
|
||||
Limit: qdrant.PtrOf(uint64(100)),
|
||||
},
|
||||
{
|
||||
Query: qdrant.NewQueryDense([]float32{0.01, 0.45, 0.67}),
|
||||
Using: qdrant.PtrOf("dense"),
|
||||
Limit: qdrant.PtrOf(uint64(100)),
|
||||
},
|
||||
},
|
||||
Query: qdrant.NewQueryFusion(qdrant.Fusion_RRF),
|
||||
Limit: qdrant.PtrOf(uint64(100)),
|
||||
},
|
||||
},
|
||||
Query: qdrant.NewQueryFormula(&qdrant.Formula{
|
||||
Expression: qdrant.NewExpressionSum(&qdrant.SumExpression{
|
||||
Sum: []*qdrant.Expression{
|
||||
qdrant.NewExpressionVariable("$score"), // the fused score from the RRF prefetch
|
||||
qdrant.NewExpressionExpDecay(&qdrant.DecayParamsExpression{
|
||||
X: qdrant.NewExpressionDatetimeKey("published_at"),
|
||||
Target: qdrant.NewExpressionDatetime("YYYY-MM-DDT00:00:00Z"),
|
||||
Scale: qdrant.PtrOf(float32(86400 * 180)), // 180 days in seconds
|
||||
Midpoint: qdrant.PtrOf(float32(0.5)),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
Limit: qdrant.PtrOf(uint64(10)),
|
||||
})
|
||||
```
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
```java
|
||||
import static io.qdrant.client.ExpressionFactory.datetime;
|
||||
import static io.qdrant.client.ExpressionFactory.datetimeKey;
|
||||
import static io.qdrant.client.ExpressionFactory.expDecay;
|
||||
import static io.qdrant.client.ExpressionFactory.sum;
|
||||
import static io.qdrant.client.ExpressionFactory.variable;
|
||||
import static io.qdrant.client.QueryFactory.formula;
|
||||
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.DecayParamsExpression;
|
||||
import io.qdrant.client.grpc.Points.Formula;
|
||||
import io.qdrant.client.grpc.Points.Fusion;
|
||||
import io.qdrant.client.grpc.Points.PrefetchQuery;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.SumExpression;
|
||||
import java.util.List;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addPrefetch(
|
||||
PrefetchQuery.newBuilder()
|
||||
.addPrefetch(
|
||||
PrefetchQuery.newBuilder()
|
||||
.setQuery(nearest(List.of(0.22f, 0.8f), List.of(1, 42)))
|
||||
.setUsing("sparse")
|
||||
.setLimit(100)
|
||||
.build())
|
||||
.addPrefetch(
|
||||
PrefetchQuery.newBuilder()
|
||||
.setQuery(nearest(List.of(0.01f, 0.45f, 0.67f)))
|
||||
.setUsing("dense")
|
||||
.setLimit(100)
|
||||
.build())
|
||||
.setQuery(fusion(Fusion.RRF))
|
||||
.setLimit(100)
|
||||
.build())
|
||||
.setQuery(
|
||||
formula(
|
||||
Formula.newBuilder()
|
||||
.setExpression(
|
||||
sum(
|
||||
SumExpression.newBuilder()
|
||||
.addSum(variable("$score"))
|
||||
.addSum(
|
||||
expDecay(
|
||||
DecayParamsExpression.newBuilder()
|
||||
.setX(datetimeKey("published_at"))
|
||||
.setTarget(
|
||||
datetime("YYYY-MM-DDT00:00:00Z"))
|
||||
.setScale(86400 * 180)
|
||||
.setMidpoint(0.5f)
|
||||
.build()))
|
||||
.build()))
|
||||
.build()))
|
||||
.setLimit(10)
|
||||
.build())
|
||||
.get();
|
||||
```
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
```python
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333")
|
||||
|
||||
client.query_points(
|
||||
collection_name="{collection_name}",
|
||||
prefetch=models.Prefetch(
|
||||
prefetch=[
|
||||
models.Prefetch(
|
||||
query=models.SparseVector(indices=[1, 42], values=[0.22, 0.8]),
|
||||
using="sparse",
|
||||
limit=100,
|
||||
),
|
||||
models.Prefetch(
|
||||
query=[0.01, 0.45, 0.67], # <-- dense vector
|
||||
using="dense",
|
||||
limit=100,
|
||||
),
|
||||
],
|
||||
query=models.FusionQuery(fusion=models.Fusion.RRF),
|
||||
limit=100,
|
||||
),
|
||||
query=models.FormulaQuery(
|
||||
formula=models.SumExpression(
|
||||
sum=[
|
||||
"$score", # the fused score from the RRF prefetch
|
||||
models.ExpDecayExpression(
|
||||
exp_decay=models.DecayParamsExpression(
|
||||
x=models.DatetimeKeyExpression(datetime_key="published_at"),
|
||||
target=models.DatetimeExpression(datetime="YYYY-MM-DDT00:00:00Z"),
|
||||
scale=86400 * 180, # 180 days in seconds
|
||||
midpoint=0.5,
|
||||
)
|
||||
),
|
||||
]
|
||||
)
|
||||
),
|
||||
limit=10,
|
||||
)
|
||||
```
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
```rust
|
||||
use qdrant_client::Qdrant;
|
||||
use qdrant_client::qdrant::{
|
||||
DecayParamsExpressionBuilder, Expression, FormulaBuilder, Fusion, PrefetchQueryBuilder, Query,
|
||||
QueryPointsBuilder,
|
||||
};
|
||||
|
||||
let client = Qdrant::from_url("http://localhost:6334").build()?;
|
||||
|
||||
client.query(
|
||||
QueryPointsBuilder::new("{collection_name}")
|
||||
.add_prefetch(
|
||||
PrefetchQueryBuilder::default()
|
||||
.add_prefetch(
|
||||
PrefetchQueryBuilder::default()
|
||||
.query(Query::new_nearest([(1, 0.22), (42, 0.8)].as_slice()))
|
||||
.using("sparse")
|
||||
.limit(100u64),
|
||||
)
|
||||
.add_prefetch(
|
||||
PrefetchQueryBuilder::default()
|
||||
.query(Query::new_nearest(vec![0.01, 0.45, 0.67]))
|
||||
.using("dense")
|
||||
.limit(100u64),
|
||||
)
|
||||
.query(Query::new_fusion(Fusion::Rrf))
|
||||
.limit(100u64),
|
||||
)
|
||||
.query(
|
||||
FormulaBuilder::new(Expression::sum_with([
|
||||
Expression::score(),
|
||||
Expression::exp_decay(
|
||||
DecayParamsExpressionBuilder::new(Expression::datetime_key("published_at"))
|
||||
.target(Expression::datetime("YYYY-MM-DDT00:00:00Z"))
|
||||
.scale(86400.0 * 180.0)
|
||||
.midpoint(0.5),
|
||||
),
|
||||
])),
|
||||
)
|
||||
.limit(10u64),
|
||||
)
|
||||
.await?;
|
||||
```
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
```typescript
|
||||
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 });
|
||||
|
||||
await client.query("{collection_name}", {
|
||||
prefetch: {
|
||||
prefetch: [
|
||||
{
|
||||
query: {
|
||||
values: [0.22, 0.8],
|
||||
indices: [1, 42],
|
||||
},
|
||||
using: "sparse",
|
||||
limit: 100,
|
||||
},
|
||||
{
|
||||
query: [0.01, 0.45, 0.67], // <-- dense vector
|
||||
using: "dense",
|
||||
limit: 100,
|
||||
},
|
||||
],
|
||||
query: { fusion: "rrf" },
|
||||
limit: 100,
|
||||
},
|
||||
query: {
|
||||
formula: {
|
||||
sum: [
|
||||
"$score", // the fused score from the RRF prefetch
|
||||
{
|
||||
exp_decay: {
|
||||
x: { datetime_key: "published_at" },
|
||||
target: { datetime: "YYYY-MM-DDT00:00:00Z" },
|
||||
scale: 86400 * 180, // 180 days in seconds
|
||||
midpoint: 0.5,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
limit: 10,
|
||||
});
|
||||
```
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package snippet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
func Main() {
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
if err != nil { panic(err) } // @hide
|
||||
|
||||
client.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Prefetch: []*qdrant.PrefetchQuery{
|
||||
{
|
||||
Prefetch: []*qdrant.PrefetchQuery{
|
||||
{
|
||||
Query: qdrant.NewQuerySparse([]uint32{1, 42}, []float32{0.22, 0.8}),
|
||||
Using: qdrant.PtrOf("sparse"),
|
||||
Limit: qdrant.PtrOf(uint64(100)),
|
||||
},
|
||||
{
|
||||
Query: qdrant.NewQueryDense([]float32{0.01, 0.45, 0.67}),
|
||||
Using: qdrant.PtrOf("dense"),
|
||||
Limit: qdrant.PtrOf(uint64(100)),
|
||||
},
|
||||
},
|
||||
Query: qdrant.NewQueryFusion(qdrant.Fusion_RRF),
|
||||
Limit: qdrant.PtrOf(uint64(100)),
|
||||
},
|
||||
},
|
||||
Query: qdrant.NewQueryFormula(&qdrant.Formula{
|
||||
Expression: qdrant.NewExpressionSum(&qdrant.SumExpression{
|
||||
Sum: []*qdrant.Expression{
|
||||
qdrant.NewExpressionVariable("$score"), // the fused score from the RRF prefetch
|
||||
qdrant.NewExpressionExpDecay(&qdrant.DecayParamsExpression{
|
||||
X: qdrant.NewExpressionDatetimeKey("published_at"),
|
||||
Target: qdrant.NewExpressionDatetime("YYYY-MM-DDT00:00:00Z"),
|
||||
Scale: qdrant.PtrOf(float32(86400 * 180)), // 180 days in seconds
|
||||
Midpoint: qdrant.PtrOf(float32(0.5)),
|
||||
}),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
Limit: qdrant.PtrOf(uint64(10)),
|
||||
})
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
```http
|
||||
POST /collections/{collection_name}/points/query
|
||||
{
|
||||
"prefetch": {
|
||||
"prefetch": [
|
||||
{
|
||||
"query": {
|
||||
"indices": [1, 42], // <┐
|
||||
"values": [0.22, 0.8] // <┴─sparse vector
|
||||
},
|
||||
"using": "sparse",
|
||||
"limit": 100
|
||||
},
|
||||
{
|
||||
"query": [0.01, 0.45, 0.67, ...], // <-- dense vector
|
||||
"using": "dense",
|
||||
"limit": 100
|
||||
}
|
||||
],
|
||||
"query": { "fusion": "rrf" },
|
||||
"limit": 100
|
||||
},
|
||||
"query": {
|
||||
"formula": {
|
||||
"sum": [
|
||||
"$score", // the fused score from the RRF prefetch
|
||||
{
|
||||
"exp_decay": {
|
||||
"x": {
|
||||
"datetime_key": "published_at"
|
||||
},
|
||||
"target": {
|
||||
"datetime": "YYYY-MM-DDT00:00:00Z"
|
||||
},
|
||||
"scale": 15552000, // 180 days in seconds
|
||||
"midpoint": 0.5
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"limit": 10
|
||||
}
|
||||
```
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
import static io.qdrant.client.ExpressionFactory.datetime;
|
||||
import static io.qdrant.client.ExpressionFactory.datetimeKey;
|
||||
import static io.qdrant.client.ExpressionFactory.expDecay;
|
||||
import static io.qdrant.client.ExpressionFactory.sum;
|
||||
import static io.qdrant.client.ExpressionFactory.variable;
|
||||
import static io.qdrant.client.QueryFactory.formula;
|
||||
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.DecayParamsExpression;
|
||||
import io.qdrant.client.grpc.Points.Formula;
|
||||
import io.qdrant.client.grpc.Points.Fusion;
|
||||
import io.qdrant.client.grpc.Points.PrefetchQuery;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.SumExpression;
|
||||
import java.util.List;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addPrefetch(
|
||||
PrefetchQuery.newBuilder()
|
||||
.addPrefetch(
|
||||
PrefetchQuery.newBuilder()
|
||||
.setQuery(nearest(List.of(0.22f, 0.8f), List.of(1, 42)))
|
||||
.setUsing("sparse")
|
||||
.setLimit(100)
|
||||
.build())
|
||||
.addPrefetch(
|
||||
PrefetchQuery.newBuilder()
|
||||
.setQuery(nearest(List.of(0.01f, 0.45f, 0.67f)))
|
||||
.setUsing("dense")
|
||||
.setLimit(100)
|
||||
.build())
|
||||
.setQuery(fusion(Fusion.RRF))
|
||||
.setLimit(100)
|
||||
.build())
|
||||
.setQuery(
|
||||
formula(
|
||||
Formula.newBuilder()
|
||||
.setExpression(
|
||||
sum(
|
||||
SumExpression.newBuilder()
|
||||
.addSum(variable("$score"))
|
||||
.addSum(
|
||||
expDecay(
|
||||
DecayParamsExpression.newBuilder()
|
||||
.setX(datetimeKey("published_at"))
|
||||
.setTarget(
|
||||
datetime("YYYY-MM-DDT00:00:00Z"))
|
||||
.setScale(86400 * 180)
|
||||
.setMidpoint(0.5f)
|
||||
.build()))
|
||||
.build()))
|
||||
.build()))
|
||||
.setLimit(10)
|
||||
.build())
|
||||
.get();
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
client = QdrantClient(url="http://localhost:6333")
|
||||
|
||||
client.query_points(
|
||||
collection_name="{collection_name}",
|
||||
prefetch=models.Prefetch(
|
||||
prefetch=[
|
||||
models.Prefetch(
|
||||
query=models.SparseVector(indices=[1, 42], values=[0.22, 0.8]),
|
||||
using="sparse",
|
||||
limit=100,
|
||||
),
|
||||
models.Prefetch(
|
||||
query=[0.01, 0.45, 0.67], # <-- dense vector
|
||||
using="dense",
|
||||
limit=100,
|
||||
),
|
||||
],
|
||||
query=models.FusionQuery(fusion=models.Fusion.RRF),
|
||||
limit=100,
|
||||
),
|
||||
query=models.FormulaQuery(
|
||||
formula=models.SumExpression(
|
||||
sum=[
|
||||
"$score", # the fused score from the RRF prefetch
|
||||
models.ExpDecayExpression(
|
||||
exp_decay=models.DecayParamsExpression(
|
||||
x=models.DatetimeKeyExpression(datetime_key="published_at"),
|
||||
target=models.DatetimeExpression(datetime="YYYY-MM-DDT00:00:00Z"),
|
||||
scale=86400 * 180, # 180 days in seconds
|
||||
midpoint=0.5,
|
||||
)
|
||||
),
|
||||
]
|
||||
)
|
||||
),
|
||||
limit=10,
|
||||
)
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
use qdrant_client::Qdrant;
|
||||
use qdrant_client::qdrant::{
|
||||
DecayParamsExpressionBuilder, Expression, FormulaBuilder, Fusion, PrefetchQueryBuilder, Query,
|
||||
QueryPointsBuilder,
|
||||
};
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
let client = Qdrant::from_url("http://localhost:6334").build()?;
|
||||
|
||||
client.query(
|
||||
QueryPointsBuilder::new("{collection_name}")
|
||||
.add_prefetch(
|
||||
PrefetchQueryBuilder::default()
|
||||
.add_prefetch(
|
||||
PrefetchQueryBuilder::default()
|
||||
.query(Query::new_nearest([(1, 0.22), (42, 0.8)].as_slice()))
|
||||
.using("sparse")
|
||||
.limit(100u64),
|
||||
)
|
||||
.add_prefetch(
|
||||
PrefetchQueryBuilder::default()
|
||||
.query(Query::new_nearest(vec![0.01, 0.45, 0.67]))
|
||||
.using("dense")
|
||||
.limit(100u64),
|
||||
)
|
||||
.query(Query::new_fusion(Fusion::Rrf))
|
||||
.limit(100u64),
|
||||
)
|
||||
.query(
|
||||
FormulaBuilder::new(Expression::sum_with([
|
||||
Expression::score(),
|
||||
Expression::exp_decay(
|
||||
DecayParamsExpressionBuilder::new(Expression::datetime_key("published_at"))
|
||||
.target(Expression::datetime("YYYY-MM-DDT00:00:00Z"))
|
||||
.scale(86400.0 * 180.0)
|
||||
.midpoint(0.5),
|
||||
),
|
||||
])),
|
||||
)
|
||||
.limit(10u64),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 });
|
||||
|
||||
await client.query("{collection_name}", {
|
||||
prefetch: {
|
||||
prefetch: [
|
||||
{
|
||||
query: {
|
||||
values: [0.22, 0.8],
|
||||
indices: [1, 42],
|
||||
},
|
||||
using: "sparse",
|
||||
limit: 100,
|
||||
},
|
||||
{
|
||||
query: [0.01, 0.45, 0.67], // <-- dense vector
|
||||
using: "dense",
|
||||
limit: 100,
|
||||
},
|
||||
],
|
||||
query: { fusion: "rrf" },
|
||||
limit: 100,
|
||||
},
|
||||
query: {
|
||||
formula: {
|
||||
sum: [
|
||||
"$score", // the fused score from the RRF prefetch
|
||||
{
|
||||
exp_decay: {
|
||||
x: { datetime_key: "published_at" },
|
||||
target: { datetime: "YYYY-MM-DDT00:00:00Z" },
|
||||
scale: 86400 * 180, // 180 days in seconds
|
||||
midpoint: 0.5,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
limit: 10,
|
||||
});
|
||||
Reference in New Issue
Block a user