RAGchain.reranker package

Subpackages

Submodules

RAGchain.reranker.base module

class RAGchain.reranker.base.BaseReranker

Bases: Runnable[RetrievalResult, RetrievalResult], ABC

property InputType: Type[Input]

The type of input this runnable accepts specified as a type annotation.

property OutputType: Type[RetrievalResult]

The type of output this runnable produces specified as a type annotation.

abstract 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]

RAGchain.reranker.bm25 module

class RAGchain.reranker.bm25.BM25Reranker(tokenizer_name: str = 'gpt2', *args, **kwargs)

Bases: BaseReranker

BM25Reranker class for reranker based on BM25. You can rerank the passages with BM25 scores .

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