time boosting example

This commit is contained in:
Evgeniya Sukhodolskaya
2025-08-20 13:36:01 +02:00
committed by Jenny
parent 020024aea2
commit 13ed6b91b7
4 changed files with 74 additions and 0 deletions
@@ -0,0 +1 @@
This code snippet applies exponential decay to boost the relevance of search results based on a datetime field in the payload. Items closer in time to a specified `target` datetime receive higher scores, with relevance decreasing exponentially and reaching a specified 0.1 `midpoint` of relevance after a defined time `scale` period of 1 week.
@@ -0,0 +1,28 @@
```http
POST /collections/{collection_name}/points/query
{
"prefetch": {
"query": [0.2, 0.8, ...], // <-- dense vector
"limit": 50
}
"query": {
"formula": {
"sum": [
"$score", // the final score = score + exp_decay(target_time - x_time)
{
"exp_decay": {
"x": {
"datetime_key": "upload_time" // payload key
},
"target": {
"datetime": "2025-08-04T00:00:00Z" // target time, for example, time of the search
},
"scale": 86400, // 1 week in seconds
"midpoint": 0.1 // 0.1 output with deviation on `scale` (1 week) from `target`
}
}
]
}
}
}
```
@@ -0,0 +1,31 @@
```python
from qdrant_client import models
time_boosted = client.query_points(
collection_name="{collection_name}",
prefetch=models.Prefetch(
query=[0.2, 0.8, ...], # <-- dense vector
limit=50
),
query=models.FormulaQuery(
formula=models.SumExpression(
sum=[
"$score", # the final score = score + exp_decay(target_time - x_time)
models.ExpDecayExpression(
exp_decay=models.DecayParamsExpression(
x=models.DatetimeKeyExpression(
datetime_key="upload_time" # payload key
),
target=models.DatetimeExpression(
datetime="2025-08-04T00:00:00Z" # target time, for example, time of the search
),
scale=86400, # 1 week in seconds
midpoint=0.1 # 0.1 output with deviation on `scale` (1 week) from `target`
)
)
]
)
)
)
```