TopHits
公测版TopHits 实例用于配置从每个 SearchAggregation bucket 返回的代表性 Entity。
python
class pymilvus.TopHits
构造函数
python
TopHits(
size: int,
sort: list[dict[str, str]] | None = None,
)
参数:
-
size (int) [必需] -
从每个 bucket 返回的代表性 Entity 的最大数量。该值必须为正整数。
-
sort (list[dict[str, str]] | None) -
按列表顺序计算的命中排序规则。每一项都是单键字典,将标量字段名或
_score映射为"asc"或"desc"。如果省略,服务器将使用其默认的命中排序顺序。
返回类型:
TopHits
异常:
- 当
size不是正整数,或sort不是由具有有效方向的单键字典组成的列表时,将引发 ParamError。
示例
python
from pymilvus import SearchAggregation, TopHits
aggregation = SearchAggregation(
fields=["brand"],
size=10,
top_hits=TopHits(
size=3,
sort=[{"rating": "desc"}, {"_score": "desc"}],
),
)