made example for explainable

This commit is contained in:
Evgeniya Sukhodolskaya
2025-08-20 13:36:01 +02:00
committed by Jenny
parent 13ed6b91b7
commit 7a60d47283
4 changed files with 13 additions and 13 deletions
@@ -194,15 +194,15 @@ In this case we use a **gauss_decay** function.
### Time-based score boosting
Or combine the score with how close the point's timestamp is to a target datetime (for example, the time of search).
Or combine the score with the information on how "fresh" the result is. It's applicable to (news) articles and in general many other different types of searches (think of the "newest" filter you use in applications).
If each point has a datetime field in its payload, f.e. the time the point was uploaded or last updated, we can calculate the time difference between this value and the target (in seconds).
To implement time-based score boosting, you'll need each point to have a datetime field in its payload, e.g., when the item was uploaded or last updated. Then we can calculate the time difference in seconds between this payload value and the current time, our `target`.
Using an exponential decay function, we can convert this time difference into a value between 0 and 1, then add it to the original score to prioritize results closer in time to the target.
With an exponential decay function, perfect for use cases with time, as freshness is a very quickly lost quality, we can convert this time difference into a value between 0 and 1, then add it to the original score to prioritise fresh results.
`score = score + exp_decay(target_time - x_time)`
`score = score + exp_decay(current_time - point_time)`
In this case, we use an **exp_decay** function.
That's how it will look for an application where, after 1 day, results start being only half-relevant (so get a score of 0.5):
{{< code-snippet path="/documentation/headless/snippets/query-points/score-boost-time/" >}}
@@ -1 +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.
This code snippet applies exponential decay to boost the relevance of search results based on a datetime field called "upload_time" in the payload (which can be when a point was uploaded to Qdrant). Items closer in time to a specified `target`, so, in our case, the current datetime, which means "fresher" results, receive higher scores. Relevance score is decreasing exponentially with "upload_time" getting further away from `target` time, reaching a 0.5 `midpoint` of relevance after a defined `scale` period of 1 day.
@@ -12,13 +12,13 @@ POST /collections/{collection_name}/points/query
{
"exp_decay": {
"x": {
"datetime_key": "upload_time" // payload key
"datetime_key": "update_time" // payload key
},
"target": {
"datetime": "2025-08-04T00:00:00Z" // target time, for example, time of the search
"datetime": "YYYY-MM-DDT00:00:00Z" // current datetime
},
"scale": 86400, // 1 week in seconds
"midpoint": 0.1 // 0.1 output with deviation on `scale` (1 week) from `target`
"scale": 86400, // 1 day in seconds
"midpoint": 0.5 // if item's "update_time" is more than 1 day apart from current datetime, relevance score is less than 0.5
}
}
]
@@ -18,10 +18,10 @@ time_boosted = client.query_points(
datetime_key="upload_time" # payload key
),
target=models.DatetimeExpression(
datetime="2025-08-04T00:00:00Z" # target time, for example, time of the search
datetime="YYYY-MM-DDT00:00:00Z" # current datetime
),
scale=86400, # 1 week in seconds
midpoint=0.1 # 0.1 output with deviation on `scale` (1 week) from `target`
scale=86400, # 1 day in seconds
midpoint=0.5 # if item's "update_time" is more than 1 day apart from current datetime, relevance score is less than 0.5
)
)
]