surfacerankingrank_semantic
Rankingaggregate · returns varchar

RANK_SEMANTIC

Rank a group of items by a subjective multi-factor criterion

Per-group — reads the whole group in one call.

rankingllmtext

Syntax

RANK_SEMANTIC({{ values }}, '{{ criteria }}')
{{ values }} RANKED BY '{{ criteria }}'

Arguments

nametypedescription
valuesVARCHARValues to rank
criteriaVARCHARRanking criteria: 'by quality', 'by relevance to X', 'by completeness'

About

Rank a group of items by a subjective or multi-factor quality that doesn't fit a single column. Use it when you can describe what "best" means in plain English but can't express it as a simple ORDER BY. Good for questions like "which customer feedback is most actionable?", "which product descriptions are most compelling?", or "rank these answers by completeness." The ranking reads all the items in the group together and compares them against each other, so position #1 is genuinely the strongest relative to everything else in the group — not just the item that scored highest in isolation. Common criteria phrasings: `by quality`, `by relevance to <topic>`, `by completeness`, `by clarity`, `by actionability`, `by specificity`. Returns a JSON object containing the ranked list (with per-item scores and short justifications), the best and worst items, and a summary of how spread-out the quality was. For very large groups (hundreds of items), pre-filter with a scalar score before calling this.

Examples

Ranks answers by quality

WITH
  test_data AS (
    SELECT
      *
    FROM
      (
        VALUES
          ('Brief but vague answer'),
          (
            'Comprehensive detailed response with examples and citations'
          ),
          ('OK response')
      ) AS t (answer)
  )
SELECT
  RANK_SEMANTIC (answer, 'by quality and completeness')
FROM
  test_data

Nearby rabbit holes

same domain
Climb back to The Looking Glass