RerankerFactory

org.llm4s.reranker.RerankerFactory

Factory for creating Reranker instances.

Supports multiple backends:

  • Cohere: Cloud-based cross-encoder reranking API
  • LLM: Use existing LLMClient for reranking with structured prompts
  • None: Passthrough that preserves original order

Usage:

// Cohere reranker from explicit config
val reranker = RerankerFactory.cohere(config)

// LLM-based reranker
val llmReranker = RerankerFactory.llm(llmClient)

// From provided config
val reranker = RerankerFactory.fromConfig(Some(config))

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

object Backend

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Backend.type
sealed trait Backend

Reranker backend type

Reranker backend type

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Cohere
object LLM
object None

Value members

Concrete methods

Create a Cohere reranker from config.

Create a Cohere reranker from config.

Value parameters

config

Provider configuration

Attributes

Returns

Cohere reranker

def cohere(apiKey: String, model: String, baseUrl: String): Reranker

Create a Cohere reranker from individual parameters.

Create a Cohere reranker from individual parameters.

Value parameters

apiKey

Cohere API key

baseUrl

API base URL (default: https://api.cohere.ai)

model

Reranking model (default: rerank-english-v3.0)

Attributes

Returns

Cohere reranker

def fromConfig(config: Option[RerankProviderConfig]): Result[Option[Reranker]]

Create a reranker from an optional typed configuration.

Create a reranker from an optional typed configuration.

Value parameters

config

Optional provider configuration

Attributes

Returns

Optional reranker (None if disabled)

def llm(client: LLMClient, batchSize: Int, systemPrompt: Option[String]): Reranker

Create an LLM-based reranker.

Create an LLM-based reranker.

Uses a language model to score document relevance on a 0-1 scale. This is more flexible than Cohere (works with any LLM) but slower and may be more expensive depending on the model.

Value parameters

batchSize

Number of documents to score per LLM call (default: 10)

client

LLM client for generating scores

systemPrompt

Custom system prompt (optional)

Attributes

Returns

LLM-based reranker

Concrete fields

No-op reranker that passes through results unchanged.

No-op reranker that passes through results unchanged.

Useful for testing or when reranking is disabled. Results preserve original order with monotonically decreasing scores.

Attributes