Skip to main content

Squillify development is paused indefinitely. Read why, and discover what this experiment achieved. Read the story

MicroSkills Reference

Max Marginal Relevance

knowledge.max_marginal_relevance

ProductionBounded custom (Class B)Deterministicstrictmoderatev1.0.0
No network

Overview

You send candidates with relevance scores and either a symmetric similarities matrix or vectors (cosine). lambda defaults to 0.5 and limit defaults to 10 (at most 200). The first pick is the highest relevance; later picks maximise lambda * relevance minus (1-lambda) times the maximum similarity to the selected set. Ties break on lexical id. Zero vectors and asymmetric matrices are refused. This does not embed text or learn lambda.

A second hit that is almost the first hit wastes the context window.

Reliability

Zero vectors and asymmetric matrices are refused. Ties break on lexical id. MMR_CANDIDATES_INVALID — trigger: missing relevance or a duplicate id; retryable: no; next: send unique scored candidates. MMR_SIMILARITY_INVALID — trigger: both/neither similarity sources, or an asymmetric matrix; retryable: no; next: send exactly one source. MMR_VECTOR_INVALID — trigger: mixed vector presence, zero vector, or dimension mismatch; retryable: no; next: send consistent non-zero vectors. MMR_PARAMETER_INVALID — trigger: lambda outside [0, 1]; retryable: no; next: send lambda in range. MMR_LIMIT_EXCEEDED — trigger: more than 2000 candidates, 2048 dimensions or limit 201; retryable: no; next: split the set.

Context footprint

Selected ids and scores only; vectors are not returned. A successful call costs 2 execution credits.

When to use it

When candidates already have relevance scores and pairwise similarity or vectors.

When embeddings still need generating, or when an ANN index should search.

Powered by Squillify's own Carbonell/Goldstein MMR arithmetic. No embedding model is involved.

Scope

Note
Selects a diverse subset with max marginal relevance from caller relevance and similarity.

Non-goals

  • Does not generate embeddings
  • Does not learn lambda
  • Does not retrieve documents

Properties

IdempotentRetry safeStreaming supportedFile input supportedRequires external service

Capabilities

analysissearch

Cost & billing

Flat rate per invocation

MetercallsBillable onsuccessCost per call2 credits

File handling

Accepts file_refProduces file_refMax input2 MB

How we handle your data

Sensitive processing
What this means

This skill is designed to detect, mask, redact, validate, or otherwise process sensitive data.

Squillify guarantees
  • Runs inside Squillify
  • This skill runs inside Squillify.
  • Payloads are not sent to an external service by this skill.
  • Squillify does not permanently store submitted payloads.
  • Telemetry records metadata only, not submitted content.
  • Submitted payloads are not used for training.
  • Submitted payloads are not reviewed by humans.
  • Targets sensitive data
  • The response does not contain submitted content.
Your responsibility

Squillify does not determine whether submitted content is sensitive. Your application is responsible for deciding what data it is allowed to submit. Your application is responsible for securing the response.

Read the Microskill Data Handling Policy

Input schema

FieldTypeRequiredDescription
candidatesarrayYesFrom 1 through 2001 closed candidates; runtime accepts at most 2000.
similaritiesarrayNoOptional n by n symmetric matrix; omit it when every candidate carries a vector.
lambdanumberNoRelevance versus diversity trade-off from 0 through 1; omit it for 0.5.
limitintegerNoHow many candidates to keep, from 1 through 201; omit it for 10.

Output schema

FieldTypeRequiredDescription
selectedarrayYesSelected candidates in pick order, 1 through 200 closed objects.
lambdanumberYesRelevance versus diversity lambda that was actually applied.
limitintegerYesSelected-set size that was actually applied after clamping to the candidate count.
candidateCountintegerYesHow many candidates were considered.
truncatedbooleanYesTrue when more candidates remained than limit.
similaritystringYesCOSINE when vectors were used, otherwise SUPPLIED_MATRIX.
formulaVersionstringYesPinned MMR formula identifier.

API contract

POST /v1/execute
curl
curl -sS -X POST "$BASE/v1/execute" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -d '{"skillKey":"knowledge.max_marginal_relevance","input":{"candidates":[{"id":"a","relevance":1.0},{"id":"b","relevance":0.9}],"similarities":[[1,0.2],[0.2,1]],"limit":1}}'
Integrations
TypeScript SDK
import { Squillify } from "@squillify/sdk";

const sq = new Squillify({ apiKey: process.env.SQUILLIFY_API_KEY });

const { output } = await sq.execute("knowledge.max_marginal_relevance", {"limit":2,"candidates":[{"id":"a","relevance":1},{"id":"b","relevance":0.9},{"id":"c","relevance":0.8}],"similarities":[[1,0.99,0.1],[0.99,1,0.1],[0.1,0.1,1]]});

Errors

CodeHTTPRetryableDescription
VALIDATION_ERROR400NoThe request payload failed schema validation.
UNAUTHORIZED401NoMissing or invalid API key.
SKILL_NOT_ACCESSIBLE403NoThe API key is not granted access to this skill.
SKILL_NOT_AVAILABLE_FOR_PLAN403NoThis skill is not included in your current plan.
PLAN_ELIGIBILITY_UNAVAILABLE503YesPlan eligibility could not be decided. Retry after backoff.
SKILL_NOT_FOUND404NoThe requested skill or version does not exist.
TENANT_RATE_LIMITED429YesRequest rate limit exceeded. Retry after backoff.
QUOTA_EXCEEDED429YesPlan quota exhausted. Retryable once the quota period resets.
EXECUTION_TIMEOUT504YesExecution exceeded the allowed time budget.
MMR_CANDIDATES_INVALID400NoThe request payload failed this skill's input validation.
MMR_SIMILARITY_INVALID400NoThe request payload failed this skill's input validation.
MMR_VECTOR_INVALID400NoThe request payload failed this skill's input validation.
MMR_PARAMETER_INVALID400NoThe request payload failed this skill's input validation.
MMR_LIMIT_EXCEEDED429NoA size, quota, rate, or time limit was exceeded.

Other limits

LimitValue
Recommended inline bytes32 KiB

Limitations

  • Does not generate embeddings
  • Does not learn lambda
  • Does not retrieve documents
  • Embedding the documents
  • Approximate nearest-neighbour search

How to call

POST /v1/execute (requires authentication)

Request bodyjson
{
  "skillKey": "knowledge.max_marginal_relevance",
  "input": {
    "limit": 2,
    "candidates": [
      {
        "id": "a",
        "relevance": 1
      },
      {
        "id": "b",
        "relevance": 0.9
      },
      {
        "id": "c",
        "relevance": 0.8
      }
    ],
    "similarities": [
      [
        1,
        0.99,
        0.1
      ],
      [
        0.99,
        1,
        0.1
      ],
      [
        0.1,
        0.1,
        1
      ]
    ]
  }
}

Examples

A near-duplicate of the top hit is skipped

Inputjson
{
  "limit": 2,
  "candidates": [
    {
      "id": "a",
      "relevance": 1
    },
    {
      "id": "b",
      "relevance": 0.9
    },
    {
      "id": "c",
      "relevance": 0.8
    }
  ],
  "similarities": [
    [
      1,
      0.99,
      0.1
    ],
    [
      0.99,
      1,
      0.1
    ],
    [
      0.1,
      0.1,
      1
    ]
  ]
}
Expected outputjson
{
  "selected": [
    {
      "rank": 1,
      "id": "a",
      "relevance": 1,
      "redundancy": 0,
      "mmr": 0.5
    },
    {
      "rank": 2,
      "id": "c",
      "relevance": 0.8,
      "redundancy": 0.1,
      "mmr": 0.35
    }
  ],
  "similarity": "SUPPLIED_MATRIX",
  "truncated": true,
  "candidateCount": 3,
  "lambda": 0.5,
  "limit": 2,
  "formulaVersion": "knowledge.max_marginal_relevance.v1"
}
Tip
a is picked first; c outranks the near-duplicate b.

lambda 1 keeps only the highest relevance

Inputjson
{
  "limit": 1,
  "candidates": [
    {
      "relevance": 0.2,
      "id": "low",
      "vector": [
        1,
        0
      ]
    },
    {
      "relevance": 0.9,
      "id": "high",
      "vector": [
        0,
        1
      ]
    }
  ],
  "lambda": 1
}
Expected outputjson
{
  "selected": [
    {
      "rank": 1,
      "id": "high",
      "relevance": 0.9,
      "redundancy": 0,
      "mmr": 0.9
    }
  ],
  "similarity": "COSINE",
  "truncated": true,
  "candidateCount": 2,
  "lambda": 1,
  "limit": 1,
  "formulaVersion": "knowledge.max_marginal_relevance.v1"
}
Tip
high is the only selected id when lambda is 1 and limit is 1.
  • Drop a near-duplicate after the top hit
  • Keep only relevance when lambda is 1

Avoid for

  • Embedding the documents
  • Approximate nearest-neighbour search

Composable with

Safety & privacy

  • Runs without calling any external service.
  • Your payloads are never stored permanently.
  • Telemetry captures metadata only — never your payload contents.
  • We never train models on your payloads.
  • No human reviews your payloads.

Tags

retrievaltextrankingsearch