Skip to main content
Glama
devopam

MCPg - Production-grade PostgreSQL MCP Server

Cluster vectors

cluster_vectors
Read-only

Perform k-means clustering on a pgvector column in PostgreSQL, returning centroids and per-row assignments. Supports L2 or cosine distance, optional id column, and configurable sample size.

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')

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kYes
seedNo
tableYes
metricNol2
schemaYes
databaseNoOptional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids.
id_columnNo
sample_sizeNo
max_iterationsNo
embedding_columnYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
metricYes
inertiaYes
availableYes
centroidsYes
convergedYes
dimensionYes
iterationsYes
assignmentsYes
sampled_rowsYes
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description discloses algorithm details (Lloyd's, k-means++ seeding), metric behavior (l2 vs cosine normalization), determinism via seed, sampling, and output structure (centroids with size, assignments with cluster index and distance). Annotations (readOnlyHint: true) are consistent with the read-only nature of clustering. No contradictions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise yet comprehensive, using a single paragraph with an illustrative example. Every sentence adds value: start with verb, then algorithm details, then parameter specifics, then a clear example. No redundant or vague statements.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 10 parameters, 4 required, and the presence of an output schema (which handles return values), the description covers all necessary aspects: purpose, conditions, algorithm details, parameter behavior. The example ties everything together. It is complete for an AI agent to understand and invoke the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is only 10% (only 'database' parameter has a description), but the description compensates fully by explaining the role and default of sample_size, seed, metric, id_column, k, and max_iterations. The example further clarifies parameter usage. This adds significant meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it performs k-means clustering on a pgvector column, specifying the algorithm, inputs, and outputs. It distinguishes itself from sibling tools by being a dedicated clustering function, which is unique among the listed tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit usage context: requires pgvector installed, k >= 2, at least 2k rows, and default sample size. It also mentions fallback behavior ('Reports available=false if pgvector is not installed'). Although no direct alternatives are mentioned, the tool's purpose is distinct, making usage clear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/devopam/MCPg'

If you have feedback or need assistance with the MCP directory API, please join our Discord server