agents.rag.modelsΒΆ

RAG Agent Models.

This module contains all Pydantic models used by RAG agents for structured data validation and type safety. These models represent different outputs and intermediate results from various RAG patterns.

Example

>>> from haive.agents.rag.models import HyDEResult
>>> result = HyDEResult(
...     hypothetical_doc="Generated document content...",
...     refined_query="Refined query text",
...     confidence=0.85
... )
Typical usage:
  • Import specific models for agent implementations

  • Use for structured output from LLM engines

  • Validate intermediate results in RAG pipelines

  • Type hints for function parameters and returns

ClassesΒΆ

BranchResult

Result from a single retrieval branch.

EnhancedResponse

Enhanced response with reasoning and memory integration.

FusionResult

Fusion ranking result from multi-query RAG.

HyDEResult

Hypothetical Document Enhanced (HyDE) result.

MemoryAnalysis

Memory analysis result for context-aware processing.

MemoryEntry

Memory entry for memory-aware RAG systems.

MemoryType

Types of memory for memory-aware RAG.

MergedResult

Final merged result from multiple branches or strategies.

QueryClassification

Query classification result for routing decisions.

QueryPlan

Query planning result for complex query decomposition.

QueryType

Types of queries for branched RAG routing.

RAGModuleType

Types of RAG modules for modular composition.

ReActStep

ReAct pattern step types.

ReActStepResult

Result from a single ReAct pattern step.

SpeculativeResult

Speculative reasoning result with hypothesis verification.

StepBackResult

Step-back reasoning result for abstract thinking.

StrategyDecision

Strategy selection decision for agentic routing.

SubQueryResult

Result from executing a single sub-query.

Module ContentsΒΆ

class agents.rag.models.BranchResult(/, **data)ΒΆ

Bases: pydantic.BaseModel

Result from a single retrieval branch.

Contains results from executing a specific branch in branched RAG, where multiple retrieval strategies are executed in parallel.

Parameters:

data (Any)

branch_typeΒΆ

Type of branch executed.

Type:

str

retrieved_docsΒΆ

Documents retrieved by this branch.

Type:

List[str]

branch_answerΒΆ

Answer generated by this branch.

Type:

str

relevance_scoreΒΆ

Relevance score for this branch (0.0 to 1.0).

Type:

float

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.

class agents.rag.models.EnhancedResponse(/, **data)ΒΆ

Bases: pydantic.BaseModel

Enhanced response with reasoning and memory integration.

Contains a comprehensive response that includes the main answer, reasoning chain, memory context, and metadata.

Parameters:

data (Any)

answerΒΆ

Main answer to the query.

Type:

str

reasoning_chainΒΆ

ReAct reasoning steps taken.

Type:

List[ReActStepResult]

memory_usedΒΆ

Memories used in generating response.

Type:

List[MemoryEntry]

new_memoriesΒΆ

New memories to store from this interaction.

Type:

List[MemoryEntry]

confidenceΒΆ

Response confidence (0.0 to 1.0).

Type:

float

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.

class agents.rag.models.FusionResult(/, **data)ΒΆ

Bases: pydantic.BaseModel

Fusion ranking result from multi-query RAG.

Contains documents ranked using reciprocal rank fusion or similar techniques for combining multiple retrieval results.

Parameters:

data (Any)

fused_documentsΒΆ

Documents ranked by fusion algorithm.

Type:

List[str]

fusion_scoresΒΆ

Corresponding fusion scores.

Type:

List[float]

ranking_methodΒΆ

Method used for ranking (e.g., β€œreciprocal_rank_fusion”).

Type:

str

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.

class agents.rag.models.HyDEResult(/, **data)ΒΆ

Bases: pydantic.BaseModel

Hypothetical Document Enhanced (HyDE) result.

Contains the generated hypothetical document and refined query used in the HyDE RAG pattern for improved retrieval performance.

Parameters:

data (Any)

hypothetical_docΒΆ

Generated hypothetical document that would answer the query.

Type:

str

refined_queryΒΆ

Query refined based on the hypothetical document.

Type:

str

confidenceΒΆ

Confidence score in the hypothesis (0.0 to 1.0).

Type:

float

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.

class agents.rag.models.MemoryAnalysis(/, **data)ΒΆ

Bases: pydantic.BaseModel

Memory analysis result for context-aware processing.

Contains analysis of relevant memories and identified knowledge gaps for enhanced context-aware response generation.

Parameters:

data (Any)

relevant_memoriesΒΆ

Relevant memories found.

Type:

List[MemoryEntry]

memory_gapsΒΆ

Identified knowledge gaps.

Type:

List[str]

temporal_contextΒΆ

Temporal context of memories.

Type:

str

confidenceΒΆ

Overall memory confidence (0.0 to 1.0).

Type:

float

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.

class agents.rag.models.MemoryEntry(/, **data)ΒΆ

Bases: pydantic.BaseModel

Memory entry for memory-aware RAG systems.

Represents a single memory entry with content, type, and metadata for use in conversation-aware RAG agents.

Parameters:

data (Any)

contentΒΆ

Memory content or summary.

Type:

str

memory_typeΒΆ

Type of memory (short-term, long-term, etc.).

Type:

MemoryType

timestampΒΆ

When this memory was created.

Type:

str

relevance_scoreΒΆ

Relevance to current query (0.0 to 1.0).

Type:

float

context_tagsΒΆ

Tags for categorizing memory content.

Type:

List[str]

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.

class agents.rag.models.MemoryTypeΒΆ

Bases: str, enum.Enum

Types of memory for memory-aware RAG.

SHORT_TERMΒΆ

Short-term conversational memory.

LONG_TERMΒΆ

Long-term knowledge memory.

EPISODICΒΆ

Episodic interaction memory.

SEMANTICΒΆ

Semantic knowledge memory.

Initialize self. See help(type(self)) for accurate signature.

class agents.rag.models.MergedResult(/, **data)ΒΆ

Bases: pydantic.BaseModel

Final merged result from multiple branches or strategies.

Contains the final synthesized result after combining outputs from multiple RAG branches or strategies.

Parameters:

data (Any)

primary_answerΒΆ

Primary synthesized answer.

Type:

str

supporting_evidenceΒΆ

Supporting evidence from branches.

Type:

List[str]

confidence_scoreΒΆ

Overall confidence (0.0 to 1.0).

Type:

float

sources_usedΒΆ

Sources used in the final answer.

Type:

List[str]

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.

class agents.rag.models.QueryClassification(/, **data)ΒΆ

Bases: pydantic.BaseModel

Query classification result for routing decisions.

Contains classification results used for routing queries to appropriate RAG strategies or processing branches.

Parameters:

data (Any)

primary_typeΒΆ

Primary query type.

Type:

QueryType

secondary_typeΒΆ

Secondary type if applicable.

Type:

Optional[QueryType]

complexityΒΆ

Query complexity level.

Type:

str

confidenceΒΆ

Classification confidence (0.0 to 1.0).

Type:

float

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.

class agents.rag.models.QueryPlan(/, **data)ΒΆ

Bases: pydantic.BaseModel

Query planning result for complex query decomposition.

Contains a plan for executing a complex query, including sub-queries and execution strategy.

Parameters:

data (Any)

sub_queriesΒΆ

Sub-queries to execute.

Type:

List[str]

execution_strategyΒΆ

How to execute them.

Type:

str

synthesis_approachΒΆ

How to combine results.

Type:

str

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.

class agents.rag.models.QueryTypeΒΆ

Bases: str, enum.Enum

Types of queries for branched RAG routing.

FACTUALΒΆ

Factual information queries.

ANALYTICALΒΆ

Analysis and reasoning queries.

CREATIVEΒΆ

Creative and ideation queries.

PROCEDURALΒΆ

Step-by-step procedure queries.

Initialize self. See help(type(self)) for accurate signature.

class agents.rag.models.RAGModuleTypeΒΆ

Bases: str, enum.Enum

Types of RAG modules for modular composition.

QUERY_EXPANSIONΒΆ

Query expansion and refinement module.

DOCUMENT_FILTERINGΒΆ

Document relevance filtering module.

CONTEXT_RANKINGΒΆ

Context relevance ranking module.

ANSWER_GENERATIONΒΆ

Answer generation module.

ANSWER_VERIFICATIONΒΆ

Answer quality verification module.

RESPONSE_SYNTHESISΒΆ

Final response synthesis module.

Initialize self. See help(type(self)) for accurate signature.

class agents.rag.models.ReActStepΒΆ

Bases: str, enum.Enum

ReAct pattern step types.

THOUGHTΒΆ

Reasoning and planning step.

ACTIONΒΆ

Action execution step.

OBSERVATIONΒΆ

Observation and analysis step.

REFLECTIONΒΆ

Reflection and evaluation step.

Initialize self. See help(type(self)) for accurate signature.

class agents.rag.models.ReActStepResult(/, **data)ΒΆ

Bases: pydantic.BaseModel

Result from a single ReAct pattern step.

Contains the output and metadata from executing a step in the ReAct (Reasoning + Acting) pattern.

Parameters:

data (Any)

step_typeΒΆ

Type of step executed.

Type:

ReActStep

contentΒΆ

Content or result of the step.

Type:

str

confidenceΒΆ

Confidence in this step (0.0 to 1.0).

Type:

float

next_actionΒΆ

Next action to take, if any.

Type:

Optional[str]

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.

class agents.rag.models.SpeculativeResult(/, **data)ΒΆ

Bases: pydantic.BaseModel

Speculative reasoning result with hypothesis verification.

Contains hypotheses generated and verified during speculative RAG, where multiple potential answers are explored and validated.

Parameters:

data (Any)

hypothesesΒΆ

Generated hypotheses for the query.

Type:

List[str]

verified_hypothesesΒΆ

Hypotheses verified against evidence.

Type:

List[str]

final_answerΒΆ

Answer based on verified hypotheses.

Type:

str

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.

class agents.rag.models.StepBackResult(/, **data)ΒΆ

Bases: pydantic.BaseModel

Step-back reasoning result for abstract thinking.

Contains results from step-back prompting where the agent first reasons about high-level concepts before specific answers.

Parameters:

data (Any)

abstract_questionΒΆ

High-level abstract question derived from the query.

Type:

str

abstract_answerΒΆ

Answer to the abstract question.

Type:

str

specific_answerΒΆ

Specific answer to the original query.

Type:

str

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.

class agents.rag.models.StrategyDecision(/, **data)ΒΆ

Bases: pydantic.BaseModel

Strategy selection decision for agentic routing.

Contains the decision made by an agentic router about which RAG strategy to use for a given query.

Parameters:

data (Any)

strategyΒΆ

Selected RAG strategy name.

Type:

str

confidenceΒΆ

Confidence in strategy selection (0.0 to 1.0).

Type:

float

reasoningΒΆ

Explanation for why this strategy was chosen.

Type:

str

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.

class agents.rag.models.SubQueryResult(/, **data)ΒΆ

Bases: pydantic.BaseModel

Result from executing a single sub-query.

Contains the result of executing one sub-query in a query planning pipeline.

Parameters:

data (Any)

queryΒΆ

The sub-query that was executed.

Type:

str

answerΒΆ

Answer to the sub-query.

Type:

str

confidenceΒΆ

Confidence in this result (0.0 to 1.0).

Type:

float

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.