Skip to content

Retrievers

Base Retriever

BaseRetriever

Bases: BaseModel, ABC

Base Retriever Class.

Source code in src/fed_rag/base/retriever.py
class BaseRetriever(BaseModel, ABC):
    """Base Retriever Class."""

    model_config = ConfigDict(arbitrary_types_allowed=True)

    @abstractmethod
    def encode_query(
        self, query: str | list[str], **kwargs: Any
    ) -> torch.Tensor:
        """Encode query."""

    @abstractmethod
    def encode_context(
        self, context: str | list[str], **kwargs: Any
    ) -> torch.Tensor:
        """Encode context."""

    @property
    @abstractmethod
    def encoder(self) -> torch.nn.Module | None:
        """PyTorch model associated with the encoder associated with retriever."""

    @property
    @abstractmethod
    def query_encoder(self) -> torch.nn.Module | None:
        """PyTorch model associated with the query encoder associated with retriever."""

    @property
    @abstractmethod
    def context_encoder(self) -> torch.nn.Module | None:
        """PyTorch model associated with the context encoder associated with retriever."""

encoder abstractmethod property

encoder

PyTorch model associated with the encoder associated with retriever.

query_encoder abstractmethod property

query_encoder

PyTorch model associated with the query encoder associated with retriever.

context_encoder abstractmethod property

context_encoder

PyTorch model associated with the context encoder associated with retriever.

encode_query abstractmethod

encode_query(query, **kwargs)

Encode query.

Source code in src/fed_rag/base/retriever.py
@abstractmethod
def encode_query(
    self, query: str | list[str], **kwargs: Any
) -> torch.Tensor:
    """Encode query."""

encode_context abstractmethod

encode_context(context, **kwargs)

Encode context.

Source code in src/fed_rag/base/retriever.py
@abstractmethod
def encode_context(
    self, context: str | list[str], **kwargs: Any
) -> torch.Tensor:
    """Encode context."""