llm.reRank(options)

Note:

The content in this help topic pertains to SuiteScript 2.1.

Method Description

Ranks the document strings you provide by their relevance to a prompt. The results are ordered by relevance, with the most relevant document first.

Each result includes the document's index in the original options.documents array and a relevance score. Refer to the input array to identify the ranked documents. The response doesn't contain document text or a generated answer.

By default, the method returns one result. Use options.topN to return more results.

Returns

llm.ReRankResponse

Supported Script Types

Server scripts

For more information, see SuiteScript 2.1 Script Types.

Governance

50

Module

N/llm Module

Since

2026.2

Parameters

Parameter

Type

Required / Optional

Description

Since

options.documents

string[]

required

The document strings to rank. Provide a minimum of 1 and a maximum of 1,000 strings. Refer to this array to identify documents by the indexes in the response.

2026.2

options.prompt

string

required

The text used to evaluate each document's relevance.

2026.2

options.maxTokensPerDocument

number

optional

The maximum number of tokens to use from each document. Longer documents are truncated to this limit. The value must be between 1 and 32,768, and the default value is 4,096.

2026.2

options.reRankModelFamily

string

optional

The rerank model family to use. Use a value from the llm.ReRankModelFamily enum. If omitted, llm.ReRankModelFamily.COHERE_RERANK is used.

2026.2

options.timeout

number

optional

The request timeout in milliseconds. The default value is 30,000 milliseconds.

2026.2

options.topN

number

optional

The number of ranked documents to return, from 1 through options.documents.length. The default is 1. Set it to the number of input documents to rank all of them.

2026.2

Errors

Error Code

Thrown If

CAN_RERANK_1_DOCUMENTS_AT_MAXIMUM

The options.documents array contains more than 1,000 strings.

INVALID_MODEL_FAMILY_VALUE

The options.reRankModelFamily value is not in the llm.ReRankModelFamily enum.

MAX_TOKENS_PER_DOCUMENT_CANNOT_EXCEED_1

The options.maxTokensPerDocument value exceeds 32,768.

MAX_TOKENS_PER_DOCUMENT_MUST_BE_POSITIVE

The options.maxTokensPerDocument value is less than 1.

MAXIMUM_PARALLEL_RE_RANK_REQUESTS_LIMIT_EXCEEDED

The maximum number of parallel rerank requests has been reached.

NO_DOCUMENTS_TO_RERANK

The options.documents array is empty.

TOP_N_CANNOT_EXCEED_NUMBER_OF_DOCUMENTS

The options.topN value exceeds the number of input documents.

TOP_N_MUST_BE_POSITIVE

The options.topN value is less than 1.

Syntax

Important:

The following code sample shows the syntax for this member. It isn't a functional example. For a complete script example, see N/llm Module Script Samples.

            // Add additional code
...

const documents = [
    "Standard delivery takes three to five business days.",
    "Contact support about damaged items to request a refund."
];
const response = llm.reRank({
    documents: documents,
    prompt: "How can I get a refund for a damaged item?",
    reRankModelFamily: llm.ReRankModelFamily.COHERE_RERANK,
    topN: documents.length
});
const rankedDocuments = response.documentRanks.map((rank) => ({
    document: documents[rank.index],
    relevance: rank.relevance
}));

...
// Add additional code 

          

Related Topics

General Notices