Analyze distance metric
analyze_distance_metricAnalyzes embedding magnitude distribution from sample rows to recommend the optimal pgvector distance metric (cosine, L2, or inner_product) for vector columns.
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.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | ||
| column | Yes | ||
| schema | Yes | ||
| database | No | Optional: target a configured secondary (read-only) database by name; omit for the primary. Call list_databases to see the configured ids. | |
| 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 |