Package com.redis.vl.utils.rerank
Class BaseReranker
java.lang.Object
com.redis.vl.utils.rerank.BaseReranker
- Direct Known Subclasses:
CohereReranker
,HFCrossEncoderReranker
,VoyageAIReranker
Abstract base class for document rerankers.
Rerankers improve search result quality by reordering documents based on their relevance to a query using specialized models (cross-encoders, API-based rerankers, etc.).
Implementations must provide the rank(String, List)
method which takes a query and a
list of documents and returns a RerankResult
with the documents reordered by relevance.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final int
Maximum number of results to return.protected final String
The model name or identifier used for reranking.Optional list of field names to rank by (may be null).protected final boolean
Whether to include relevance scores in results. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BaseReranker
(String model, List<String> rankBy, int limit, boolean returnScore) Create a reranker with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionint
getLimit()
Get the maximum number of results to return.getModel()
Get the model name.Get the fields to rank by.boolean
Check if scores should be returned with results.abstract RerankResult
Rerank documents based on their relevance to the query.protected void
validateDocs
(List<?> docs) Validate documents parameter.protected void
validateQuery
(String query) Validate query parameter.
-
Field Details
-
model
The model name or identifier used for reranking. -
rankBy
Optional list of field names to rank by (may be null). -
limit
protected final int limitMaximum number of results to return. -
returnScore
protected final boolean returnScoreWhether to include relevance scores in results.
-
-
Constructor Details
-
BaseReranker
Create a reranker with the specified configuration.- Parameters:
model
- The model name or identifierrankBy
- Optional list of field names to rank by (may be null)limit
- Maximum number of results to return (must be positive)returnScore
- Whether to include relevance scores in results- Throws:
IllegalArgumentException
- if limit is not positive
-
-
Method Details
-
rank
Rerank documents based on their relevance to the query.- Parameters:
query
- The search querydocs
- The documents to rerank (either List<String> or List<Map<String, Object>>)- Returns:
- RerankResult containing reranked documents and optional scores
- Throws:
IllegalArgumentException
- if query or docs are invalid
-
getModel
Get the model name.- Returns:
- Model identifier
-
getRankBy
Get the fields to rank by.- Returns:
- Unmodifiable list of field names, or null if not applicable
-
getLimit
public int getLimit()Get the maximum number of results to return.- Returns:
- Result limit
-
isReturnScore
public boolean isReturnScore()Check if scores should be returned with results.- Returns:
- true if scores are included
-
validateQuery
Validate query parameter.- Parameters:
query
- The query string to validate- Throws:
IllegalArgumentException
- if query is null or empty
-
validateDocs
Validate documents parameter.- Parameters:
docs
- The documents list to validate- Throws:
IllegalArgumentException
- if docs is null
-