Skip to content

@inferedge/moss-clustering v1.0.0-beta.3


@inferedge/moss-clustering / MossClusteringClient

Class: MossClusteringClient

Main client for interacting with the Moss Clustering API

Example

ts
1. Instantiate with your project ID and API key.
2. Call `generateClusters(5)` to create clusters.
3. Access results via `getClusters()`.

Constructors

Constructor

new MossClusteringClient(options): MossClusteringClient

Creates a new MossClusteringClient instance

Parameters

options

MossClusteringOptions

Configuration options

Returns

MossClusteringClient

Methods

getServiceHealth()

getServiceHealth(endpoint): Promise<HealthStatus>

Retrieves service health information.

Parameters

endpoint

Health endpoint to query (health, healthz, or readyz)

"health" | "healthz" | "readyz"

Returns

Promise<HealthStatus>

Health status payload


startClusterGeneration()

startClusterGeneration(k, options): Promise<GenerateClusterJobResponse>

Starts cluster generation job (async operation)

This method starts an async job to perform k-means++ clustering on indexes in the project. The operation runs in the background. Use the returned jobId to poll for status.

Parameters

k

number

Number of clusters to generate (must be > 0)

options

StartClusterOptions = {}

Optional settings such as a subset of index names to cluster

Returns

Promise<GenerateClusterJobResponse>

Job information with jobId to poll for status

Throws

ClusteringError If k is invalid or the API request fails

Example

typescript
const jobResponse = await clustering.startClusterGeneration(5);
console.log('Job started:', jobResponse.jobId);
// Pass StartClusterOptions.indexNames to limit specific indexes

getJobStatus()

getJobStatus(jobId): Promise<GetJobResponse>

Gets the status of a clustering job

Parameters

jobId

string

Job ID returned from startClusterGeneration

Returns

Promise<GetJobResponse>

Job status with progress and results (if completed)

Example

typescript
const jobStatus = await clustering.getJobStatus(jobId);
console.log('Status:', jobStatus.job.status);
console.log('Progress:', jobStatus.job.progress);
console.log('Phase:', jobStatus.job.currentPhase);

waitForJobCompletion()

waitForJobCompletion(jobId, pollInterval, maxWaitTime): Promise<ClusteringResult>

Waits for a job to complete by polling

This is a convenience method that polls getJobStatus until the job completes or fails.

Parameters

jobId

string

Job ID to wait for

pollInterval

number = 2000

Milliseconds between polls (default: 2000)

maxWaitTime

number = 300000

Maximum time to wait in milliseconds (default: 300000 = 5 minutes)

Returns

Promise<ClusteringResult>

Clustering result when job completes

Throws

ClusteringError If job fails or times out

Example

typescript
const jobResponse = await clustering.startClusterGeneration(5);
const result = await clustering.waitForJobCompletion(jobResponse.jobId, 2000, 600000);
console.log('Completed job with clusters:', result.clusters.length);

generateClusters()

generateClusters(k, optionsOrPollInterval?, legacyMaxWaitTime?): Promise<ClusteringResult>

Generates clusters and waits for completion (convenience method)

This method combines startClusterGeneration and waitForJobCompletion for a simpler API when you want to wait for the result.

Parameters

k

number

Number of clusters to generate (must be > 0)

optionsOrPollInterval?

Either an options object or the polling interval in milliseconds

number | GenerateClustersOptions

legacyMaxWaitTime?

number

Maximum wait time when using the legacy signature

Returns

Promise<ClusteringResult>

Clustering result with cluster information

Throws

ClusteringError If k is invalid, job fails, or times out

Example

typescript
// Simple usage - waits for completion
const result = await clustering.generateClusters(5);
console.log('Created clusters:', result.clusters.length);

Advanced usage: supply GenerateClustersOptions with indexNames, pollInterval, and maxWaitTime to process subsets or override polling behavior.


getClusters()

getClusters(): Promise<ClusterInfo[]>

Retrieves all clusters for the project

Returns current clustering state with index counts and assignments. Returns empty array if no clustering exists.

Returns

Promise<ClusterInfo[]>

Array of cluster information

Example

typescript
const clusters = await clustering.getClusters();
clusters.forEach(cluster =>
  console.log('Cluster label:', cluster.label, 'indexes:', cluster.indexCount)
);

getIndexCluster()

getIndexCluster(indexName): Promise<ClusterAssignment | null>

Gets the cluster assignment for a specific index

Parameters

indexName

string

Name of the index

Returns

Promise<ClusterAssignment | null>

Cluster assignment or null if not classified

Example

typescript
const assignment = await clustering.getIndexCluster('my-index');
console.log('Belongs to:', assignment?.label);

clusterIndexDocuments()

clusterIndexDocuments(indexName, k, options?): Promise<GenerateIndexDocumentClustersResponse>

Clusters documents stored within a specific index

Parameters

indexName

string

Name of the index whose documents should be clustered

k

number

Number of clusters to generate (must be > 0)

options?

DocumentClusteringOptions

Optional tuning parameters such as sampling strategy

Returns

Promise<GenerateIndexDocumentClustersResponse>

Document clustering payload including per-phase progress


getIndexDocumentClusters()

getIndexDocumentClusters(indexName): Promise<GetIndexDocumentClustersResponse | null>

Retrieves the most recently generated document clusters for an index

Returns null if document clustering has not been generated yet.

Parameters

indexName

string

Name of the index to query

Returns

Promise<GetIndexDocumentClustersResponse | null>

Document clustering snapshot or null when unavailable


hasActiveClustering()

hasActiveClustering(): Promise<boolean>

Checks if clustering exists for the project

Quick check to determine if generateClusters() has been called.

Returns

Promise<boolean>

True if clustering exists, false otherwise

Example

typescript
if (!(await clustering.hasActiveClustering())) {
  await clustering.generateClusters(5);
}

deleteClustering()

deleteClustering(): Promise<void>

Deletes all clustering data for the project

This removes all clusters and assignments. This action cannot be undone. You will need to call generateClusters() again to re-cluster.

Returns

Promise<void>

Example

typescript
await clustering.deleteClustering();
console.log('All clustering data deleted');