Skip to content

Rerank

Source: src/AWS/Bedrock/Rerank.ts

Runtime binding for bedrock-agent-runtime:Rerank — re-order a list of candidate documents by semantic relevance to a query using a Bedrock reranker model (e.g. amazon.rerank-v1:0, cohere.rerank-v3-5:0).

Bind one or more reranker model references inside a function runtime. The binding grants the function bedrock:Rerank (which AWS authorizes only against *) plus bedrock:InvokeModel scoped to exactly the bound models.

// init
const rerank = yield* Bedrock.Rerank("amazon.rerank-v1:0");
// runtime
const result = yield* rerank({
queries: [{ type: "TEXT", textQuery: { text: "What is Alchemy?" } }],
sources: docs.map((text) => ({
type: "INLINE",
inlineDocumentSource: { type: "TEXT", textDocument: { text } },
})),
rerankingConfiguration: {
type: "BEDROCK_RERANKING_MODEL",
bedrockRerankingConfiguration: {
modelConfiguration: {
modelArn: `arn:aws:bedrock:us-west-2::foundation-model/amazon.rerank-v1:0`,
},
},
},
});
const best = result.results[0]; // { index, relevanceScore }