Client
TheClient class is the main entry point for interacting with the TopK API. Use it to manage collections and perform data operations.
Constructor
Your TopK API key. Get one from the TopK Console.
The region where your data is stored. For available regions, see the regions documentation.
The TopK API host. Typically this should not be changed.
Whether to use HTTPS for connections.
Configuration for retry behavior. See RetryConfig below.
Methods
collection()
Get a client for managing data operations on a specific collection such as querying, upserting, and deleting documents.The name of the collection to interact with.
A client instance for the specified collection.
collections()
Get a client for managing collections (create, list, get, delete).A client instance for managing collections.
AsyncClient
Asynchronous client for interacting with the TopK API. All operations return awaitables.Constructor
Client.
Methods
collection()
Get an async client for a specific collection.The name of the collection to interact with.
An async client instance for the specified collection.
collections()
Get an async client for managing collections.An async client instance for managing collections.
CollectionClient
Synchronous client for collection operations like querying, upserting, and deleting documents.get()
Get documents by their IDs.List of document IDs to retrieve.
Optional list of field names to return. If not provided, all fields are returned.
Log Sequence Number for consistency. Wait for writes up to this LSN to be available.
Consistency level for the operation. Can be
ConsistencyLevel.Strong or ConsistencyLevel.Indexed.A dictionary mapping document IDs to their field values.
count()
Get the count of documents in the collection.Log Sequence Number for consistency.
Consistency level for the operation.
The number of documents in the collection.
query()
Execute a query against the collection.The query to execute. See the Query documentation for details.
Log Sequence Number for consistency.
Consistency level for the operation.
A list of documents matching the query.
upsert()
Insert or update documents in the collection. Each document must have an_id field.
List of documents to insert or update. Each document must contain an
_id field.The LSN (Log Sequence Number) at which the upsert was applied.
update()
Update documents in the collection. Existing documents will be merged with the provided fields. Missing documents will be ignored.List of documents to update. Each document must contain an
_id field.If true, the operation fails if any document IDs don’t exist.
The LSN at which the update was applied. If no updates were applied, this will be empty.
delete()
Delete documents by their IDs or using a filter expression.- By IDs
- By Filter
Either a list of document IDs to delete, or a filter expression.
The LSN at which the delete was applied.
AsyncCollectionClient
Asynchronous client for collection operations. All methods are identical toCollectionClient but return awaitables.
Collection
Represents a collection in the TopK system. Returned byCollectionsClient.get() and CollectionsClient.list().
The name of the collection.
The organization ID that owns the collection.
The project ID that owns the collection.
The region where the collection is stored.
The schema definition for the collection. See Schema documentation for details.
ConsistencyLevel
Enumeration of consistency levels for operations.Strong consistency ensures reads reflect all writes acknowledged before the read operation.
Indexed consistency ensures reads reflect all indexed writes.
RetryConfig
Configuration for retry behavior. By default, retries occur in two situations:- When the server requests the client to reduce its request rate, resulting in a
SlowDownError. - When using
query(..., lsn=N)to wait for writes to be available.
Maximum number of retries to attempt.
The total timeout for the retry chain in milliseconds. Default is 30,000 milliseconds (30 seconds).
The backoff configuration for the client. See BackoffConfig below.
BackoffConfig
Configuration for backoff behavior in retries.The base for the exponential backoff. Default is 2x backoff.
The initial backoff in milliseconds. Default is 100 milliseconds.
The maximum backoff in milliseconds. Default is 10,000 milliseconds (10 seconds).