Skip to main content

Classes

AskStream

Iterator for ask responses. This type implements JavaScript’s async iterable protocol. It can be used with for await...of loops. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols Constructors Constructor
Returns AskStream Methods
[asyncIterator]()
Returns AsyncGenerator< | Answer | Progress, void, undefined>

Client

Client for interacting with the TopK API. For available regions see https://docs.topk.io/regions Constructors Constructor
Creates a new TopK client with the provided configuration. Parameters Returns Client Methods
ask()
Ask a question and get streaming responses as an async iterator. Parameters Returns AskStream
collection()
Returns a client for interacting with a specific collection. Optionally, pass partition name to scope data operations to that partition. Parameters Returns CollectionClient
collections()
Returns a client for managing collections. This method provides access to collection management operations like creating, listing, and deleting collections. Returns CollectionsClient
dataset()
Get a client for managing data operations on a specific dataset such as upserting files, managing metadata, and deleting files. Parameters Returns DatasetClient
datasets()
Get a client for managing datasets. Returns DatasetsClient
search()
Search for documents and get streaming responses as an async iterator. Parameters Returns SearchStream

CollectionClient

Internal Client for interacting with a specific collection. This client provides methods to perform operations on a specific collection, including querying, upserting, and deleting documents. Methods
count()
Counts the number of documents in the collection. Parameters Returns Promise<number>
delete()
Deletes documents from the collection by their IDs or using a filter expression. Example: Delete documents by their IDs:
Delete documents by a filter expression:
Parameters Returns Promise<string>
deletePartition()
Delete a partition and all documents within it. Parameters Returns Promise<void>
get()
Retrieves documents by their IDs. Parameters Returns Promise<Record<string, Record<string, any>>>
listPartitions()
List partitions in the collection as an async iterator. Parameters Returns PartitionListStream
query()
Executes a query against the collection. Parameters Returns Promise<Record<string, any>[]>
update()
Updates documents in the collection. Existing documents will be merged with the provided fields. Missing documents will be ignored. Parameters Returns Promise<string> The LSN at which the update was applied. If no updates were applied, this will be empty.
upsert()
Inserts or updates documents in the collection. Parameters Returns Promise<string>

CollectionsClient

Internal Client for managing collections. This client provides methods to create, list, get, and delete collections. Methods
create()
Creates a new collection with the specified schema. Parameters Returns Promise<Collection>
delete()
Deletes a collection and all its data.
This operation is irreversible and will permanently delete all data in the collection.
Parameters Returns Promise<void>
get()
Retrieves information about a specific collection. Parameters Returns Promise<Collection>
list()
Lists all collections in the current project. Returns Promise<Collection[]>

DatasetClient

Internal Client for dataset operations. Methods
checkHandle()
Return whether the handle has been processed. Parameters Returns Promise<boolean>
delete()
Delete a file from the dataset. Parameters Returns Promise<string>
getMetadata()
Get metadata for one or more documents. Parameters Returns Promise<Record<string, Record<string, any>>>
list()
List files in the dataset as an async iterator. Parameters Returns DatasetListStream
updateMetadata()
Update metadata for a file. Parameters Returns Promise<string>
upsertFile()
Upsert a file to the dataset. Parameters Returns Promise<string>
waitForHandle()
Poll until a handle has been processed or the timeout is reached. Throws if the handle is not processed within the configured timeout. Parameters Returns Promise<void>

DatasetListStream

Iterator for dataset list responses. This type implements JavaScript’s async iterable protocol. It can be used with for await...of loops. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols Constructors Constructor
Returns DatasetListStream Methods
[asyncIterator]()
Returns AsyncGenerator<ListEntry, void, undefined>
next()
Returns the next entry in the stream. Returns Promise<ListEntry>

DatasetsClient

Internal Client for managing datasets. Methods
create()
Create a new dataset. Parameters Returns Promise<Dataset>
delete()
Delete a dataset. Parameters Returns Promise<void>
get()
Get information about a specific dataset. Parameters Returns Promise<Dataset>
list()
List all datasets. Returns Promise<Dataset[]>
update()
Update dataset properties Parameters Returns Promise<Dataset>

PartitionListStream

Iterator for partition list responses. This type implements JavaScript’s async iterable protocol. It can be used with for await...of loops. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols Constructors Constructor
Returns PartitionListStream Methods
[asyncIterator]()
Returns AsyncGenerator<Partition, void, undefined>
next()
Returns the next partition in the stream. Returns Promise<Partition>

SearchStream

Iterator for search responses. This type implements JavaScript’s async iterable protocol. It can be used with for await...of loops. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols Constructors Constructor
Returns SearchStream Methods
[asyncIterator]()
Returns AsyncGenerator<SearchResult, void, undefined>

Interfaces

Answer

Represents a final answer in an ask response. Properties

BackoffConfig

Configuration for exponential backoff between retry attempts. This struct controls how the delay between retry attempts increases over time. All fields are optional and will use sensible defaults if not provided. Properties

Chunk

Text chunk content. Properties

ClientConfig

Configuration for the TopK client. This struct contains all the necessary configuration options to connect to the TopK API. The api_key and region are required, while other options have sensible defaults. Properties

Collection

Represents a collection in the TopK service. A collection is a container for documents with a defined schema. This struct contains metadata about the collection including its name, organization, project, schema, and region. Properties

CollectionFieldSpec

Represents a field specification within a collection schema. This struct defines the properties of a field in a collection, including its data type, whether it’s required, and any index configuration. Properties

Content

Content in a search result. One of chunk, page, or image. Properties

Dataset

Represents a dataset in the TopK service. Properties

Fact

Represents a fact in an ask response. Properties

Image

Image content. Properties

InputFile

Input for upserting a file to a dataset. Provide either a path to a file on disk, or inline data via data + fileName + mimeType. Properties

ListEntry

Entry in a dataset. Properties

Page

Page content with optional image. Properties

Partition

A partition within a collection. Properties

Progress

Represents a progress update in an ask response. Properties

QueryOptions

Options for query operations. These options control the behavior of query operations, including consistency guarantees and sequence number constraints. Properties

RetryConfig

Configuration for retry behavior when requests fail. This struct allows you to customize how the client handles retries for failed requests. All fields are optional and will use sensible defaults if not provided. Properties

SearchResult

Represents a search result in an ask response. Properties

UpdateDatasetParams

Properties

WaitConfig

Configuration for polling when waiting for a handle to be processed. Properties

Namespaces

Type Aliases

ConsistencyLevel

Consistency levels for query operations.
  • Indexed: Query returns results as soon as they are indexed (faster, eventual consistency)
  • Strong: Query waits for all replicas to be consistent (slower, strong consistency)

Mode

Mode for ask operations.

SchemaFieldSpec