Max Marginal Relevance
knowledge.max_marginal_relevance
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
Non-goals
- Does not generate embeddings
- Does not learn lambda
- Does not retrieve documents
Properties
Capabilities
Cost & billing
Flat rate per invocation
File handling
How we handle your data
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.
Input schema
| Field | Type | Required | Description |
|---|---|---|---|
| candidates | array | Yes | From 1 through 2001 closed candidates; runtime accepts at most 2000. |
| similarities | array | No | Optional n by n symmetric matrix; omit it when every candidate carries a vector. |
| lambda | number | No | Relevance versus diversity trade-off from 0 through 1; omit it for 0.5. |
| limit | integer | No | How many candidates to keep, from 1 through 201; omit it for 10. |
Output schema
| Field | Type | Required | Description |
|---|---|---|---|
| selected | array | Yes | Selected candidates in pick order, 1 through 200 closed objects. |
| lambda | number | Yes | Relevance versus diversity lambda that was actually applied. |
| limit | integer | Yes | Selected-set size that was actually applied after clamping to the candidate count. |
| candidateCount | integer | Yes | How many candidates were considered. |
| truncated | boolean | Yes | True when more candidates remained than limit. |
| similarity | string | Yes | COSINE when vectors were used, otherwise SUPPLIED_MATRIX. |
| formulaVersion | string | Yes | Pinned MMR formula identifier. |
API contract
POST /v1/executecurl -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}}'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
| Code | HTTP | Retryable | Description |
|---|---|---|---|
| VALIDATION_ERROR | 400 | No | The request payload failed schema validation. |
| UNAUTHORIZED | 401 | No | Missing or invalid API key. |
| SKILL_NOT_ACCESSIBLE | 403 | No | The API key is not granted access to this skill. |
| SKILL_NOT_AVAILABLE_FOR_PLAN | 403 | No | This skill is not included in your current plan. |
| PLAN_ELIGIBILITY_UNAVAILABLE | 503 | Yes | Plan eligibility could not be decided. Retry after backoff. |
| SKILL_NOT_FOUND | 404 | No | The requested skill or version does not exist. |
| TENANT_RATE_LIMITED | 429 | Yes | Request rate limit exceeded. Retry after backoff. |
| QUOTA_EXCEEDED | 429 | Yes | Plan quota exhausted. Retryable once the quota period resets. |
| EXECUTION_TIMEOUT | 504 | Yes | Execution exceeded the allowed time budget. |
| MMR_CANDIDATES_INVALID | 400 | No | The request payload failed this skill's input validation. |
| MMR_SIMILARITY_INVALID | 400 | No | The request payload failed this skill's input validation. |
| MMR_VECTOR_INVALID | 400 | No | The request payload failed this skill's input validation. |
| MMR_PARAMETER_INVALID | 400 | No | The request payload failed this skill's input validation. |
| MMR_LIMIT_EXCEEDED | 429 | No | A size, quota, rate, or time limit was exceeded. |
Other limits
| Limit | Value |
|---|---|
| Recommended inline bytes | 32 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)
{
"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
{
"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
]
]
}{
"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"
}lambda 1 keeps only the highest relevance
{
"limit": 1,
"candidates": [
{
"relevance": 0.2,
"id": "low",
"vector": [
1,
0
]
},
{
"relevance": 0.9,
"id": "high",
"vector": [
0,
1
]
}
],
"lambda": 1
}{
"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"
}Recommended use cases
- Drop a near-duplicate after the top hit
- Keep only relevance when lambda is 1
Avoid for
- Embedding the documents
- Approximate nearest-neighbour search
Related skills
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.