Detect vector outliers
detect_vector_outliersDetect anomalous pgvector rows by clustering embeddings and flagging those with extreme distances to their cluster centroid.
Instructions
Flag pgvector rows whose embedding sits far from any cluster centroid. Samples up to sample_size (default 5000) non-NULL rows of schema.table.embedding_column, clusters them with k-means (same engine as cluster_vectors), then per cluster computes a z-score on the distance from each row to its centroid and flags rows whose z-score exceeds zscore_threshold (default 3.0). Per-cluster scoring catches rows that are weird-for-their-group rather than weird-overall, which is usually what 'find outliers' should mean. Returns outliers sorted by z-score descending (capped at max_results), total_outliers (the unclipped count), and cluster_stats (per-cluster mean / std of within-cluster distances). When id_column is set each outlier carries that column's value; otherwise the row's positional sample index. k >= 2 and there must be at least 2k parseable rows. Reports available=false if pgvector is not installed.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| k | No | ||
| seed | No | ||
| table | Yes | ||
| metric | No | l2 | |
| 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. | |
| id_column | No | ||
| max_results | No | ||
| sample_size | No | ||
| max_iterations | No | ||
| embedding_column | Yes | ||
| zscore_threshold | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| k | Yes | ||
| metric | Yes | ||
| outliers | Yes | ||
| available | Yes | ||
| dimension | Yes | ||
| sampled_rows | Yes | ||
| cluster_stats | Yes | ||
| total_outliers | Yes | ||
| zscore_threshold | Yes |