agents.rag.simple.enhanced_v3.agentΒΆ

SimpleRAG V3 - Enhanced MultiAgent Implementation.

This module implements SimpleRAG using Enhanced MultiAgent V3 with the pattern: SimpleRAG = EnhancedMultiAgent[RetrieverAgent, SimpleAnswerAgent]

The implementation provides: - Type-safe agent composition - Performance tracking and optimization - Debug support and monitoring - Adaptive routing capabilities - Comprehensive state management

Examples

Basic usage:

rag = SimpleRAGV3.from_documents(
    documents=documents,
    embedding_config=embedding_config,
    performance_mode=True
)

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

Advanced usage with monitoring:

rag = SimpleRAGV3(
    name="qa_system",
    vector_store_config=vector_store_config,
    performance_mode=True,
    debug_mode=True,
    adaptation_rate=0.2
)

result = await rag.arun("Complex query")
analysis = rag.analyze_agent_performance()

ClassesΒΆ

SimpleRAGV3

SimpleRAG V3 - Enhanced MultiAgent implementation.

Module ContentsΒΆ

class agents.rag.simple.enhanced_v3.agent.SimpleRAGV3ΒΆ

Bases: haive.agents.multi.enhanced_multi_agent_v3.EnhancedMultiAgent[RAGAgentCollection]

SimpleRAG V3 - Enhanced MultiAgent implementation.

This class implements SimpleRAG using Enhanced MultiAgent V3 with the pattern: SimpleRAGV3 = EnhancedMultiAgent[RetrieverAgent, SimpleAnswerAgent]

The sequential execution flow is: 1. RetrieverAgent: Retrieves relevant documents from vector store 2. SimpleAnswerAgent: Generates answer using retrieved documents

Key Features:
  • Type-safe agent composition using Enhanced MultiAgent V3

  • Performance tracking and adaptive optimization

  • Debug support with comprehensive monitoring

  • Automatic state management and transfer

  • Factory methods for easy creation

  • Backward compatibility with existing SimpleRAG

State Management:

Uses SimpleRAGState when enhanced features are enabled, falls back to EnhancedMultiAgentState for basic usage.

Examples

From documents:

rag = SimpleRAGV3.from_documents(
    documents=my_documents,
    embedding_config=embedding_config,
    performance_mode=True,
    debug_mode=True
)

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

From vector store:

rag = SimpleRAGV3.from_vectorstore(
    vector_store_config=vs_config,
    llm_config=AugLLMConfig(temperature=0.7),
    performance_mode=True
)

With structured output:

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

rag = SimpleRAGV3(
    name="structured_rag",
    vector_store_config=vs_config,
    structured_output_model=QAResponse,
    performance_mode=True
)
async arun(input_data, debug=False, **kwargs)ΒΆ

Execute RAG pipeline using Enhanced MultiAgent V3 sequential execution.

This leverages the Enhanced MultiAgent V3 infrastructure for: - Performance tracking and optimization - Debug support and monitoring - Adaptive routing capabilities - Comprehensive state management

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

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

  • **kwargs – Additional execution parameters

Returns:

Generated response from the answer generation agent

Raises:
Return type:

Any

classmethod ensure_agents_is_list(values)ΒΆ

Ensure agents field starts as an empty list for our List type.

Parameters:

values (dict)

Return type:

dict

classmethod from_documents(documents, embedding_config, llm_config=None, name=None, **kwargs)ΒΆ

Create SimpleRAG V3 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 | None) – LLM configuration for answer generation

  • name (str | None) – Name for the RAG system

  • **kwargs – Additional configuration parameters

Returns:

Configured SimpleRAGV3 instance

Return type:

SimpleRAGV3

Examples

Basic usage:

rag = SimpleRAGV3.from_documents(
    documents=my_documents,
    embedding_config=embedding_config
)

With enhanced features:

rag = SimpleRAGV3.from_documents(
    documents=my_documents,
    embedding_config=embedding_config,
    llm_config=AugLLMConfig(temperature=0.3),
    performance_mode=True,
    debug_mode=True,
    top_k=10
)
classmethod from_vectorstore(vector_store_config, llm_config=None, name=None, **kwargs)ΒΆ

Create SimpleRAG V3 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 | None) – LLM configuration for answer generation

  • name (str | None) – Name for the RAG system

  • **kwargs – Additional configuration parameters

Returns:

Configured SimpleRAGV3 instance

Return type:

SimpleRAGV3

Examples

Basic usage:

rag = SimpleRAGV3.from_vectorstore(
    vector_store_config=vs_config,
    llm_config=AugLLMConfig()
)

With monitoring:

rag = SimpleRAGV3.from_vectorstore(
    vector_store_config=vs_config,
    llm_config=AugLLMConfig(temperature=0.5),
    performance_mode=True,
    adaptation_rate=0.2
)
async generate_answer(query, documents, **kwargs)ΒΆ

Generate answer using the answer generation 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_answer_agent()ΒΆ

Get the answer generation agent.

Return type:

agents.rag.simple.enhanced_v3.answer_generator_agent.SimpleAnswerAgent

get_rag_info()ΒΆ

Get comprehensive information about the RAG configuration.

Return type:

dict[str, Any]

get_retriever_agent()ΒΆ

Get the retriever agent.

Return type:

agents.rag.simple.enhanced_v3.retriever_agent.RetrieverAgent

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:

Retrieval result with documents and metadata

Return type:

dict[str, Any]

setup_rag_pipeline()ΒΆ

Setup the RAG pipeline with RetrieverAgent and SimpleAnswerAgent.

Return type:

SimpleRAGV3

classmethod validate_citation_style(v)ΒΆ

Validate citation style.

Parameters:

v (str)

Return type:

str