Boost RankerCompatible with Milvus v2.6.2+
Instead of relying solely on semantic similarity calculated based on vector distances, Boost Rankers allow you to influence search results in a meaningful way. It is ideal for quickly adjusting search results using metadata filtering.
When a search request includes a Boost Ranker function, Milvus uses the optional filtering condition within the function to find matches among search result candidates and boosts the scores of those matches by applying the specified weight, helping promote or demote the rankings of the matched entities in the final result.
When to use Boost Ranker
Unlike other rankers that rely on cross-encoder models or fusion algorithms, a Boost Ranker directly injects optional metadata-driven rules into the ranking process, which makes it more suitable in the following scenarios.
Use Case |
Examples |
Why Boost Ranker Works Well |
---|---|---|
Business-driven content prioritization |
|
Without the need to rebuild indexes or modify vector embedding models—operations that can be time-consuming—you can instantly promote or demote specific items in search results by applying optional metadata filters in real time. This mechanism enables flexible, dynamic search rankings that easily adapt to evolving business requirements. |
Strategic content downranking |
|
You can also combine multiple Boost Rankers to implement a more dynamic and robust weight-based ranking strategy.
Mechanism of Boost Ranker
The following diagram illustrates the main workflow of Boost Rankers.
Boost Ranker Mechanism
When you insert data, Milvus distributes it across segments. During a search, each segment returns a set of candidates, and Milvus ranks these candidates from all segments to produce the final results. When a search request includes a Boost Ranker, Milvus applies it to the candidate results from each segment to prevent potential precision loss and improve recall.
Before finalizing the results, Milvus processes these candidates with the Boost Ranker as follows:
Applies the optional filtering expression specified in the Boost Ranker to identify the entities that match the expression.
Applies the weight specified in the Boost Ranker to boost the scores of the identified entities.
You cannot use Boost Ranker as the ranker in a multi-vector hybrid search. However, you can use it as the ranker in any of its sub-requests (AnnSearchRequest
).
Examples of Boost Ranker
The following example illustrates the use of a Boost Ranker in a single-vector search that requires returning the top five most relevant entities and adding weights to the scores of entities with the abstract doc type.
Collect search result candidates in segments.
The following table assumes Milvus distributes entities into two segments (0001 and 0002), with each segment returning five candidates.
ID
DocType
Score
Rank
segment
117
abstract
0.344
1
0001
89
abstract
0.456
2
0001
257
body
0.578
3
0001
358
title
0.788
4
0001
168
body
0.899
5
0001
46
body
0.189
1
0002
48
body
0265
2
0002
561
abstract
0.366
3
0002
344
abstract
0.444
4
0002
276
abstract
0.845
5
0002
Apply the filtering expression specified in the Boost Ranker (
doctype='abstract'
).As denoted by the
DocType
field in the following table, Milvus will mark all entities with theirdoctype
set toabstract
for further processing.ID
DocType
Score
Rank
segment
117
abstract
0.344
1
0001
89
abstract
0.456
2
0001
257
body
0.578
3
0001
358
title
0.788
4
0001
168
body
0.899
5
0001
46
body
0.189
1
0002
48
body
0265
2
0002
561
abstract
0.366
3
0002
344
abstract
0.444
4
0002
276
abstract
0.845
5
0002
Apply the weight specified in the Boost Ranker (
weight=0.5
).All identified entities in the previous step will be multiplied by the weight specified in the Boost Ranker, resulting in changes in their ranks.
ID
DocType
Score
Weighted Score
(= score x weight)
Rank
segment
117
abstract
0.344
0.172
1
0001
89
abstract
0.456
0.228
2
0001
257
body
0.578
0.578
3
0001
358
title
0.788
0.788
4
0001
168
body
0.899
0.899
5
0001
561
abstract
0.366
0.183
1
0002
46
body
0.189
0.189
2
0002
344
abstract
0.444
0.222
3
0002
48
body
0.265
0.265
4
0002
276
abstract
0.845
0.423
5
0002
The weight must be a floating-point number that you choose. In cases like the above example, where a smaller score indicates greater relevance, use a weight less than 1. Otherwise, use a weight greater than 1.
Aggregate the candidates from all segments based on the weighted scores to finalize the results.
ID
DocType
Score
Weighted Score
Rank
segment
117
abstract
0.344
0.172
1
0001
561
abstract
0.366
0.183
2
0002
46
body
0.189
0.189
3
0002
344
abstract
0.444
0.222
4
0002
89
abstract
0.456
0.228
5
0001
Usage of Boost Ranker
In this section, you will see examples of how to use Boost Ranker to influence the results of a single-vector search.
Create a Boost Ranker
Before passing a Boost Ranker as the reranker of a search request, you should properly define the Boost Ranker as a reranking function as follows:
from pymilvus import Function, FunctionType
ranker = Function(
name="boost",
input_field_names=[], # Must be an empty list
function_type=FunctionType.RERANK,
params={
"reranker": "boost",
"filter": "doctype == 'abstract'",
"random_score": {
"seed": 126,
"field": "id"
},
"weight": 0.5
}
)
Parameter |
Required? |
Description |
Value/Example |
---|---|---|---|
|
Yes |
Unique identifier for this Function |
|
|
Yes |
List of vector fields to apply the function to (must be empty for RRF Ranker) |
|
|
Yes |
The type of Function to invoke; use |
|
|
Yes |
Specifies the type of the reranker. Must be set to |
|
|
Yes |
Specifies the weight that will be multiplied by the scores of any matching entities in the raw search results. The value should be a floating-point number.
|
|
|
No |
Specifies the filter expression that will be used to match entities among search result entities. It can be any valid basic filter expression mentioned in Filtering Explained. Note: Only use basic operators, such as |
|
|
No |
Specifies the random function that generates a value between
|
|
Search with a single Boost Ranker
Once the Boost Ranker function is ready, you can reference it in a search request. The following example assumes that you have already created a collection that has the following fields: id, vector, and doctype.
from pymilvus import MilvusClient
# Connect to the Milvus server
client = MilvusClient(
uri="http://localhost:19530",
token="root:Milvus"
)
# Assume you have a collection set up
# Conduct a similarity search using the created ranker
client.search(
data=[-0.619954382375778, 0.4479436794798608, -0.17493894838751745, -0.4248030059917294, -0.8648452746018911],
anns_field="vector",
params={},
output_field=["doctype"],
ranker=ranker
)
Search with multiple Boost Rankers
You can combine multiple Boost Rankers in a single search to influence the search results. To do so, create several Boost Rankers, reference them in a FunctionScore instance, and use the FunctionScore instance as the ranker in the search request.
The following example shows how to modify the scores of all identified entities by applying a weight between 0.8 and 1.2.
from pymilvus import MilvusClient, Function, FunctionType, FunctionScore
# Create a Boost Ranker with a fixed weight
fix_weight_ranker = Function(
name="boost",
input_field_names=[], # Must be an empty list
function_type=FunctionType.RERANK,
params={
"reranker": "boost",
"weight": 0.8
}
)
# Create a Boost Ranker with a randomly generated weight between 0 and 0.4
random_weight_ranker = Function(
name="boost",
input_field_names=[], # Must be an empty list
function_type=FunctionType.RERANK,
params={
"reranker": "boost",
"random_score": {
"seed": 126,
},
"weight": 0.4
}
)
# Create a Function Score
ranker = FunctionScore(
functions=[
fix_weight_ranker,
random_weight_ranker
],
params: {
"boost_mode": "Multiply"
"function_mode": "Sum"
}
)
# Conduct a similarity search using the created Function Score
client.search(
data=[-0.619954382375778, 0.4479436794798608, -0.17493894838751745, -0.4248030059917294, -0.8648452746018911],
anns_field="vector",
params={},
output_field=["doctype"],
ranker=ranker
)
Specifically, there are two Boost Rankers: one applies a fixed weight to all found entities, while the other assigns a random weight to them. Then, we reference these two rankers in a FunctionScore, which also defines how the weights influence the scores of the found entities.
The following table lists the parameters required to create a FunctionScore instance.
Parameter |
Required? |
Description |
Value/Example |
---|---|---|---|
|
Yes |
Specifies the names of the target rankers in a list. |
|
|
No |
Specifies how the specified weights influence the scores of any matching entities. Possible values are:
|
|
|
No |
Specifies how the weighted values from various Boost Rankers are processed. Possible values are:
|
|