rag_context

rag_context#

Bases: SerializableMixin “)

Attributes#

Name

Type

Description

<a href="rag_context.mdx#griptape.engines.rag.rag_context.RagContext.query" title="query = field(metadata={'serializable': True}) class-attribute instance-attribute (griptape.engines.rag.rag_context.RagContext.query)"><code class="language-python">query</code></a>

str

Query provided by the user.<br/>

<a href="rag_context.mdx#griptape.engines.rag.rag_context.RagContext.module_configs" title="module_configs = field(factory=dict, metadata={'serializable': True}) class-attribute instance-attribute (griptape.engines.rag.rag_context.RagContext.module_configs)"><code class="language-python">module_configs</code></a>

dict[str, dict]

Dictionary of module configs. First key should be a module name and the second a dictionary of configs parameters.<br/>

<a href="rag_context.mdx#griptape.engines.rag.rag_context.RagContext.before_query" title="before_query = field(factory=list, metadata={'serializable': True}) class-attribute instance-attribute (griptape.engines.rag.rag_context.RagContext.before_query)"><code class="language-python">before_query</code></a>

<a href="../../../data/artifacts.mdx#list" title="List (list)"><code class="language-python">list[str]</code></a>

An optional list of strings to add before the query in response modules.<br/>

<a href="rag_context.mdx#griptape.engines.rag.rag_context.RagContext.after_query" title="after_query = field(factory=list, metadata={'serializable': True}) class-attribute instance-attribute (griptape.engines.rag.rag_context.RagContext.after_query)"><code class="language-python">after_query</code></a>

<a href="../../../data/artifacts.mdx#list" title="List (list)"><code class="language-python">list[str]</code></a>

An optional list of strings to add after the query in response modules.<br/>

<a href="rag_context.mdx#griptape.engines.rag.rag_context.RagContext.text_chunks" title="text_chunks = field(factory=list, metadata={'serializable': True}) class-attribute instance-attribute (griptape.engines.rag.rag_context.RagContext.text_chunks)"><code class="language-python">text_chunks</code></a>

<a href="../../../data/artifacts.mdx#list" title="List (list)"><code class="language-python">list[TextArtifact]</code></a>

A list of text chunks to pass around from the retrieval stage to the response stage.<br/>

<a href="rag_context.mdx#griptape.engines.rag.rag_context.RagContext.outputs" title="outputs = field(factory=list, metadata={'serializable': True}) class-attribute instance-attribute (griptape.engines.rag.rag_context.RagContext.outputs)"><code class="language-python">outputs</code></a>

<a href="../../../data/artifacts.mdx#list" title="List (list)"><code class="language-python">list[BaseArtifact]</code></a>

List of outputs from the response stage.<br/>

Source Code in griptape/engines/rag/rag_context.py

@define(kw_only=True)
class RagContext(SerializableMixin):
    """Used by RagEngine stages and module to pass context that individual modules are expected to update in the `run` method.

    Attributes:
        query: Query provided by the user.
        module_configs: Dictionary of module configs. First key should be a module name and the second a dictionary of configs parameters.
        before_query: An optional list of strings to add before the query in response modules.
        after_query: An optional list of strings to add after the query in response modules.
        text_chunks: A list of text chunks to pass around from the retrieval stage to the response stage.
        outputs: List of outputs from the response stage.
    """

    query: str = field(metadata={"serializable": True})
    module_configs: dict[str, dict] = field(factory=dict, metadata={"serializable": True})
    before_query: list[str] = field(factory=list, metadata={"serializable": True})
    after_query: list[str] = field(factory=list, metadata={"serializable": True})
    text_chunks: list[TextArtifact] = field(factory=list, metadata={"serializable": True})
    outputs: list[BaseArtifact] = field(factory=list, metadata={"serializable": True})

    def get_references(self) -> list[Reference]:
        return utils.references_from_artifacts(self.text_chunks)
  • after_query = field(factory=list, metadata={'serializable': True}) class-attribute instance-attribute

  • before_query = field(factory=list, metadata={'serializable': True}) class-attribute instance-attribute

  • module_configs = field(factory=dict, metadata={'serializable': True}) class-attribute instance-attribute

  • outputs = field(factory=list, metadata={'serializable': True}) class-attribute instance-attribute

  • query = field(metadata={'serializable': True}) class-attribute instance-attribute

  • text_chunks = field(factory=list, metadata={'serializable': True}) class-attribute instance-attribute

get_references()#

Source Code in griptape/engines/rag/rag_context.py

def get_references(self) -> list[Reference]:
    return utils.references_from_artifacts(self.text_chunks)