N/llm Module Adds Async llm.reRank.promise() for Document Re-Ranking
SuiteScript 2.1 gains llm.reRank.promise(), an asynchronous counterpart to llm.reRank() in the N/llm module, allowing server-side scripts to rank document strings by relevance to a prompt without blocking execution. Costs 50 governance units per call.
What changed
In 2026.2, the N/llm module now exposes llm.reRank.promise(options), the asynchronous (promise-based) variant of the existing synchronous llm.reRank(options) method. Both methods accept the same parameters and throw the same errors; the only difference is the return type.
- Method:
llm.reRank.promise(options) - Module:
N/llm - Returns: A
Promisethat resolves to allm.ReRankResponseobject - Governance: 50 units per invocation
- Script types: Server-side scripts only (Scheduled, Map/Reduce, Suitelet, User Event, RESTlet, etc.)
- Requires: SuiteScript 2.1 (not available in 2.0)
How it works
You pass an array of document strings and a prompt. The method returns ranked results via response.documentRanks, where each entry includes an index property that maps back to the original documents array. The topN parameter controls how many ranked results are returned.
const documents = ["Shipping information", "Return and refund information"];
const pendingResponse = llm.reRank.promise({
documents: documents,
prompt: "How do I request a refund?",
topN: 2
});
pendingResponse.then((response) => {
const topDocument = documents[response.documentRanks[0].index];
// Work with the ranked document
});Why it matters
The promise-based variant lets you fire off a re-ranking call and continue other processing while waiting for the result, which is particularly useful in Map/Reduce scripts or Suitelets that need to orchestrate multiple LLM calls without burning wall-clock time sequentially. Note that governance is still consumed at invocation time, so parallelizing multiple .promise() calls will still cost 50 units each.
What to do
- SuiteScript 2.1 only — confirm your script files use the
@NScriptTypeJSDoc tag and the 2.1 runtime. This method is not available in SuiteScript 2.0. - Governance budgeting — at 50 units per call, factor this into your script's governance budget. In a Map/Reduce context, each
maporreduceentry invokingllm.reRank.promise()costs 50 units toward that phase's limit. - Swap synchronous calls if appropriate — if you already use
llm.reRank()and would benefit from non-blocking execution (e.g., issuing multiple re-rank calls in sequence), replace withllm.reRank.promise()and handle results via.then()orawait. - Error handling — the promise rejects with the same errors as the synchronous version. Attach a
.catch()handler or usetry/catchwithawaitto handle failures gracefully. - Review N/llm module script samples — Oracle references complete examples in the N/llm Module Script Samples help topic for end-to-end patterns.
Source: Oracle NetSuite Release Notes