ReqLLM.Rerank (ReqLLM v1.14.0)

View Source

Reranking functionality for ReqLLM.

This module provides document reranking with support for:

  • Single-query reranking against a document set
  • Automatic batching for large document collections
  • Provider-specific rerank options

Usage

{:ok, response} =
  ReqLLM.Rerank.rerank(
    "cohere:rerank-v3.5",
    query: "What is deep learning?",
    documents: ["Doc 1", "Doc 2", "Doc 3"],
    top_n: 2
  )

response.results
#=> [%{index: 1, relevance_score: 0.97, document: "Doc 2"}, ...]

Summary

Functions

Reranks documents against a query.

Same as rerank/2 but raises on error.

Returns the base reranking options schema.

Validates that a model supports reranking operations.

Functions

rerank(model_spec, opts \\ [])

@spec rerank(
  ReqLLM.model_input(),
  keyword()
) :: {:ok, ReqLLM.RerankResponse.t()} | {:error, term()}

Reranks documents against a query.

Returns a ReqLLM.RerankResponse with results ordered from highest relevance to lowest relevance.

rerank!(model_spec, opts \\ [])

Same as rerank/2 but raises on error.

schema()

@spec schema() :: NimbleOptions.t()

Returns the base reranking options schema.

validate_model(model_spec)

@spec validate_model(ReqLLM.model_input()) ::
  {:ok, LLMDB.Model.t()} | {:error, term()}

Validates that a model supports reranking operations.