Cluster vectors
cluster_vectorsRun k-means clustering on a pgvector embedding column to group similar vectors, returning cluster centroids and per-row assignments with distances for analysis.
Instructions
k-means cluster a pgvector column. Samples up to sample_size (default 5000) non-NULL rows of schema.table.embedding_column, runs Lloyd's algorithm with k-means++ seeding (seed for determinism), and returns centroids (one per cluster, with size) + assignments (per-row cluster index + distance). When id_column is set each assignment carries that column's value; otherwise the row's positional sample index. metric='l2' (default — squared Euclidean) or 'cosine' (vectors normalised; centroids re-normalised every iteration). k >= 2 and there must be at least 2k parseable rows. Reports available=false if pgvector is not installed.
Example: cluster_vectors(schema='public', table='docs', embedding_column='embedding', k=8, metric='cosine')
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"schema": "<schema>",
"table": "<table>",
"embedding_column": "<embedding_column>",
"k": "<k>"
},
"name": "cluster_vectors"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| k | Yes | ||
| seed | No | ||
| table | Yes | ||
| metric | No | l2 | |
| schema | Yes | ||
| database | No | Optional: a database id from list_databases, to target a configured secondary (read-only) database; omit for the primary. Database names that are not configured ids are rejected. | |
| id_column | No | ||
| sample_size | No | ||
| max_iterations | No | ||
| embedding_column | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| metric | Yes | ||
| inertia | Yes | ||
| available | Yes | ||
| centroids | Yes | ||
| converged | Yes | ||
| dimension | Yes | ||
| iterations | Yes | ||
| assignments | Yes | ||
| sampled_rows | Yes |