Pagination

Some SDK operations return results in pages. The SDK provides Paginator (sync) and AsyncPaginator (async) to iterate over those pages lazily, fetching the next page only when you ask for it.

Paginator and AsyncPaginator

Both classes share the same interface:

Member

Description

__iter__ / __aiter__

Iterate over individual items across all pages

.pages()

Iterate over Page objects rather than individual items

.to_list()

Fetch all items into a list in one call

.pagination_token

Token for the next page; None when all pages have been consumed

Iterating over items

from pinecone import Pinecone

pc = Pinecone()

for assistant in pc.assistants.list():
    print(assistant.name)

Iterating page by page

for page in pc.assistants.list().pages():
    print(f"Page has {len(page.items)} items")
    for assistant in page.items:
        print(assistant.name)
    if not page.has_more:
        break

Collecting all results at once

all_assistants = pc.assistants.list().to_list()

The Page Object

Each page yielded by .pages() has two attributes:

Attribute

Type

Description

items

list[T]

The items on this page

pagination_token

str | None

Opaque token to fetch the next page; None on the last page

has_more

bool

True if more pages are available

Limiting Results

Pass limit to cap the total number of items returned across all pages:

# Return at most 50 assistants total
for assistant in pc.assistants.list(limit=50):
    print(assistant.name)

Resuming Pagination

Save pagination_token to resume iteration later:

paginator = pc.assistants.list()
first_page = next(paginator.pages())

# Store the token
token = first_page.pagination_token

# Later: resume from where you left off
for assistant in pc.assistants.list(pagination_token=token):
    print(assistant.name)

Paginating Vector IDs

Index.list() automatically follows pagination and yields a ListResponse per page:

from pinecone import Pinecone

pc = Pinecone()
desc = pc.indexes.describe("product-search")
index = pc.index(host=desc.host)

for page in index.list(prefix="product#", limit=100):
    for item in page.vectors:
        print(item.id)

For manual control over individual pagination tokens, call Index.list_paginated() directly:

page = index.list_paginated(prefix="product#", limit=100)
for item in page.vectors:
    print(item.id)

while page.pagination is not None and page.pagination.next is not None:
    page = index.list_paginated(
        prefix="product#",
        limit=100,
        pagination_token=page.pagination.next,
    )
    for item in page.vectors:
        print(item.id)

Single-Page Responses

Not every list operation pages through multiple responses. pc.indexes.list() returns a Paginator (an AsyncPaginator on AsyncPinecone) for interface consistency, but the server returns all indexes in a single page, so iteration makes exactly one request:

for index in pc.indexes.list():
    print(index.name)