Skip to main content
POST
/
db
/
cluster
JavaScript
const url = 'https://api.worqhat.com/db/cluster';
const options = {
  method: 'POST',
  headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
  body: '{"table":"products","num_clusters":5,"min_clusters":2,"max_clusters":10,"generate_labels":true,"environment":"production"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
{
  "success": true,
  "clusters": [
    {
      "id": 0,
      "label": "Cluster focused on: electronics, gadgets, technology",
      "size": 45,
      "sample_records": [
        {}
      ],
      "centroid": [
        0.123,
        -0.456,
        0.789,
        -0.321,
        0.654,
        0.987,
        -0.234,
        0.567,
        -0.89,
        0.123
      ]
    }
  ],
  "optimal_k": 5,
  "silhouette_score": 0.75,
  "iterations": 12,
  "executionTime": 2341
}

Authorizations

Authorization
string
header
required

API key authentication. Format - "Bearer YOUR_API_KEY"

Body

application/json
table
string
required

Table to cluster

Example:

"products"

num_clusters
number

Number of clusters (auto-detected if not provided)

Required range: 2 <= x <= 20
Example:

5

min_clusters
number
default:2

Minimum clusters for auto-detection

Required range: 2 <= x <= 10
max_clusters
number
default:10

Maximum clusters for auto-detection

Required range: 2 <= x <= 20
generate_labels
boolean
default:true

Whether to generate AI labels for clusters

environment
enum<string>

Environment to cluster (development, staging, production)

Available options:
development,
staging,
production
Example:

"production"

Response

Clustering completed successfully

success
boolean
Example:

true

clusters
object[]
optimal_k
number

Determined optimal cluster count

Example:

5

silhouette_score
number

Clustering quality metric (0-1)

Example:

0.75

iterations
number

Number of K-means iterations performed

Example:

12

executionTime
number

Clustering execution time in milliseconds

Example:

2341