jevrecipes

Recipe catalog / rerank

Rerank evidence

rerank is a Jev recipe from the jev-recipes TypeScript package. Select candidate passages by relevance to a query. Use it when you have retrieved passages and want to find the most useful evidence for a question.

Last updated .

Explore this recipe interactively · Source and implementation guide · Markdown version

How do I use rerank in TypeScript?

Install with npm install jev-recipes. Requires Node.js 22.9 or newer and ES modules. Set TYPESAFE_API_KEY in your server environment for live calls, which send input to TypeSafe and use API quota. See the installation guide.

import { rerank } from 'jev-recipes/rerank';

const result = await rerank({
  "query": "How do I reset my password?",
  "items": [
    {
      "id": "billing",
      "text": "Invoices are available on the Billing page."
    },
    {
      "id": "reset",
      "text": "Select Forgot password on the sign-in page. We will email you a reset link."
    },
    {
      "id": "security",
      "text": "Choose a strong password and enable two-factor authentication."
    }
  ],
  "topK": 2,
  "minRelevance": 0.5
});
console.log(result);

What input does rerank take?

FieldTypeNeeded
querystringRequired
itemsarrayRequired
topKintegerOptional
minRelevancenumberOptional
Full input and result schemas
{
  "input": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "query": {
        "type": "string"
      },
      "items": {
        "minItems": 1,
        "maxItems": 100,
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "text": {
              "type": "string"
            }
          },
          "required": [
            "id",
            "text"
          ]
        }
      },
      "topK": {
        "type": "integer",
        "minimum": 1,
        "maximum": 100
      },
      "minRelevance": {
        "type": "number",
        "minimum": 0,
        "maximum": 1
      }
    },
    "required": [
      "query",
      "items"
    ]
  },
  "result": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "model": {
        "type": "string"
      },
      "usage": {
        "type": "object",
        "properties": {
          "input_tokens": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "output_tokens": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          }
        },
        "required": [
          "input_tokens",
          "output_tokens"
        ],
        "additionalProperties": false
      },
      "status": {
        "type": "string",
        "enum": [
          "ready",
          "review"
        ]
      },
      "items": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "text": {
              "type": "string"
            },
            "relevance": {
              "type": "number",
              "minimum": 0,
              "maximum": 1
            }
          },
          "required": [
            "id",
            "text",
            "relevance"
          ],
          "additionalProperties": false
        }
      },
      "evaluated": {
        "type": "integer",
        "minimum": 0,
        "maximum": 9007199254740991
      }
    },
    "required": [
      "model",
      "usage",
      "status",
      "items",
      "evaluated"
    ],
    "additionalProperties": false
  }
}

What does a rerank result look like?

This hand-authored response demonstrates the contract. It is not a model accuracy measurement. Run it without an API key: npx jev-recipes demo rerank.

{
  "model": "demo-fixture",
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0
  },
  "status": "ready",
  "items": [
    {
      "id": "reset",
      "text": "Select Forgot password on the sign-in page. We will email you a reset link.",
      "relevance": 0.97
    }
  ],
  "evaluated": 3
}

Input

See shared options and behavior for client configuration, validation, and errors. Types are inferred from this folder's Zod 4 schemas.

Result

items contains passages at or above minRelevance, ordered from highest relevance to lowest and limited to topK. Each item keeps its ID and text and adds relevance. Equal values preserve input order. The input array is not changed.

status is ready when at least one passage qualifies, otherwise review. evaluated reports the number of supplied items. Relevance comes from independent yes/no questions, so values do not sum to 1 and have no separate confidence field.

The result includes model and token usage. Inspect the outcome as well as its review status.

Reuse and calls

Uses shared input preparation, instruction handling, the SDK client, and yes/no answer parsing. This folder owns the relevance question, filtering, and ordering. All item questions are sent in one request. A live invocation makes one logical Jev request; SDK retries can add transport attempts.

Limits

Relevance does not establish that a passage is true or sufficient to answer the entire query. Use answerability to assess the selected evidence. This recipe does not retrieve documents or generate an answer.

Example input

demo.json contains editable input and a hand-authored response. After installing jev-recipes, npx jev-recipes demo rerank shows an offline illustration, not an accuracy measurement. Use npx jev-recipes describe rerank to inspect the input and result schemas.

How accurate is rerank?

Current measurement; labels unspecified

jev-1.13.0 / 2026-10-04 / 57 development cases

Scoring revision 2.

100%All-case accuracy
0Sent for review
0Failed calls / cases

57 ready decisions, with 100% accuracy among those decisions.

95% case-level interval: 94% to 100%. Related synthetic cases are correlated.

This measures the recorded dataset, not general readiness. Label sources: unspecified: Not recorded by the dataset author.

Use the evaluation guide to measure this decision on your own labeled cases.

What are the limits of rerank?