agents.rag.simple.clean_simple_rag

SimpleRAG - Clean MultiAgent Implementation.

This is the CORRECT SimpleRAG implementation using the clean MultiAgent pattern.

Architecture:

SimpleRAG extends MultiAgent from clean.py agents = [BaseRAGAgent, SimpleAgent] # List initialization (converted to dict) execution_mode = “sequential” (default)

Flow: BaseRAGAgent retrieves documents → SimpleAgent generates answers

Key Features: - Uses the clean MultiAgent pattern from haive.agents.multi.clean - Proper list initialization: MultiAgent(agents=[retriever, generator]) - Sequential execution (retriever → generator) - No custom routing needed - uses intelligent routing - Proper Pydantic patterns with no __init__ overrides - Comprehensive field validation and documentation

Examples

Basic usage:

from haive.agents.rag.simple.clean_simple_rag import SimpleRAG
from haive.core.engine.aug_llm import AugLLMConfig
from haive.core.engine.vectorstore import VectorStoreConfig

rag = SimpleRAG(
    name="qa_assistant",
    retriever_config=VectorStoreConfig(vector_store=vector_store),
    llm_config=AugLLMConfig(temperature=0.7),
    top_k=5
)

result = await rag.arun("What is machine learning?")

With structured output:

class QAResponse(BaseModel):
    answer: str
    sources: List[str]
    confidence: float

rag = SimpleRAG(
    name="structured_qa",
    retriever_config=retriever_config,
    llm_config=llm_config,
    structured_output_model=QAResponse
)

From documents:

rag = SimpleRAG.from_documents(
    documents=my_documents,
    embedding_config=embedding_config,
    llm_config=AugLLMConfig()
)

Classes

SimpleRAG

SimpleRAG - Clean MultiAgent implementation with BaseRAGAgent + SimpleAgent.

Module Contents

class agents.rag.simple.clean_simple_rag.SimpleRAG

Bases: haive.agents.multi.agent.MultiAgent

SimpleRAG - Clean MultiAgent implementation with BaseRAGAgent + SimpleAgent.

This is the proper SimpleRAG following the clean MultiAgent pattern:

Architecture:
  • Extends MultiAgent from clean.py

  • agents = [BaseRAGAgent, SimpleAgent] (list initialization)

  • execution_mode = “sequential” (default intelligent routing)

  • No custom routing needed - uses BaseGraph intelligent routing

Flow:
  1. BaseRAGAgent retrieves relevant documents from vector store

  2. SimpleAgent generates answers from retrieved documents

  3. MultiAgent handles the sequential coordination automatically

This leverages the full MultiAgent infrastructure:
  • Proper state management via MultiAgentState

  • Graph building and execution

  • Sequential routing and coordination

  • Error handling and debugging

Examples

Basic RAG:

rag = SimpleRAG(
    name="qa_system",
    retriever_config=VectorStoreConfig(vector_store=vector_store),
    llm_config=AugLLMConfig(temperature=0.7),
    top_k=5
)

result = await rag.arun("What is machine learning?")

With structured output:

class QAResponse(BaseModel):
    answer: str
    sources: List[str]
    confidence: float

rag = SimpleRAG(
    name="structured_qa",
    retriever_config=retriever_config,
    llm_config=llm_config,
    structured_output_model=QAResponse
)

From documents:

rag = SimpleRAG.from_documents(
    documents=my_documents,
    embedding_config=embedding_config,
    llm_config=AugLLMConfig()
)
async arun(input_data, debug=False, **kwargs)

Execute RAG pipeline using clean MultiAgent sequential execution.

This leverages the clean MultiAgent infrastructure for proper sequential execution of retriever → generator with full state management.

Parameters:
  • input_data (str | dict[str, Any]) – Query string or structured input dict with ‘query’ field

  • debug (bool) – Enable debug logging and detailed output

  • **kwargs – Additional execution parameters

Returns:

Generated response from the generator agent

Raises:
Return type:

Any

classmethod from_documents(documents, embedding_config, llm_config, name='SimpleRAG_from_docs', **kwargs)

Create SimpleRAG from a list of documents.

Parameters:
  • documents (list[langchain_core.documents.Document]) – List of documents to create vector store from

  • embedding_config (Any) – Embedding configuration for vector store

  • llm_config (haive.core.engine.aug_llm.AugLLMConfig) – LLM configuration for answer generation

  • name (str) – Name for the RAG agent

  • **kwargs – Additional configuration parameters

Returns:

Configured SimpleRAG instance

Return type:

SimpleRAG

classmethod from_vectorstore(vector_store_config, llm_config, name='SimpleRAG_from_vs', **kwargs)

Create SimpleRAG from existing vector store configuration.

Parameters:
  • vector_store_config (haive.core.engine.vectorstore.VectorStoreConfig) – Vector store configuration

  • llm_config (haive.core.engine.aug_llm.AugLLMConfig) – LLM configuration for answer generation

  • name (str) – Name for the RAG agent

  • **kwargs – Additional configuration parameters

Returns:

Configured SimpleRAG instance

Return type:

SimpleRAG

async generate_answer(query, documents, **kwargs)

Generate answer using the generator agent.

Parameters:
  • query (str) – Original query

  • documents (list[langchain_core.documents.Document]) – Retrieved documents for context

  • **kwargs – Additional generation parameters

Returns:

Generated answer (format depends on structured_output_model)

Return type:

Any

get_generator_agent()

Get the generator agent from the agents dict.

Return type:

haive.agents.simple.agent.SimpleAgent

get_rag_info()

Get comprehensive information about the RAG configuration.

Return type:

dict[str, Any]

get_retriever_agent()

Get the retriever agent from the agents dict.

Return type:

haive.agents.rag.base.agent.BaseRAGAgent

async retrieve_documents(query, k=None, score_threshold=None, **kwargs)

Retrieve documents using the retriever agent.

Parameters:
  • query (str) – Query string for retrieval

  • k (int | None) – Number of documents to retrieve (defaults to self.top_k)

  • score_threshold (float | None) – Minimum similarity score (defaults to self.similarity_threshold)

  • **kwargs – Additional retrieval parameters

Returns:

List of retrieved documents

Return type:

list[langchain_core.documents.Document]

setup_rag_agents()

Setup the retriever and generator agents using the clean MultiAgent pattern.

Return type:

SimpleRAG

classmethod validate_context_template(v)

Validate context template has required placeholders.

Parameters:

v (str)

Return type:

str