Retrieve Collections
TaskingAI provides two main methods to retrieve collection information programmatically using the Client SDK:
get_collection
and list_collections
.
These methods are useful for accessing specific details about collections or obtaining a list of all available collections, respectively.
Get a Collection
The get_collection
method which accepts a collection_id to retrieve a specific collection.
import taskingai
collection = taskingai.retrieval.get_collection(
collection_id="YOUR_COLLECTION_ID"
)
List Collections
The list_collections
function retrieves a list of all collections in the project.
collections = taskingai.retrieval.list_collections(limit=20)
print(f"collections: {collections}")
You can also add pagination to list_collections
by specifying the cursor and limit parameters.
collections = taskingai.retrieval.list_collections(
order="asc",
limit=20,
after="YOUR_COLLECTION_ID"
)
Here are the required parameters for the pagination features:
- Order: Specify the order of the returned list as ascending (asc) or descending (desc), sorting on the
created_timestamp
field. It is set todesc
by default. - Limit: Set a maximum number of entries to return in a single request. The default value is 20.
- After/Before: Use cursors for pagination, retrieving collections in pages either after or before the specified cursor. Note that you cannot use both after and before simultaneously.