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