RAGchain.reranker.upr package

Submodules

RAGchain.reranker.upr.upr module

class RAGchain.reranker.upr.upr.UPRReranker(model_name: str = 't5-large', prefix_prompt: str = 'Passage: ', suffix_prompt: str = 'Please write a question based on this passage.', use_bf16: bool = False, use_gpu: bool = False, shard_size: int = 16)

Bases: BaseReranker

UPRReranker is a reranker based on UPR (https://github.com/DevSinghSachan/unsupervised-passage-reranking). The language model will make a question based on the passage and rerank the passages by the likelihood of the question.

calculate_likelihood(question: str, contexts: List[str]) tuple[List[int], List[float]]
invoke(input: Input, config: RunnableConfig | None = None) Output

Transform a single input into an output. Override to implement.

Args:

input: The input to the runnable. config: A config to use when invoking the runnable.

The config supports standard keys like ‘tags’, ‘metadata’ for tracing purposes, ‘max_concurrency’ for controlling how much work to do in parallel, and other keys. Please refer to the RunnableConfig for more details.

Returns:

The output of the runnable.

rerank(query: str, passages: List[Passage]) List[Passage]

Reranks a list of passages based on a specific ranking algorithm.

Parameters:
  • passages (List[Passage]) – A list of Passage objects representing the passages to be reranked.

  • query – str: The query that was used for retrieving the passages.

Returns:

The reranked list of passages.

Return type:

List[Passage]

Module contents