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ΒΆ
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:
- Returns:
Generated response from the answer generation agent
- Raises:
ValueError β If input validation fails
RuntimeError β If pipeline execution fails
- Return type:
Any
- classmethod ensure_agents_is_list(values)ΒΆ
Ensure agents field starts as an empty list for our List type.
- 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:
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:
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.
- get_answer_agent()ΒΆ
Get the answer generation agent.
- get_rag_info()ΒΆ
Get comprehensive information about the RAG configuration.
- get_retriever_agent()ΒΆ
Get the retriever agent.
- async retrieve_documents(query, k=None, score_threshold=None, **kwargs)ΒΆ
Retrieve documents using the retriever agent.
- Parameters:
- Returns:
Retrieval result with documents and metadata
- Return type:
- setup_rag_pipeline()ΒΆ
Setup the RAG pipeline with RetrieverAgent and SimpleAnswerAgent.
- Return type: