reranker_retriever#

Reranking model using modelclient as a retriever.

Classes

RerankerRetriever(model_client[, ...])

A retriever that uses a reranker model to rank the documents and retrieve the top-k documents.

class RerankerRetriever(model_client: ModelClient, model_kwargs: Dict = {}, top_k: int = 5, documents: Sequence[RetrieverDocumentType] | None = None, document_map_func: Callable[[Any], str] | None = None)[source]#

Bases: Retriever[str, str | Sequence[str]]

A retriever that uses a reranker model to rank the documents and retrieve the top-k documents.

Parameters:
  • top_k (int, optional) – The number of top documents to retrieve. Defaults to 5.

  • model_client (ModelClient) – The model client that has a reranker model, such as CohereAPIClient or TransformersClient.

  • model_kwargs (Dict) – The model kwargs to pass to the model client.

  • documents (Optional[RetrieverDocumentsType], optional) – The documents to build the index from. Defaults to None.

  • document_map_func (Optional[Callable[[Any], str]], optional) – The function to map the document of Any type to the specific type RetrieverDocumentType that the retriever expects. Defaults to None.

Examples:

reset_index()[source]#

Initialize/reset any attributes/states for the index.

build_index_from_documents(documents: Sequence[RetrieverDocumentType], document_map_func: Callable[[Any], str] | None = None)[source]#

Built index from the [document_map_func(doc) for doc in documents].

call(input: str | Sequence[str], top_k: int | None = None) List[RetrieverOutput][source]#