Skip to content

RAG

Auxiliary types for RAG System

Query

Bases: _MultiModalDataContainer

Query data structure.

This class represents a multimodal representation of a RAG query.

Attributes:

Name Type Description
text str

Text content of query.

images list[Image] | None

Images content of query.

audios list[Any] | None

Audios content of query.

videos list[Any] | None

Videos content of query.

Source code in src/fed_rag/data_structures/rag.py
class Query(_MultiModalDataContainer):
    """Query data structure.

    This class represents a multimodal representation of a RAG query.

    Attributes:
        text: Text content of query.
        images: Images content of query.
        audios: Audios content of query.
        videos: Videos content of query.
    """

    pass

Context

Bases: _MultiModalDataContainer

Context data structure.

This class represents a multimodal representation of RAG context.

Attributes:

Name Type Description
text str

Text content of query.

images list[Image] | None

Images content of query.

audios list[Any] | None

Audios content of query.

videos list[Any] | None

Videos content of query.

Source code in src/fed_rag/data_structures/rag.py
class Context(_MultiModalDataContainer):
    """Context data structure.

    This class represents a multimodal representation of RAG context.

    Attributes:
        text: Text content of query.
        images: Images content of query.
        audios: Audios content of query.
        videos: Videos content of query.
    """

    pass

Prompt

Bases: _MultiModalDataContainer

Prompt data structure.

This class represents a multimodal representation of a prompt given to a multi-modal LLM.

Attributes:

Name Type Description
text str

Text content of query.

images list[Image] | None

Images content of query.

audios list[Any] | None

Audios content of query.

videos list[Any] | None

Videos content of query.

Source code in src/fed_rag/data_structures/rag.py
class Prompt(_MultiModalDataContainer):
    """Prompt data structure.

    This class represents a multimodal representation of a prompt given to a
    multi-modal LLM.

    Attributes:
        text: Text content of query.
        images: Images content of query.
        audios: Audios content of query.
        videos: Videos content of query.
    """

    pass

SourceNode

Bases: BaseModel

Represents a source node with an associated score and a reference to a knowledge node.

This class is used to associate a score with a specific knowledge node, allowing for the evaluation or ranking of knowledge entities. It provides access to the underlying node's attributes and functionalities through a convenient getattr wrapper.

Attributes:

Name Type Description
score float

The score associated with the node, representing some metric of evaluation or importance.

node KnowledgeNode

The knowledge node this source node is referencing.

Source code in src/fed_rag/data_structures/rag.py
class SourceNode(BaseModel):
    """
    Represents a source node with an associated score and a reference to a knowledge node.

    This class is used to associate a score with a specific knowledge node, allowing
    for the evaluation or ranking of knowledge entities. It provides access to the
    underlying node's attributes and functionalities through a convenient getattr wrapper.

    Attributes:
        score (float): The score associated with the node, representing some metric
            of evaluation or importance.
        node (KnowledgeNode): The knowledge node this source node is referencing.
    """

    score: float
    node: KnowledgeNode

    def __getattr__(self, __name: str) -> Any:
        """Convenient wrapper on getattr of associated node."""
        return getattr(self.node, __name)

__getattr__

__getattr__(__name)

Convenient wrapper on getattr of associated node.

Source code in src/fed_rag/data_structures/rag.py
def __getattr__(self, __name: str) -> Any:
    """Convenient wrapper on getattr of associated node."""
    return getattr(self.node, __name)

RAGResponse

Bases: BaseModel

Represents a response object for a Retrieval-Augmented Generation (RAG) system.

This class is used to encapsulate information about the response including the generated response text, optional raw response details, and the source nodes leveraged in generating the response.

Attributes:

Name Type Description
response str

The generated response text from the RAG system.

raw_response str | None

Optional raw response details, if available.

source_nodes list[SourceNode]

A list of source nodes that were used to generate the response, each with an associated score and reference to a knowledge node.

Source code in src/fed_rag/data_structures/rag.py
class RAGResponse(BaseModel):
    """
    Represents a response object for a Retrieval-Augmented Generation (RAG)
    system.

    This class is used to encapsulate information about the response including
    the generated response text, optional raw response details, and the source
    nodes leveraged in generating the response.

    Attributes:
        response (str): The generated response text from the RAG system.
        raw_response (str | None): Optional raw response details, if available.
        source_nodes (list[SourceNode]): A list of source nodes that were used
            to generate the response, each with an associated score and reference
            to a knowledge node.


    """

    response: str
    raw_response: str | None = None
    source_nodes: list[SourceNode]

    def __str__(self) -> str:
        return self.response