top
relationalai.semantics.std.aggregates
top(limit: int, *args: AggValue) -> AggregateGet the top N results in descending order.
Parameters
Section titled “Parameters”
(limitint) - Number of top results to return.
(*argsAggValue, default:()) - Values to order by (descending).
Returns
Section titled “Returns”Aggregate- AnAggregaterepresenting the computation of the top N results.
Examples
Section titled “Examples”Get top 10 highest-paid employees:
>>> select(Employee).where(aggregates.top(10, Employee.salary))Get top 3 products by revenue per store:
>>> select(Product).where(aggregates.top(3, Product.revenue).per(Store).where(Product.store == Store))Referenced By
Section titled “Referenced By”RelationalAI Documentation └── Build With RelationalAI └── Understand how PyRel works ├── Build a semantic model │ └── Query a model │ └── Rank and select top results withrank,asc,desc, andtop└── Use advanced reasoning > Rules-based reasoning └── Aggregate and group data └── Pick top and bottom results