Analyze distance metric
analyze_distance_metricRecommends the right pgvector distance metric (cosine, l2, or inner_product) for a table column by sampling embeddings and analyzing their magnitude distribution, returning the metric plus rationale and stats.
Instructions
Recommend a pgvector distance metric (cosine | l2 | inner_product) from the embedding-magnitude distribution. Samples up to sample_size non-NULL rows of schema.table.column, computes each embedding's L2 norm, and applies a small heuristic: pre-normalised (CV < 5% and mean ≈ 1.0) → inner_product; nearly-constant magnitude but not unit-norm → cosine (same ranking as L2, safer default); variable magnitude → cosine (normalises out heterogeneous sources). Returns the metric + a rationale + the underlying distribution stats. Reports available=false if the pgvector extension is not installed.
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>",
"column": "<column>"
},
"name": "analyze_distance_metric"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | ||
| column | Yes | ||
| 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. | |
| sample_size | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| available | Yes | ||
| rationale | Yes | ||
| magnitude_cv | Yes | ||
| sampled_rows | Yes | ||
| magnitude_std | Yes | ||
| mean_magnitude | Yes | ||
| pre_normalised | Yes | ||
| recommended_metric | Yes |