Knowledge store items

Use these methods to add assets to a knowledge store as items, and to organize those items into named collections.

Knowledge store items

The KnowledgeStoreItemsClient class provides methods to add and manage the items in a knowledge store.

Create a knowledge store item

Description: This method adds an asset to a knowledge store for processing. The operation is asynchronous. The item is created immediately with the queued status and processed in the background.

The asset must not exceed 5 GB.

Function signature and example:

1def create(
2 self,
3 knowledge_store_id: str,
4 *,
5 asset_id: str,
6 asset_type: typing.Optional[KnowledgeStoreItemAssetType] = OMIT,
7 metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
8 request_options: typing.Optional[RequestOptions] = None,
9) -> KnowledgeStoreItem:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
asset_idstrYesThe unique identifier of the asset to add to the knowledge store.
asset_typetyping.
Optional
[KnowledgeStore
ItemAssetType]
NoThe type of item to create. Values: video, image.
metadatatyping.
Optional
[typing.Dict
[str, str]]
NoCustom metadata for the item. Both keys and values must be strings.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a KnowledgeStoreItem object. The KnowledgeStoreItem class contains the following properties:

NameTypeDescription
idOptional[str]The unique identifier of the knowledge store item.
asset_typeKnowledgeStore
ItemAssetType
The type of item. Values: video, image.
asset_idOptional[str]The unique identifier of the source asset.
statusOptional
[KnowledgeStore
ItemStatus]
The processing status of the item. Values: queued, pending, processing, ready, failed. For the meaning of each value, see the Item statuses section on The knowledge store item object page.
system_metadataOptional
[KnowledgeStore
ItemSystemMetadata]
System-generated media metadata for the source asset. Its asset_type field always matches the item’s top-level asset_type field.
metadataOptional
[typing.Dict
[str, str]]
Custom metadata for the item.
created_atOptional
[datetime]
The date and time when the item was created, in the RFC 3339 format.
updated_atOptional
[datetime]
The date and time when the item was last updated, in the RFC 3339 format.

API Reference

Create a knowledge store item.

Add assets to a knowledge store.

List knowledge store items

Description: This method returns a list of items in the specified knowledge store.

Function signature and example:

1def list(
2 self,
3 knowledge_store_id: str,
4 *,
5 page: typing.Optional[int] = None,
6 page_limit: typing.Optional[int] = None,
7 sort_by: typing.Optional[KnowledgeStoreItemsListRequestSortBy] = None,
8 sort_option: typing.Optional[str] = None,
9 status: typing.Optional[
10 typing.Union[
11 KnowledgeStoreItemsListRequestStatusItem,
12 typing.Sequence[KnowledgeStoreItemsListRequestStatusItem],
13 ]
14 ] = None,
15 request_options: typing.Optional[RequestOptions] = None,
16) -> SyncPager[KnowledgeStoreItem]:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
pagetyping.
Optional[int]
NoA number that identifies the page to retrieve. Default: 1.
page_limittyping.
Optional[int]
NoThe number of items to return on each page. Default: 10. Max: 50.
sort_bytyping.
Optional
[KnowledgeStore
ItemsListRequestSortBy]
NoThe field to sort on. The following options are available:
- created_at: Sorts by the time, in the RFC 3339 format (“YYYY-MM-DDTHH:mm:ssZ”), when the item was created.
- updated_at: Sorts by the time, in the RFC 3339 format (“YYYY-MM-DDTHH:mm:ssZ”), when the item was last updated. Default: created_at.
sort_optiontyping.
Optional[str]
NoThe sorting direction. The following options are available:
- asc
- desc Default: desc.
statustyping.
Optional
[typing.Union
[..., Sequence]]
NoFilter by one or more item processing statuses. Values: queued, pending, processing, ready, failed. For the meaning of each value, see the Item statuses section on The knowledge store item object page. To filter by multiple statuses, pass a list.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a SyncPager[KnowledgeStoreItem] object that allows you to iterate through the paginated list of items. For the properties of each KnowledgeStoreItem object, see Create a knowledge store item.

API Reference

List knowledge store items.

Retrieve a knowledge store item

Description: This method retrieves the details of a specific knowledge store item.

Function signature and example:

1def retrieve(
2 self,
3 knowledge_store_id: str,
4 item_id: str,
5 *,
6 request_options: typing.Optional[RequestOptions] = None,
7) -> KnowledgeStoreItem:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
item_idstrYesThe unique identifier of the knowledge store item.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a KnowledgeStoreItem object. For its properties, see Create a knowledge store item.

API Reference

Retrieve a knowledge store item.

Delete a knowledge store item

Description: This method deletes the specified knowledge store item.

Function signature and example:

1def delete(
2 self,
3 knowledge_store_id: str,
4 item_id: str,
5 *,
6 request_options: typing.Optional[RequestOptions] = None,
7) -> None:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
item_idstrYesThe unique identifier of the knowledge store item.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

This method does not return a value.

API Reference

Delete a knowledge store item.

Item collections

The KnowledgeStoreItemCollectionsClient class provides methods to organize items into named collections that you can reference together.

Create an item collection

Description: This method creates an item collection in the specified knowledge store. An item collection is a named collection of items. Use item collections to organize and reference subsets of items together.

Function signature and example:

1def create(
2 self,
3 knowledge_store_id: str,
4 *,
5 name: str,
6 description: typing.Optional[str] = OMIT,
7 metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
8 request_options: typing.Optional[RequestOptions] = None,
9) -> KnowledgeStoreItemCollection:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
namestrYesThe name of the item collection. Must be unique within the knowledge store.
descriptiontyping.
Optional[str]
NoAn optional description of the item collection.
metadatatyping.
Optional
[typing.Dict
[str, str]]
NoCustom metadata for the item collection. Both keys and values must be strings.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a KnowledgeStoreItemCollection object. The KnowledgeStoreItemCollection class contains the following properties:

NameTypeDescription
idOptional[str]The unique identifier of the item collection.
knowledge_store_idOptional[str]The unique identifier of the knowledge store this collection belongs to.
nameOptional[str]The name of the item collection.
descriptionOptional[str]The description of the item collection.
metadataOptional
[typing.Dict
[str, str]]
Custom metadata for the item collection.
member_countOptional[int]The number of items in the collection.
created_atOptional
[datetime]
The date and time when the item collection was created, in the RFC 3339 format.
updated_atOptional
[datetime]
The date and time when the item collection was last updated, in the RFC 3339 format.

API Reference

Create an item collection.

List item collections

Description: This method returns a list of the item collections in the specified knowledge store.

Function signature and example:

1def list(
2 self,
3 knowledge_store_id: str,
4 *,
5 page: typing.Optional[int] = None,
6 page_limit: typing.Optional[int] = None,
7 sort_by: typing.Optional[KnowledgeStoreItemCollectionsListRequestSortBy] = None,
8 sort_option: typing.Optional[str] = None,
9 request_options: typing.Optional[RequestOptions] = None,
10) -> SyncPager[KnowledgeStoreItemCollection]:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
pagetyping.
Optional[int]
NoA number that identifies the page to retrieve. Default: 1.
page_limittyping.
Optional[int]
NoThe number of items to return on each page. Default: 10. Max: 50.
sort_bytyping.
Optional
[KnowledgeStore
ItemCollections
ListRequestSortBy]
NoThe field to sort on. The following options are available:
- created_at: Sorts by the time, in the RFC 3339 format (“YYYY-MM-DDTHH:mm:ssZ”), when the item collection was created.
- updated_at: Sorts by the time, in the RFC 3339 format (“YYYY-MM-DDTHH:mm:ssZ”), when the item collection was last updated.
- name: Sorts alphabetically by the name of the item collection. Default: created_at.
sort_optiontyping.
Optional[str]
NoThe sorting direction. The following options are available:
- asc
- desc Default: desc.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a SyncPager[KnowledgeStoreItemCollection] object that allows you to iterate through the paginated list of item collections. For the properties of each KnowledgeStoreItemCollection object, see Create an item collection.

API Reference

List item collections.

Retrieve an item collection

Description: This method retrieves the details of a specific item collection.

Function signature and example:

1def retrieve(
2 self,
3 knowledge_store_id: str,
4 collection_id: str,
5 *,
6 request_options: typing.Optional[RequestOptions] = None,
7) -> KnowledgeStoreItemCollection:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
collection_idstrYesThe unique identifier of the knowledge store item collection.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a KnowledgeStoreItemCollection object. For its properties, see Create an item collection.

API Reference

Retrieve an item collection.

Update an item collection

Description: This method updates the name, description, and metadata fields of the specified item collection.

Function signature and example:

1def update(
2 self,
3 knowledge_store_id: str,
4 collection_id: str,
5 *,
6 name: typing.Optional[str] = OMIT,
7 description: typing.Optional[str] = OMIT,
8 metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
9 request_options: typing.Optional[RequestOptions] = None,
10) -> KnowledgeStoreItemCollection:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
collection_idstrYesThe unique identifier of the knowledge store item collection.
nametyping.
Optional[str]
NoThe name of the item collection. Must be unique within the knowledge store.
descriptiontyping.
Optional[str]
NoAn optional description of the item collection.
metadatatyping.
Optional
[typing.Dict
[str, str]]
NoCustom metadata for the item collection. Both keys and values must be strings. To remove all metadata, set this field to an empty object ({}).
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a KnowledgeStoreItemCollection object. For its properties, see Create an item collection.

API Reference

Update an item collection.

Delete an item collection

Description: This method deletes the specified item collection. The items themselves remain in the knowledge store.

Function signature and example:

1def delete(
2 self,
3 knowledge_store_id: str,
4 collection_id: str,
5 *,
6 request_options: typing.Optional[RequestOptions] = None,
7) -> None:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
collection_idstrYesThe unique identifier of the knowledge store item collection.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

This method does not return a value.

API Reference

Delete an item collection.

List items in an item collection

Description: This method returns a list of the items in the specified item collection.

Function signature and example:

1def list_items(
2 self,
3 knowledge_store_id: str,
4 collection_id: str,
5 *,
6 page: typing.Optional[int] = None,
7 page_limit: typing.Optional[int] = None,
8 request_options: typing.Optional[RequestOptions] = None,
9) -> SyncPager[KnowledgeStoreItem]:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
collection_idstrYesThe unique identifier of the knowledge store item collection.
pagetyping.
Optional[int]
NoA number that identifies the page to retrieve. Default: 1.
page_limittyping.
Optional[int]
NoThe number of items to return on each page. Default: 10. Max: 50.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a SyncPager[KnowledgeStoreItem] object that allows you to iterate through the paginated list of items in the collection. For the properties of each KnowledgeStoreItem object, see Create a knowledge store item.

API Reference

List items in an item collection.

Add items to an item collection

Description: This method adds one or more items to the specified item collection. This operation is idempotent — items already in the collection are skipped. Every identifier must reference an existing item in the knowledge store.

Function signature and example:

1def add_items(
2 self,
3 knowledge_store_id: str,
4 collection_id: str,
5 *,
6 item_ids: typing.Sequence[str],
7 request_options: typing.Optional[RequestOptions] = None,
8) -> KnowledgeStoreItemCollection:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
collection_idstrYesThe unique identifier of the knowledge store item collection.
item_idstyping.
Sequence[str]
YesThe unique identifiers of the items to add to the collection. Include up to 500 identifiers per request.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

Returns a KnowledgeStoreItemCollection object. For its properties, see Create an item collection.

API Reference

Add items to an item collection.

Remove items from an item collection

Description: This method removes one or more items from the specified item collection. This operation is idempotent — identifiers that do not match a member of the collection are ignored. The items themselves remain in the knowledge store.

Function signature and example:

1def remove_items(
2 self,
3 knowledge_store_id: str,
4 collection_id: str,
5 *,
6 item_ids: typing.Sequence[str],
7 request_options: typing.Optional[RequestOptions] = None,
8) -> None:

Parameters

NameTypeRequiredDescription
knowledge_store_idstrYesThe unique identifier of the knowledge store.
collection_idstrYesThe unique identifier of the knowledge store item collection.
item_idstyping.
Sequence[str]
YesThe unique identifiers of the items to remove from the collection. Include up to 500 identifiers per request.
request_optionstyping.
Optional
[RequestOptions]
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

Return value

This method does not return a value.

API Reference

Remove items from an item collection.