fabricatio_rag.capabilities.rag

A module for the RAG (Retrieval Augmented Generation) model.

Classes

RAGConfigBase

A base class for RAG (Retrieval Augmented Generation) configuration.

RAG

A class representing the RAG (Retrieval Augmented Generation) model.

Module Contents

class fabricatio_rag.capabilities.rag.RAGConfigBase(/, **data: Any)

Bases: fabricatio_core.models.generic.Base

A base class for RAG (Retrieval Augmented Generation) configuration.

classmethod default() Self

Create a default configuration instance.

class fabricatio_rag.capabilities.rag.RAG[STD: fabricatio_rag.models.document.StoredDocumentModel, SRD: fabricatio_rag.models.document.SearchedDocumentModel, AC: RAGConfigBase, FC: RAGConfigBase](/, **data: Any)

Bases: fabricatio_core.capabilities.usages.UseEmbedding, fabricatio_core.capabilities.usages.UseReranker, fabricatio_core.capabilities.usages.UseLLM, abc.ABC

A class representing the RAG (Retrieval Augmented Generation) model.

abstractmethod add_document(data: STD | List[STD], config: AC | None = None) Self
Async:

Add documents to a collection.

abstractmethod afetch_document(query: str | List[str], config: FC | None = None) List[SRD]
Async:

Fetch documents based on query.

async arefined_query(question: List[str] | str, **kwargs: Unpack[fabricatio_core.models.kwargs_types.ListStringKwargs]) List[str] | None

Refines the given question using a template.

Parameters:
  • question (List[str] | str) – The question to be refined.

  • **kwargs (Unpack[ChooseKwargs]) – Additional keyword arguments for the refinement process.

Returns:

A list of refined questions.

Return type:

List[str]

async arank_documents(query: str, documents: List[SRD], **kwargs: Unpack[fabricatio_core.models.kwargs_types.RerankerKwargs]) List[SRD]

Rerank documents by relevance to query, preserving document objects.

Delegates to UseReranker.arank() for scoring, then reorders the original document list by descending score.

Parameters:
  • query – The query text to rank against.

  • documents – Previously retrieved documents to rerank.

  • **kwargs – Additional keyword arguments for the reranking process.

Returns:

Documents reordered by relevance (descending score).