Classes

Client

The main TopK client for interacting with the TopK service. This client provides access to collections and allows you to perform various operations like creating collections, querying data, and managing documents. Constructors Constructor
new Client(config: ClientConfig): Client;
Creates a new TopK client with the provided configuration. Parameters
ParameterType
configClientConfig
Returns Client Methods
collection()
collection(name: string): CollectionClient;
Returns a client for interacting with a specific collection. Parameters
ParameterType
namestring
Returns CollectionClient
collections()
collections(): CollectionsClient;
Returns a client for managing collections. This method provides access to collection management operations like creating, listing, and deleting collections. Returns CollectionsClient

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()
count(options?: QueryOptions): Promise<number>;
Counts the number of documents in the collection. Parameters
ParameterType
options?QueryOptions
Returns Promise<number>
delete()
delete(ids: string[]): Promise<string>;
Deletes documents from the collection by their IDs. Parameters
ParameterType
idsstring[]
Returns Promise<string>
get()
get(
   ids: string[], 
   fields?: string[], 
options?: QueryOptions): Promise<Record<string, Record<string, any>>>;
Retrieves documents by their IDs. Parameters
ParameterType
idsstring[]
fields?string[]
options?QueryOptions
Returns Promise<Record<string, Record<string, any>>>
query()
query(query: Query, options?: QueryOptions): Promise<Record<string, any>[]>;
Executes a query against the collection. Parameters
ParameterType
queryQuery
options?QueryOptions
Returns Promise<Record<string, any>[]>
upsert()
upsert(docs: Record<string, any>[]): Promise<string>;
Inserts or updates documents in the collection. Parameters
ParameterType
docsRecord<string, any>[]
Returns Promise<string>

CollectionsClient

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

Interfaces

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
PropertyTypeDescription
base?numberBase multiplier for exponential backoff (default: 2.0)
initBackoff?numberInitial delay before the first retry in milliseconds
maxBackoff?numberMaximum delay between retries in milliseconds

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
PropertyTypeDescription
apiKeystringYour TopK API key for authentication
host?stringCustom host URL (optional, defaults to the standard TopK endpoint)
https?booleanWhether to use HTTPS (optional, defaults to true)
regionstringThe region where your data is stored (e.g., “us-east-1”, “eu-west-1”)
retryConfig?RetryConfigRetry configuration for failed requests (optional)

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
PropertyTypeDescription
namestringName of the collection
orgIdstringOrganization ID that owns the collection
projectIdstringProject ID that contains the collection
regionstringRegion where the collection is stored
schemaRecord<string, CollectionFieldSpec>Schema definition for the collection fields

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
PropertyTypeDescription
dataTypeDataTypeData type of the field
index?FieldIndexUnionIndex configuration for the field (optional)
requiredbooleanWhether the field is required (must be present in all documents)

QueryOptions

Options for query operations. These options control the behavior of query operations, including consistency guarantees and sequence number constraints. Properties
PropertyTypeDescription
consistency?ConsistencyLevelConsistency level for the query
lsn?stringLast sequence number to query at (for consistency)

RerankOptions

Options for rerank stages. This struct contains configuration options for reranking results, including the model, query, and fields to use. Properties
PropertyTypeDescription
fields?string[]Fields to include in reranking
model?stringThe reranking model to use
query?stringThe query text for reranking
topkMultiple?numberMultiple of top-k to consider for reranking

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
PropertyTypeDescription
backoff?BackoffConfigBackoff configuration for spacing out retry attempts
maxRetries?numberMaximum number of retries to attempt before giving up
timeout?numberTotal timeout for the entire retry chain in milliseconds

Namespaces

Type Aliases

ConsistencyLevel

type ConsistencyLevel = "indexed" | "strong";
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)