跳到主要内容
版本:v3.0.x

TopHits

A TopHits instance configures the representative entities returned from each SearchAggregation bucket.

Python
class pymilvus.TopHits

Constructor

Python
TopHits(
size: int,
sort: list[dict[str, str]] | None = None,
)

PARAMETERS:

  • size (int) [REQUIRED] -

    The maximum number of representative entities returned from each bucket. The value must be a positive integer.

  • sort (list[dict[str, str]] | None) -

    Hit ordering rules evaluated in list order. Each item is a single-key dictionary mapping a scalar field name or _score to "asc" or "desc". If omitted, the server uses its default hit order.

RETURN TYPE:

TopHits

EXCEPTIONS:

  • ParamError - Raised when size is not a positive integer or sort is not a list of single-key dictionaries with valid directions.

Example

Python
from pymilvus import SearchAggregation, TopHits

aggregation = SearchAggregation(
fields=["brand"],
size=10,
top_hits=TopHits(
size=3,
sort=[{"rating": "desc"}, {"_score": "desc"}],
),
)