Indexes, videos, and tasks
The endpoints that return lists of items support pagination. You can use the following parameters to control pagination behavior:
page
: Page number to retrieve. Defaults to1
.page_limit
: Maximum items per page. Default to10
. The maximum value is50
.
The examples on this page are specific to listing your indexes. The same principles apply to other similar endpoints.
Prerequisites
- You’re familiar with the concepts that are described on the Platform overview page.
- You’ve already created an index.
Examples
The SDKs provide two distinct methods for listing items, each suited to different use cases and requirements. Selecting the most efficient method is important for optimizing the performance of your application:
- Direct pagination: Choose this method for retrieving a specific page, mainly when the total number of items is manageable, or you must fetch a single page of results.
- Iterative pagination: Choose this method for iterative navigation through lists, mainly when your application must retrieve a large number of items.
Direct pagination
Retrieve the first page of results
The following example code retrieves the first page of results using the default value for the page
and page_limit
parameters by invoking the list
method of the index
object with no parameters:
The following output was truncated for brevity:
Retrieve a specific page
The following example code uses the page
parameter to retrieve a specific page (2
):
If the number of items on a page is less than the maximum number of items the platform should return on that page, you’ve reached the end of the dataset.
Limits
The following example code uses the page_limit
parameter to specify a limit of 2
items on each page:
Iterative pagination
To retrieve the first page of results, invoke the list_pagination
method of the index
object. To retrieve subsequent pages of results, use the iterator protocol in Python or the async iterator protocol in JavaScript.
Retrieve the first page of results
The following example code retrieves the first page of results using the default value for the page
and page_limit
parameters by invoking the list_pagination
method of the index
object with no parameters:
The following example output was truncated for brevity:
Iterate over the results
The following example code iterates over results using the default value for the page
and page_limit
parameters:
Limits
The following example code iterates over results and specifies a limit of 5
items on each page: