org.llm4s.reranker
Members list
Type members
Classlikes
Cohere Rerank API implementation.
Cohere Rerank API implementation.
Calls POST https://api.cohere.ai/v1/rerank with:
- model: reranking model name (e.g., "rerank-english-v3.0")
- query: search query
- documents: array of document strings
- top_n: number of results to return
- return_documents: whether to include document text
Attributes
- See also
- Companion
- object
- Supertypes
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
CohereReranker.type
LLM-based reranker using a language model to score documents.
LLM-based reranker using a language model to score documents.
Uses a structured prompt to ask the LLM to rate document relevance on a scale of 0 to 1. This is slower and more expensive than cross-encoder rerankers (like Cohere) but works with any LLM.
Usage:
val llmClient = /* build LLMClient with your ProviderConfig */
val reranker = LLMReranker(llmClient)
val request = RerankRequest(
query = "What is Scala?",
documents = Seq("Scala is a programming language", "Python is popular"),
topK = Some(5)
)
val response = reranker.rerank(request)
Value parameters
- batchSize
-
Number of documents to score per LLM call
- client
-
LLM client for generating scores
- systemPrompt
-
Custom system prompt (optional)
Attributes
- Companion
- object
- Supertypes
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
LLMReranker.type
Error from a reranking operation.
Error from a reranking operation.
Value parameters
- code
-
Error code (HTTP status or provider-specific)
- message
-
Human-readable error message
- provider
-
Provider name (cohere, llm, etc.)
Attributes
- Supertypes
-
trait LLMErrortrait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Configuration for reranker providers.
Configuration for reranker providers.
Value parameters
- apiKey
-
API key for authentication
- baseUrl
-
API endpoint
- model
-
Model name (e.g., "rerank-english-v3.0")
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Request to rerank documents against a query.
Request to rerank documents against a query.
Value parameters
- documents
-
The documents to rerank
- query
-
The query to rank documents against
- returnDocuments
-
Whether to return document content in results
- topK
-
Maximum results to return (None = all)
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Response from a reranking operation.
Response from a reranking operation.
Value parameters
- metadata
-
Provider-specific metadata (model, latency, etc.)
- results
-
Reranked results sorted by score (descending)
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Result of reranking a single document.
Result of reranking a single document.
Value parameters
- document
-
The original document content
- index
-
Original index in the input documents
- score
-
Relevance score from reranker (higher is better, typically 0-1)
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Cross-encoder reranker interface.
Cross-encoder reranker interface.
Rerankers improve search quality by re-scoring candidate documents using a cross-encoder model that sees both query and document together. This produces more accurate relevance scores than bi-encoder (embedding) similarity alone.
Usage:
val reranker = RerankerFactory.cohere(config)
val request = RerankRequest(
query = "What is Scala?",
documents = Seq("Scala is a programming language", "Python is popular"),
topK = Some(5)
)
val response = reranker.rerank(request)
response.foreach { r =>
r.results.foreach(rr => println(s"Score $${rr.score}: $${rr.document.take(50)}..."))
}
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class CohereRerankerclass LLMReranker
Factory for creating Reranker instances.
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
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
RerankerFactory.type