haive.core.schema.prebuilt.rag_state¶

RAG (Retrieval-Augmented Generation) state schema for haive agents.

Classes¶

RAGState

State schema for RAG (Retrieval-Augmented Generation) workflows.

Module Contents¶

class haive.core.schema.prebuilt.rag_state.RAGState(/, **data)[source]¶

Bases: haive.core.schema.prebuilt.messages_state.MessagesState

State schema for RAG (Retrieval-Augmented Generation) workflows.

This schema extends MessagesState with fields specific to RAG operations: - Document retrieval and storage - Query/question tracking - Context management - Retrieved document scoring and metadata

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

add_document(document)[source]¶

Add a document to the retrieved documents list.

Parameters:

document (langchain_core.documents.Document)

Return type:

None

clear_documents()[source]¶

Clear all retrieved documents.

Return type:

None

format_documents_as_context(separator='\n\n')[source]¶

Format documents into a context string.

Parameters:

separator (str)

Return type:

str

classmethod from_query(query)[source]¶

Create a RAGState from a query string.

Parameters:

query (str)

Return type:

RAGState

get_top_documents(k=5)[source]¶

Get the top k documents based on retrieval scores.

Parameters:

k (int)

Return type:

list[langchain_core.documents.Document]

update_retrieval_metadata(metadata)[source]¶

Update retrieval metadata.

Parameters:

metadata (dict[str, Any])

Return type:

None